vitrine 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c4afcd269b9abc86ecb39b02b1a54c969ef98a2
4
- data.tar.gz: 6487d2ed130c0ac7859ec8c7307a720054192396
3
+ metadata.gz: 2fcf49c459400509a306d68ac41f7fa0eb330322
4
+ data.tar.gz: 18797aa7373fcd1dd90fc9274f14f8ee133baf0d
5
5
  SHA512:
6
- metadata.gz: 74a076f0a0c24bbe1e09d03fea87bf85747515104a2e83f6477b43b4950d244970a4c74e3cf465f9fc71e9a61aac2d791f5c733c5aa055b7260052950130dd44
7
- data.tar.gz: c1cb7930928de1182867c03b3c8a073d364a847e521c9ad737c75a951d2c7b602781d579e389f25ce9be6f900a630881b1f7cec754e370e4ba5a67a0df1d89f4
6
+ metadata.gz: 0c07c3645db4170a981d9ffc192222db4ee9f0b7456705c93facacf581f69fe4168926e0778c336d5055dbb8386491f203c8b126ab323ed62a4a0e2903938bc2
7
+ data.tar.gz: 2f53f0309e7775e470c5325e0dee47c2f7670ca7316e626cf6533bf4442c53d69cc4cab08570fb922d09aec9ef76acbd5d01effb51537a36acc3c009769c8017
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  A nimble web server one-liner for modern web-apps, a bit in the style of
2
- [lineman](https://github.com/testdouble/lineman), [serve](https://github.com/visionmedia/serve),
3
- another [serve](https://github.com/jlong/serve) and such. Will display your precious stuff on port 9292.
2
+ [lineman](https://github.com/testdouble/lineman), [middleman](https://github.com/middleman/middleman), [serve](https://github.com/visionmedia/serve), another [serve](https://github.com/jlong/serve)
3
+ and such. Will display your precious stuff on port 9292.
4
+
5
+ It does some of what those other projects - only the stuff I need, with less.
4
6
 
5
7
  ## Core idea of Vitrine
6
8
 
@@ -34,8 +36,8 @@ to be able to just yank the file in there and carry on. THe compilation perks in
34
36
 
35
37
  ## Asset caching
36
38
 
37
- Succesfully compiled assets will be cached to save time on next reload, and ETagged based on their
38
- mtime.
39
+ Succesfully compiled assets will be ETagged based on their mtime. You should run an HTTP caching
40
+ proxy on top of a Vitrine app in production.
39
41
 
40
42
  ## Automatic Ruby template pickup
41
43
 
@@ -43,8 +45,10 @@ If you have the "views" directory available, Vitrine will try to pick up any usa
43
45
  From there on, it's going to try to render it with the automatically picked template engine using the
44
46
  standard Sinatra facilities. You can use HAML, LESS, Slim, ERB, Builder or anything else you like.
45
47
 
46
- If you are writing an SPA, you can make a file called "catch_all.erb" which is going to be
47
- the fall-through template for all missing URLs without extension.
48
+ ### The "catch-all" template for single-page apps
49
+
50
+ If you are writing an SPA, you can make a template called `catch_all.erb` (or `.haml` or whatever really)
51
+ in your `views` which is going to be the fall-through template for all missing URLs _without_ extension.
48
52
 
49
53
  ## Automatic reload via Guard
50
54
 
@@ -55,14 +59,7 @@ If your project already has a Guardfile, Vitrine will inject live-reloading hook
55
59
 
56
60
  Vitrine will `etag` all the precompiled assets for faster reloading.
57
61
 
58
- ## Packaging and baking
59
-
60
- At this point the best way to bake a Vitrine site is to crawl it externally, but we are going to implement
61
- baking at some point. The idea is that you will end up upgrading the site to either a Node app or a Ruby app
62
- with it's own `config.ru` - if after that point you still wish to use Vitrine, you can use it like a Rack
63
- middleware.
64
-
65
- ## Using as a middleware
62
+ ## Using the whole Vitrine as Rack middleware
66
63
 
67
64
  Most actions in Vitrine will fall through to 404, so `Vitrine::App` can be used as a middleware handler.
68
65
  Put Vitrine into your application stack and it will complement your main application very nicely. But don't
@@ -81,6 +78,18 @@ Note that you _need_ to have an `ExecJS` environment on your server for this:
81
78
  vitrine.settings.set :root => File.dirname(__FILE__)
82
79
  end
83
80
 
81
+ But you can also choose to have your JSON-serving API backend at the end of the Rack stack, and `Vitrine`
82
+ on top of it for assets and templating - the choice is entirelly up to you.
83
+
84
+ ## Packaging and baking of assets
85
+
86
+ This is on the TODO list, primarilly because it's notoriously difficult to splice assets for minification
87
+ preserving their source maps.
88
+
89
+ The idea is that you will end up upgrading the site to either a Node app or a Ruby app
90
+ with it's own `config.ru` - if after that point you still wish to use Vitrine, you can use it like a Rack
91
+ middleware.
92
+
84
93
  ## Contributing to vitrine
85
94
 
86
95
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -29,14 +29,14 @@ class Vitrine::AssetCompiler < Sinatra::Base
29
29
  # Try to find SCSS replacement for missing CSS
30
30
  get /(.+)\.css/ do | basename |
31
31
  begin
32
- content_type 'text/css', :charset => 'utf-8'
33
- # TODO: has no handling for .sass
32
+ # TODO: handle .sass ext as well
34
33
  scss_source_path = File.join(get_public, "#{basename}.scss")
35
- mtime_cache(scss_source_path) do
36
- # TODO: Examine http://sass-lang.com/documentation/file.SASS_REFERENCE.html
37
- # It already has provisions for error display, among other things
38
- Sass.compile_file(scss_source_path, cache_location: '/tmp/vitrine/sass-cache')
39
- end
34
+ mtime_cache(scss_source_path)
35
+ content_type 'text/css', :charset => 'utf-8'
36
+
37
+ # TODO: Examine http://sass-lang.com/documentation/file.SASS_REFERENCE.html
38
+ # It already has provisions for error display, among other things
39
+ Sass.compile_file(scss_source_path, cache_location: '/tmp/vitrine/sass-cache')
40
40
  rescue Errno::ENOENT # Missing SCSS
41
41
  forward_or_halt "No such CSS or SCSS file found"
42
42
  rescue Exception => e # CSS syntax error or something alike
@@ -55,10 +55,9 @@ class Vitrine::AssetCompiler < Sinatra::Base
55
55
  get /(.+)\.js\.map$/ do | basename |
56
56
  begin
57
57
  coffee_source = File.join(get_public, "#{basename}.coffee")
58
+ mtime_cache(coffee_source)
58
59
  content_type 'application/json', :charset => 'utf-8'
59
- mtime_cache(coffee_source) do
60
- Vitrine.build_coffeescript_source_map_body(coffee_source, get_public)
61
- end
60
+ Vitrine.build_coffeescript_source_map_body(coffee_source, get_public)
62
61
  rescue Errno::ENOENT # Missing CoffeeScript
63
62
  forward_or_halt "No coffeescript file found to generate the map for"
64
63
  rescue Exception => e # CS syntax error or something alike
@@ -71,17 +70,16 @@ class Vitrine::AssetCompiler < Sinatra::Base
71
70
  # If this file is not found resort back to a coffeescript
72
71
  begin
73
72
  coffee_source = File.join(get_public, "#{basename}.coffee")
73
+ mtime_cache coffee_source
74
74
  content_type 'text/javascript'
75
- mtime_cache(coffee_source) do
76
- source_body = File.read(coffee_source)
77
- # We could have sent a header, but it's a nice idea to have the
78
- # sourcemap header saved if we write out the compiled JS,
79
- # whereas otherwise it would have been discarded
80
- [
81
- "//# sourceMappingURL=#{basename}.js.map",
82
- Vitrine.compile_coffeescript(source_body)
83
- ].join("\n")
84
- end
75
+ source_body = File.read(coffee_source)
76
+ # We could have sent a header, but it's a nice idea to have the
77
+ # sourcemap header saved if we write out the compiled JS,
78
+ # whereas otherwise it would have been discarded
79
+ [
80
+ "//# sourceMappingURL=#{basename}.js.map",
81
+ Vitrine.compile_coffeescript(source_body)
82
+ ].join("\n")
85
83
  rescue Errno::ENOENT # Missing CoffeeScript
86
84
  forward_or_halt "No such JS file and could not find a .coffee replacement"
87
85
  rescue Exception => e # CS syntax error or something alike
@@ -92,31 +90,17 @@ class Vitrine::AssetCompiler < Sinatra::Base
92
90
  end
93
91
  end
94
92
 
95
- def mtime_cache(path, &blk)
93
+ def mtime_cache(path)
96
94
  # Mix in the request URL into the cache key so that we can hash
97
95
  # .map sourcemaps and .js compiles based off of the same file path
98
96
  # and mtime
99
97
  key = [File.expand_path(path), File.mtime(path), request.path_info, get_public]
100
98
  cache_sha = Digest::SHA1.hexdigest(Marshal.dump(key))
99
+ cache_control :public
100
+ etag cache_sha
101
101
 
102
- # Store in a temp dir
103
- FileUtils.mkdir_p '/tmp/vitrine'
104
- p = '/tmp/vitrine/%s' % cache_sha
105
-
106
- # Only write it out unless a file with the same SHA does not exist
107
- unless File.exist?(p)
108
- Vitrine.atomic_write(p) do |f|
109
- log "---> Recompiling #{path} for #{request.path_info}"
110
- f.write(yield)
111
- end
112
- end
113
-
114
- # And send out the file that's been written
115
- last_modified(File.mtime(p))
116
- etag File.mtime(p).to_i.to_s
117
- File.read(p)
102
+ log "---> Vitrine AC: Recompiling #{path} -> #{request.path_info}"
118
103
  end
119
-
120
104
 
121
105
  # Get path to the public directory, trying (in order:)
122
106
  # self.public_dir reader
@@ -132,7 +116,7 @@ class Vitrine::AssetCompiler < Sinatra::Base
132
116
  choices.compact.shift
133
117
  end
134
118
 
135
- def forward_or_halt msg
119
+ def forward_or_halt(msg)
136
120
  if @app
137
121
  log "Forwarding, #{msg} -> pub #{get_public.inspect}"
138
122
  forward
@@ -141,7 +125,7 @@ class Vitrine::AssetCompiler < Sinatra::Base
141
125
  end
142
126
  end
143
127
 
144
- def log(mgs)
128
+ def log(msg)
145
129
  env['captivity.logger'].debug(msg) if env['captivity.logger']
146
130
  end
147
131
  end
data/lib/server.rb CHANGED
@@ -22,7 +22,7 @@ module Vitrine::Server
22
22
  Rack::Builder.new do
23
23
  use Rack::ShowStatus
24
24
  use Rack::ShowExceptions
25
-
25
+
26
26
  guardfile_path = options[:root] + '/Guardfile'
27
27
  if File.exist?(guardfile_path)
28
28
  $stderr.puts "Attaching LiveReload via Guardfile at #{guardfile_path.inspect}"
@@ -70,6 +70,7 @@ module Vitrine::Server
70
70
  options = DEFAULTS.merge(passed_options)
71
71
  check_dirs_present!(options)
72
72
 
73
+ $stderr.puts "Vitrine v.#{Vitrine::VERSION} booting in dev mode"
73
74
  app = build_app(options)
74
75
  start_server(app, options)
75
76
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vitrine
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
  end
data/lib/vitrine.rb CHANGED
@@ -92,8 +92,6 @@ class Vitrine::App < Sinatra::Base
92
92
  render(template_engine, File.read(template_path), :layout => get_layout, :locals => locals)
93
93
  end
94
94
 
95
-
96
-
97
95
  def get_layout
98
96
  layouts = Dir.glob(File.join(settings.views, 'layout.*'))
99
97
  layouts.any? ? :layout : false
data/vitrine.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "vitrine"
8
- s.version = "0.0.16"
8
+ s.version = "0.0.17"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julik Tarkhanov"]
12
- s.date = "2014-01-06"
12
+ s.date = "2014-01-08"
13
13
  s.description = " Serves ERB templates with live CoffeeScript and SASS "
14
14
  s.email = "me@julik.nl"
15
15
  s.executables = ["vitrine"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitrine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra