vitrine 0.0.19 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +20 -1
- data/lib/asset_compiler.rb +24 -13
- data/lib/sourcemaps.rb +48 -0
- data/lib/version.rb +1 -1
- data/test/test_vitrine_asset_compiler.rb +15 -3
- data/vitrine.gemspec +5 -5
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49fedd846e606aff4360c45e4556e2e414825970
|
4
|
+
data.tar.gz: 5729915ef21f08204acd7c20c19b0d0ab4a425c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7d58844b0376a6815342d87dc3b44cbd36eaf9825ffdf4401264ced9b67688b4a95c411e5abcc8bae5c06716f43a84e086411855936e71417ff6e351e3afe68
|
7
|
+
data.tar.gz: bcaa8447a233db781468ca3a58e3faf193f88823ae1559b0d180f14b538397e4a3539acd85b243ea244faac5d950d093b93c64b9a141c65e347836052457ae83
|
data/Gemfile
CHANGED
@@ -2,7 +2,26 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
gem 'sinatra', '~> 1.4', require: 'sinatra/base'
|
4
4
|
gem 'coffee-script', '~> 2.2'
|
5
|
-
|
5
|
+
|
6
|
+
=begin
|
7
|
+
|
8
|
+
Now here we get into an issue. I am using Guard BIG TIME.
|
9
|
+
That means that Sass above this version will puke out because
|
10
|
+
the Sass authors wisely decided to burden me with having a version
|
11
|
+
of 'listen' even though I never use their watching features.
|
12
|
+
|
13
|
+
According to this:
|
14
|
+
https://rubygems.org/api/v1/dependencies?gems=sass
|
15
|
+
the last version of SASS which does not have a "listen" dependency
|
16
|
+
is '3.3.0.alpha.136', so this is what we are going to depend on
|
17
|
+
until at least this issue is resolved
|
18
|
+
|
19
|
+
https://github.com/nex3/sass/pull/982
|
20
|
+
|
21
|
+
Better still, SASS authors should remove filesystem watching or implement
|
22
|
+
it in a portable/vendored manner.
|
23
|
+
=end
|
24
|
+
gem 'sass', '3.3.0.alpha.136'
|
6
25
|
gem 'rack-contrib'
|
7
26
|
gem 'rack-livereload'
|
8
27
|
|
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,54 @@ 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
|
+
# We are using a pre-release version of SASS which still had old sourcemap reference
|
35
|
+
# syntax, so we have to fix it by hand
|
36
|
+
chunk = Regexp.escape('/*@ sourceMappingURL')
|
37
|
+
replacement = '/*# sourceMappingURL'
|
38
|
+
re = /^#{chunk}/
|
39
|
+
[rendered.gsub(re,replacement), sourcemap_body]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Compile SASS and return the source map only
|
43
|
+
def self.compile_sass_source_map(scss_path, public_folder_path)
|
44
|
+
css, map = compile_sass_and_sourcemap(scss_path, public_folder_path)
|
45
|
+
map
|
46
|
+
end
|
47
|
+
|
48
|
+
# Compiles SASS and it's sourcemap and returns the CSS only
|
49
|
+
def self.compile_sass(scss_path, public_folder_path)
|
50
|
+
css, map = compile_sass_and_sourcemap(scss_path, public_folder_path)
|
51
|
+
css
|
52
|
+
end
|
53
|
+
|
6
54
|
# Compile a script (String or IO) to JavaScript.
|
7
55
|
# This is a version lifted from here
|
8
56
|
# 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.21"
|
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-13"
|
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,7 +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>, ["
|
52
|
+
s.add_runtime_dependency(%q<sass>, ["= 3.3.0.alpha.136"])
|
53
53
|
s.add_runtime_dependency(%q<rack-contrib>, [">= 0"])
|
54
54
|
s.add_runtime_dependency(%q<rack-livereload>, [">= 0"])
|
55
55
|
s.add_development_dependency(%q<guard>, ["~> 2.2"])
|
@@ -63,7 +63,7 @@ Gem::Specification.new do |s|
|
|
63
63
|
else
|
64
64
|
s.add_dependency(%q<sinatra>, ["~> 1.4"])
|
65
65
|
s.add_dependency(%q<coffee-script>, ["~> 2.2"])
|
66
|
-
s.add_dependency(%q<sass>, ["
|
66
|
+
s.add_dependency(%q<sass>, ["= 3.3.0.alpha.136"])
|
67
67
|
s.add_dependency(%q<rack-contrib>, [">= 0"])
|
68
68
|
s.add_dependency(%q<rack-livereload>, [">= 0"])
|
69
69
|
s.add_dependency(%q<guard>, ["~> 2.2"])
|
@@ -78,7 +78,7 @@ Gem::Specification.new do |s|
|
|
78
78
|
else
|
79
79
|
s.add_dependency(%q<sinatra>, ["~> 1.4"])
|
80
80
|
s.add_dependency(%q<coffee-script>, ["~> 2.2"])
|
81
|
-
s.add_dependency(%q<sass>, ["
|
81
|
+
s.add_dependency(%q<sass>, ["= 3.3.0.alpha.136"])
|
82
82
|
s.add_dependency(%q<rack-contrib>, [">= 0"])
|
83
83
|
s.add_dependency(%q<rack-livereload>, [">= 0"])
|
84
84
|
s.add_dependency(%q<guard>, ["~> 2.2"])
|
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.21
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: sass
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.3.0.alpha.136
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.3.0.alpha.136
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-contrib
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|