vitrine 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/lib/asset_compiler.rb +24 -13
- data/lib/sourcemaps.rb +43 -0
- data/lib/version.rb +1 -1
- data/test/test_vitrine_asset_compiler.rb +15 -3
- data/vitrine.gemspec +5 -11
- metadata +6 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc4ee8209933285451897b7e350f08d688415809
|
4
|
+
data.tar.gz: ee63f9d1f096126084c62426139533431c5a474e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14101114ebe8d809b452a2424b19833335498949cb39ed280377854f6fa06e8051c9d1c089f5fbc774aec7b1c89e8dbf9c4fc088f4c0f20799f4414b42c8e174
|
7
|
+
data.tar.gz: 65ccc5b3cf467b38a8ad86ba5d2f48bf9e6e89aed72345e60311162ef6ca39246fb4d8150561899be080f0e6f431ac055a8bd3cd0d489b9ae6d808349ac1a50f
|
data/Gemfile
CHANGED
data/lib/asset_compiler.rb
CHANGED
@@ -27,30 +27,41 @@ class Vitrine::AssetCompiler < Sinatra::Base
|
|
27
27
|
attr_accessor :public_dir
|
28
28
|
|
29
29
|
# Try to find SCSS replacement for missing CSS
|
30
|
-
get /(.+)\.css
|
30
|
+
get /(.+)\.css$/ do | basename |
|
31
|
+
# Return vanilla CSS
|
32
|
+
if File.exist?(File.join(get_public, basename + '.css'))
|
33
|
+
return send_file(File.join(get_public, basename + '.css'))
|
34
|
+
end
|
35
|
+
|
31
36
|
begin
|
32
37
|
# TODO: handle .sass ext as well
|
33
38
|
scss_source_path = File.join(get_public, "#{basename}.scss")
|
34
39
|
mtime_cache(scss_source_path)
|
35
40
|
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')
|
41
|
+
Vitrine.compile_sass(scss_source_path, get_public)
|
40
42
|
rescue Errno::ENOENT # Missing SCSS
|
41
43
|
forward_or_halt "No such CSS or SCSS file found"
|
42
44
|
rescue Exception => e # CSS syntax error or something alike
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
# Add a generated DOM element before <body/> to inject
|
46
|
+
# a visible error message
|
47
|
+
error_tpl = 'body:before {
|
48
|
+
background: white; padding: 3px; font-family: monospaced; color: red;
|
49
|
+
font-size: 14px; content: %s }'
|
50
|
+
css_message = error_tpl % [e.class, "\n", "--> ", e.message].join.inspect
|
51
|
+
# If we halt with 500 this will not be shown as CSS
|
52
|
+
halt 200, css_message
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
56
|
+
# Try to find SCSS replacement for missing CSS
|
57
|
+
get /(.+)\.css\.map$/ do | basename |
|
58
|
+
# TODO: handle .sass ext as well
|
59
|
+
scss_source_path = File.join(get_public, "#{basename}.scss")
|
60
|
+
mtime_cache(scss_source_path)
|
61
|
+
content_type 'application/json', :charset => 'utf-8'
|
62
|
+
Vitrine.compile_sass_source_map(scss_source_path, get_public)
|
63
|
+
end
|
64
|
+
|
54
65
|
# Generate a sourcemap for CoffeeScript files
|
55
66
|
get /(.+)\.js\.map$/ do | basename |
|
56
67
|
begin
|
data/lib/sourcemaps.rb
CHANGED
@@ -3,6 +3,49 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Vitrine
|
5
5
|
|
6
|
+
# We need to override the Sass importer
|
7
|
+
# so that it gives us URLs relative to the server root for sourcemaps
|
8
|
+
class Imp < Sass::Importers::Filesystem
|
9
|
+
def public_url(of_filesystem_path)
|
10
|
+
scss_uri = '/' + Pathname.new(of_filesystem_path).relative_path_from(Pathname.new(root)).to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Compile a SASS/SCSS file to CSS
|
15
|
+
def self.compile_sass_and_sourcemap(scss_path, public_folder_path)
|
16
|
+
# Compute the paths relative to the webserver public root
|
17
|
+
scss_uri = '/' + Pathname.new(scss_path).relative_path_from(Pathname.new(public_folder_path)).to_s
|
18
|
+
css_uri = scss_uri.gsub(/\.scss$/, '.css')
|
19
|
+
sourcemap_uri= css_uri + '.map'
|
20
|
+
|
21
|
+
engine_opts = {importer: Imp.new(public_folder_path), sourcemap: true, cache: false}
|
22
|
+
map_options = {css_path: css_uri, sourcemap_path: sourcemap_uri }
|
23
|
+
|
24
|
+
engine = Sass::Engine.for_file(scss_path, engine_opts)
|
25
|
+
|
26
|
+
# Determine the sourcemap URL for the SASS file
|
27
|
+
rendered, mapping = engine.render_with_sourcemap(sourcemap_uri)
|
28
|
+
|
29
|
+
# Serialize the sourcemap
|
30
|
+
# We need to pass css_uri: so that the generated sourcemap refers to the
|
31
|
+
# file that can be pulled of the server as opposed to a file on the filesystem
|
32
|
+
sourcemap_body = mapping.to_json(map_options)
|
33
|
+
|
34
|
+
[rendered, sourcemap_body]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Compile SASS and return the source map only
|
38
|
+
def self.compile_sass_source_map(scss_path, public_folder_path)
|
39
|
+
css, map = compile_sass_and_sourcemap(scss_path, public_folder_path)
|
40
|
+
map
|
41
|
+
end
|
42
|
+
|
43
|
+
# Compiles SASS and it's sourcemap and returns the CSS only
|
44
|
+
def self.compile_sass(scss_path, public_folder_path)
|
45
|
+
css, map = compile_sass_and_sourcemap(scss_path, public_folder_path)
|
46
|
+
css
|
47
|
+
end
|
48
|
+
|
6
49
|
# Compile a script (String or IO) to JavaScript.
|
7
50
|
# This is a version lifted from here
|
8
51
|
# https://github.com/josh/ruby-coffee-script/blob/114b65b638f66ba04b60bf9c24b54360260f9898/lib/coffee_script.rb
|
data/lib/version.rb
CHANGED
@@ -69,17 +69,29 @@ class TestVitrineAssetCompiler < Test::Unit::TestCase
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_compiles_scss_when_requested_as_css
|
72
|
-
write_public 'styles.scss' do | f |
|
72
|
+
write_public '/les-styles-rococo/styles.scss' do | f |
|
73
73
|
f.puts '.foo {'
|
74
74
|
f.puts '.bar { font-size: 10px; }'
|
75
75
|
f.puts '}'
|
76
76
|
end
|
77
77
|
|
78
|
-
get '/styles.css'
|
78
|
+
get '/les-styles-rococo/styles.css'
|
79
79
|
|
80
80
|
assert last_response.ok?
|
81
81
|
assert_not_nil last_response.headers['ETag'], 'Should set ETag for the compiled version'
|
82
|
-
|
82
|
+
assert_include last_response.body, '.foo .bar {'
|
83
|
+
assert_include last_response.body, '*# sourceMappingURL=/les-styles-rococo/styles.css.map */'
|
84
|
+
|
85
|
+
get '/les-styles-rococo/styles.css.map'
|
86
|
+
|
87
|
+
assert last_response.ok?
|
88
|
+
assert_equal "application/json;charset=utf-8", last_response.content_type
|
89
|
+
resp = {"version"=> 3,
|
90
|
+
"mappings"=> "AACA,SAAK;EAAE,SAAS,EAAE,IAAI",
|
91
|
+
"sources"=> ["/les-styles-rococo/styles.scss"],
|
92
|
+
"file" => "styles.css"
|
93
|
+
}
|
94
|
+
assert_equal resp, JSON.parse(last_response.body)
|
83
95
|
end
|
84
96
|
|
85
97
|
def test_displays_decent_alerts_for_scss_errors
|
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.18"
|
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-12"
|
13
13
|
s.description = " Serves ERB templates with live CoffeeScript and SASS "
|
14
14
|
s.email = "me@julik.nl"
|
15
15
|
s.executables = ["vitrine"]
|
@@ -49,9 +49,7 @@ Gem::Specification.new do |s|
|
|
49
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
50
|
s.add_runtime_dependency(%q<sinatra>, ["~> 1.4"])
|
51
51
|
s.add_runtime_dependency(%q<coffee-script>, ["~> 2.2"])
|
52
|
-
s.add_runtime_dependency(%q<sass>, ["
|
53
|
-
s.add_runtime_dependency(%q<guard>, ["~> 2.2"])
|
54
|
-
s.add_runtime_dependency(%q<guard-livereload>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<sass>, ["= 3.3.0.rc.2"])
|
55
53
|
s.add_runtime_dependency(%q<rack-contrib>, [">= 0"])
|
56
54
|
s.add_runtime_dependency(%q<rack-livereload>, [">= 0"])
|
57
55
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
@@ -64,9 +62,7 @@ Gem::Specification.new do |s|
|
|
64
62
|
else
|
65
63
|
s.add_dependency(%q<sinatra>, ["~> 1.4"])
|
66
64
|
s.add_dependency(%q<coffee-script>, ["~> 2.2"])
|
67
|
-
s.add_dependency(%q<sass>, ["
|
68
|
-
s.add_dependency(%q<guard>, ["~> 2.2"])
|
69
|
-
s.add_dependency(%q<guard-livereload>, [">= 0"])
|
65
|
+
s.add_dependency(%q<sass>, ["= 3.3.0.rc.2"])
|
70
66
|
s.add_dependency(%q<rack-contrib>, [">= 0"])
|
71
67
|
s.add_dependency(%q<rack-livereload>, [">= 0"])
|
72
68
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
@@ -80,9 +76,7 @@ Gem::Specification.new do |s|
|
|
80
76
|
else
|
81
77
|
s.add_dependency(%q<sinatra>, ["~> 1.4"])
|
82
78
|
s.add_dependency(%q<coffee-script>, ["~> 2.2"])
|
83
|
-
s.add_dependency(%q<sass>, ["
|
84
|
-
s.add_dependency(%q<guard>, ["~> 2.2"])
|
85
|
-
s.add_dependency(%q<guard-livereload>, [">= 0"])
|
79
|
+
s.add_dependency(%q<sass>, ["= 3.3.0.rc.2"])
|
86
80
|
s.add_dependency(%q<rack-contrib>, [">= 0"])
|
87
81
|
s.add_dependency(%q<rack-livereload>, [">= 0"])
|
88
82
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
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.18
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -42,44 +42,16 @@ dependencies:
|
|
42
42
|
name: sass
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '3'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '2.2'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '2.2'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: guard-livereload
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
45
|
+
- - '='
|
74
46
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
47
|
+
version: 3.3.0.rc.2
|
76
48
|
type: :runtime
|
77
49
|
prerelease: false
|
78
50
|
version_requirements: !ruby/object:Gem::Requirement
|
79
51
|
requirements:
|
80
|
-
- - '
|
52
|
+
- - '='
|
81
53
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
54
|
+
version: 3.3.0.rc.2
|
83
55
|
- !ruby/object:Gem::Dependency
|
84
56
|
name: rack-contrib
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|