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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4e9452a9802c22e3cd800ed12520dcfa01e0a15
4
- data.tar.gz: 35f02e34fca96a5284d39aecdaca1e7667461da2
3
+ metadata.gz: 49fedd846e606aff4360c45e4556e2e414825970
4
+ data.tar.gz: 5729915ef21f08204acd7c20c19b0d0ab4a425c5
5
5
  SHA512:
6
- metadata.gz: 0e0cfdf1366282057c2d42dbe33843978f124df3c521a92aa44b33277af3825163b108a742f1db7448d77f632772213f2e7902e6c720dcefb6ecc52bb6bd5156
7
- data.tar.gz: 9a810b28d393939b931ae6df6d019a8dc283764ca6334e62bb2a22151eee20c091c6fec2a4b8402be857039ac6951eb620e42ba99cd4a2882243d6468ef070c4
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
- gem 'sass', '~> 3'
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
 
@@ -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/ do | basename |
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
- # Add a generated DOM element before <body/> to inject
44
- # a visible error message
45
- error_tpl = 'body:before {
46
- background: white; padding: 3px; font-family: monospaced; color: red;
47
- font-size: 14px; content: %s }'
48
- css_message = error_tpl % [e.class, "\n", "--> ", e.message].join.inspect
49
- # If we halt with 500 this will not be shown as CSS
50
- halt 200, css_message
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
@@ -1,3 +1,3 @@
1
1
  module Vitrine
2
- VERSION = '0.0.19'
2
+ VERSION = '0.0.21'
3
3
  end
@@ -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
- assert last_response.body.include?('.foo .bar {'), 'Should have compiled the CSS rule'
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.19"
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"
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>, ["~> 3"])
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>, ["~> 3"])
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>, ["~> 3"])
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.19
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-12 00:00:00.000000000 Z
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: '3'
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: '3'
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