vitrine 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -5
- data/lib/asset_compiler.rb +1 -1
- data/lib/sourcemaps.rb +10 -6
- data/lib/version.rb +1 -1
- data/test/test_vitrine_asset_compiler.rb +5 -3
- data/vitrine.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69628563d51142a39a52b1327d3c863886e83688
|
4
|
+
data.tar.gz: 442bd527960f9ee697af2a42c169d4523e23245d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 311ab78e5a8d58b5723134c3d733508e8889d92e99cb84f97b0f5c7a3a0a68885256215163a9bf86fe20bf164e9a27f799d62e5d95981b1dd10b83e3e7b64b75
|
7
|
+
data.tar.gz: bd09d14767ea2d5ed4af6fb1d4af9228ca808d73f53371e09cf48736443f82518805cdccf13b1215f2b88d93c373b11a49c4292655025fd8fe12288253131be2
|
data/README.md
CHANGED
@@ -2,7 +2,19 @@ A nimble web server one-liner for modern web-apps, a bit in the style of
|
|
2
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
3
|
and such. Will display your precious stuff on port 9292.
|
4
4
|
|
5
|
-
It does some of what those other projects - only the stuff I need, with less.
|
5
|
+
It does some of what those other projects - only the stuff I need, with less. And *with* the stuff that I
|
6
|
+
consider essential that still isn't supported where it should be supported. You can see Vitrine as
|
7
|
+
reinventing the wheel for sure, but the reason I wrote it is that I found the other development servers
|
8
|
+
giving me death by a thousand paper cuts. Just that really:
|
9
|
+
|
10
|
+
For example, `serve` which I loved dearly compiles `.coffee` files to JS with their native extension and
|
11
|
+
does not do source maps. It also depends on Compass, so you probably won't be able to put in the newer
|
12
|
+
version of SASS required for source maps. Sprockets does not do source maps either. The CoffeeScript
|
13
|
+
gem does not propagate the syntax error line to your browser console, so it's notoriously difficult
|
14
|
+
to find out where the errors are - because someone refused to accept a PR to the CoffeeScript gem -
|
15
|
+
and these small irritating things just go on and on and on. In the meantime, I wanted a comfortable
|
16
|
+
dev environment, without resorting to filesystem watching and rebuilding all my assets every time I change
|
17
|
+
a character. So there: Vitrine.
|
6
18
|
|
7
19
|
## Core idea of Vitrine
|
8
20
|
|
@@ -18,26 +30,44 @@ If most of the above is true, Vitrine is just what you need.
|
|
18
30
|
## All you need is some `public`
|
19
31
|
|
20
32
|
Vitrine assumes that there are two directories under the current tree:
|
33
|
+
|
21
34
|
* `public` - for the JS, for CSS and SCSS and in general all the static files served straight out
|
22
35
|
* `views` - for the templates, in any Ruby templating format you have
|
23
36
|
|
37
|
+
This structure fits my preferred stack (Sinatra + Passenger) perfectly and allows running sane
|
38
|
+
defaults. It is also migratable to another stack with minimum effort, while still having things
|
39
|
+
like asset passthrough via Passenger work out of the box.
|
40
|
+
|
24
41
|
## Automatic compilation
|
25
42
|
|
26
43
|
Vitrine is for **development**. It takes runtime compilation to 11 and beyound. Running tasks
|
27
44
|
is all fine and good when you build out the app for production, but when iterating on UI it's essential
|
28
|
-
to be able to just yank the file in there and carry on.
|
45
|
+
to be able to just yank the file in there and carry on. Compilation perks include:
|
29
46
|
|
30
47
|
* Any `.scss` file you shove into the `public` directory can be referenced as `.css` from your HTML.
|
31
48
|
Ask for `foo.css` and `foo.scss` will be compiled on the fly.
|
32
49
|
* Any `.coffee` file you shove into the `public` directory can be references as `.js` from your HTML.
|
33
50
|
Ask for `bar.js` and `bar.coffee` will be compiled on the fly.
|
34
|
-
* CoffeeScript files will have
|
35
|
-
|
51
|
+
* CoffeeScript and SCSS files will have sourcemaps out of the box for pleasant browser debugging
|
52
|
+
(something Sprockets still cannot do properly)
|
53
|
+
* Decent error messages will be shown for both invalid SCSS and invalid CoffeeScript, including
|
54
|
+
proper line reference for syntax errors (something Sprockets still cannot do properly)
|
55
|
+
|
56
|
+
Vitrine favors **runtime assembly** for JavaScript and CSS. That is: load many files into your page
|
57
|
+
in development mode, and build them into one chunk using external tools on deployment only.
|
58
|
+
|
59
|
+
This helps accelerating the roundtrip time because if you use asset compilation on every reload
|
60
|
+
when designing the UI you can easily get into the compile-concat-minify roundtrip times of more
|
61
|
+
than a few seconds. This is too much.
|
62
|
+
|
63
|
+
You are totally free to use your own compile-concat-minify pipelines when building for production.
|
64
|
+
Unlike Sprockets Vitrine does not force you to inject any specific preprocessor directives into
|
65
|
+
your scripts or CSS - this also facilitates debugging a GREAT LOT.
|
36
66
|
|
37
67
|
## Asset caching
|
38
68
|
|
39
69
|
Succesfully compiled assets will be ETagged based on their mtime. You should run an HTTP caching
|
40
|
-
proxy on top of
|
70
|
+
proxy on top of Vitrine if you use it in production.
|
41
71
|
|
42
72
|
## Automatic Ruby template pickup
|
43
73
|
|
data/lib/asset_compiler.rb
CHANGED
@@ -88,8 +88,8 @@ class Vitrine::AssetCompiler < Sinatra::Base
|
|
88
88
|
# sourcemap header saved if we write out the compiled JS,
|
89
89
|
# whereas otherwise it would have been discarded
|
90
90
|
[
|
91
|
+
Vitrine.compile_coffeescript(source_body),
|
91
92
|
"//# sourceMappingURL=#{basename}.js.map",
|
92
|
-
Vitrine.compile_coffeescript(source_body)
|
93
93
|
].join("\n")
|
94
94
|
rescue Errno::ENOENT # Missing CoffeeScript
|
95
95
|
forward_or_halt "No such JS file and could not find a .coffee replacement"
|
data/lib/sourcemaps.rb
CHANGED
@@ -5,9 +5,11 @@ module Vitrine
|
|
5
5
|
|
6
6
|
# We need to override the Sass importer
|
7
7
|
# so that it gives us URLs relative to the server root for sourcemaps
|
8
|
-
class
|
8
|
+
class SassImporter < Sass::Importers::Filesystem
|
9
9
|
def public_url(of_filesystem_path)
|
10
|
-
|
10
|
+
# Importer defines a basic attribute called "root" which we set when initializing
|
11
|
+
# We have to return the server-relative URL of the path from here
|
12
|
+
'/' + Pathname.new(of_filesystem_path).relative_path_from(Pathname.new(root)).to_s
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
@@ -16,9 +18,9 @@ module Vitrine
|
|
16
18
|
# Compute the paths relative to the webserver public root
|
17
19
|
scss_uri = '/' + Pathname.new(scss_path).relative_path_from(Pathname.new(public_folder_path)).to_s
|
18
20
|
css_uri = scss_uri.gsub(/\.scss$/, '.css')
|
19
|
-
sourcemap_uri= css_uri + '.map'
|
21
|
+
sourcemap_uri = css_uri + '.map'
|
20
22
|
|
21
|
-
engine_opts = {importer:
|
23
|
+
engine_opts = {importer: SassImporter.new(public_folder_path), sourcemap: true, cache: false}
|
22
24
|
map_options = {css_path: css_uri, sourcemap_path: sourcemap_uri }
|
23
25
|
|
24
26
|
engine = Sass::Engine.for_file(scss_path, engine_opts)
|
@@ -27,8 +29,8 @@ module Vitrine
|
|
27
29
|
rendered, mapping = engine.render_with_sourcemap(sourcemap_uri)
|
28
30
|
|
29
31
|
# Serialize the sourcemap
|
30
|
-
# We need to pass
|
31
|
-
# file that can be pulled
|
32
|
+
# We need to pass the map options so that the generated sourcemap refers to the
|
33
|
+
# file that can be pulled off the server as opposed to a file on the filesystem
|
32
34
|
sourcemap_body = mapping.to_json(map_options)
|
33
35
|
|
34
36
|
# We are using a pre-release version of SASS which still had old sourcemap reference
|
@@ -36,6 +38,8 @@ module Vitrine
|
|
36
38
|
chunk = Regexp.escape('/*@ sourceMappingURL')
|
37
39
|
replacement = '/*# sourceMappingURL'
|
38
40
|
re = /^#{chunk}/
|
41
|
+
|
42
|
+
# And return both
|
39
43
|
[rendered.gsub(re,replacement), sourcemap_body]
|
40
44
|
end
|
41
45
|
|
data/lib/version.rb
CHANGED
@@ -18,9 +18,11 @@ class TestVitrineAssetCompiler < Test::Unit::TestCase
|
|
18
18
|
assert_equal 200, last_response.status
|
19
19
|
assert_equal 'text/javascript;charset=utf-8', last_response.content_type
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
assert_include last_response.body, 'alert("rockage!")', 'Should include the compiled function'
|
22
|
+
assert_include last_response.body, '//# sourceMappingURL=/nice.js.map', 'Should include the reference to the source map'
|
23
|
+
|
24
|
+
last_line = last_response.body.split("\n").pop
|
25
|
+
assert_include last_line, 'sourceMappingURL'
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_compiles_coffeescript_sourcemap
|
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.
|
8
|
+
s.version = "0.0.22"
|
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-
|
12
|
+
s.date = "2014-01-14"
|
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.
|
4
|
+
version: 0.0.22
|
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-
|
11
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|