roger_sassc 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91b6039cbafc9ee6acdfd7800ee47ddcca4aa10a
4
- data.tar.gz: e38dd16bd62dba9768eea6101fcd28b578f8e9f6
3
+ metadata.gz: b60d9ab78717d99ca86d35f7b82b1ffc3449215f
4
+ data.tar.gz: ef6e144662222e549bcca649fb7283bb2cdbdce1
5
5
  SHA512:
6
- metadata.gz: 4e14ca200660ad01d1f04e7886f919f65097d651b03ca3660532bf41cfaeb6d66dbb331b68fc1cdc490d1f9874b2d35808b1f5681d9935a11bcda359ef17e455
7
- data.tar.gz: 00fdc39be355f740160a9d660fc01e050afd314f4db22ae62ba6f3e0a96d59c7a19bb49ce2f939427fdf4e7f0b5cd1dbbf0abe0acea0e117cf028168e4d657cb
6
+ metadata.gz: f6480795dc4bfc30e09e93ee3380b78379e8d99d67b2d4271d5574a3a741216dadca54fe7af9a8a92f74e17d40c5ea33a85ada8bc997ce18ef0429a174b092e7
7
+ data.tar.gz: a51940be9fc2a9ee8da59767d8dd3bcf10457d283a85ac98c2ed99c5904e25df7157dba4c1938f9768220e3d3c0f647b1bb110668755b9291077e2fbb1bca423
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .ruby-version
@@ -10,6 +10,7 @@ module RogerSassc
10
10
  # compiles (with the help of libsass) the scss.
11
11
  class Middleware
12
12
  attr_writer :resolver
13
+ attr_accessor :project
13
14
 
14
15
  def initialize(app, options = {})
15
16
  @app = app
@@ -22,7 +23,8 @@ module RogerSassc
22
23
  end
23
24
 
24
25
  def call(env)
25
- @project = env["roger.project"]
26
+ @project ||= env["roger.project"]
27
+ @options[:roger_html_path] = @project.html_path
26
28
 
27
29
  url = ::Rack::Utils.unescape(env["PATH_INFO"].to_s).sub(%r{^/}, "")
28
30
 
@@ -34,7 +36,9 @@ module RogerSassc
34
36
  begin
35
37
  css = compile_scss(scss_path)
36
38
  respond(css)
37
- rescue SassC::SyntaxError, SassC::NotRenderedError, SassC::InvalidStyleError => sassc_error
39
+ rescue ::SassC::SyntaxError,
40
+ ::SassC::NotRenderedError,
41
+ ::SassC::InvalidStyleError => sassc_error
38
42
  respond(debug_css(sassc_error))
39
43
  end
40
44
  else
@@ -57,7 +61,7 @@ module RogerSassc
57
61
  # Supply the filename for load path resolving
58
62
  @options[:filename] = scss_path.to_s
59
63
 
60
- SassC::Engine.new(File.read(scss_path), @options).render
64
+ ::SassC::Engine.new(File.read(scss_path), @options).render
61
65
  end
62
66
 
63
67
  def debug_css(sassc_error)
@@ -19,6 +19,7 @@ module RogerSassc
19
19
  # :build_files
20
20
  def call(release, options = {})
21
21
  @options = @options.update(options)
22
+ @options[:roger_html_path] = release.build_path
22
23
 
23
24
  match = @options.delete(:match)
24
25
  skip = @options.delete(:skip)
@@ -50,7 +51,7 @@ module RogerSassc
50
51
  scss = File.read(path)
51
52
 
52
53
  File.open(path.gsub(/\.scss$/, ".css"), "w+") do |file|
53
- file.write(SassC::Engine.new(scss, @options).render)
54
+ file.write(::SassC::Engine.new(scss, @options).render)
54
55
  end
55
56
  end
56
57
  end
@@ -0,0 +1,43 @@
1
+ require "sassc"
2
+ require "digest"
3
+
4
+ module RogerSassc
5
+ module SassC
6
+ # Defintion of asset functions
7
+ module AssetFunctions
8
+ # The asset_path method will search for
9
+ # the file and if it exists will append a fingerprint
10
+ # hexdigest to the output url (?v=DIGEST)
11
+ def asset_path(path)
12
+ file = find_file(path)
13
+
14
+ if File.exist?(file)
15
+ digest = Digest::SHA256.file(file).hexdigest
16
+ finger_printed_path = "#{path}?v=#{digest}"
17
+ else
18
+ finger_printed_path = path.value
19
+ end
20
+
21
+ ::SassC::Script::String.new("url(#{finger_printed_path})", :identifier)
22
+ end
23
+
24
+ private
25
+
26
+ # Translate the given path to a path on disk
27
+ def find_file(path)
28
+ # Absolute url, starting with /
29
+ if path.value.match(%r{^\/[^\/]})
30
+ File.join(@options[:roger_html_path], path.value)
31
+ else
32
+ # Relative url - we can join from .scss position
33
+ File.join(File.dirname(@options[:filename]), path.value)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ # SassC includes ruby functions for us
41
+ module ::SassC::Script::Functions
42
+ include ::RogerSassc::SassC::AssetFunctions
43
+ end
@@ -1,4 +1,4 @@
1
1
  # Version number
2
2
  module RogerSassc
3
- VERSION = "0.2.1"
3
+ VERSION = "0.4.0"
4
4
  end
data/lib/roger_sassc.rb CHANGED
@@ -29,5 +29,9 @@ RogerSassc.load_paths = RogerSassc::DEFAULT_LOAD_PATHS.dup
29
29
  # supply assets such as bourbon and neat
30
30
  RogerSassc.append_path(Sass.load_paths) if defined?(Sass.load_paths)
31
31
 
32
+ # Load our custom SASSC functions
33
+ require "roger_sassc/sassc/asset_functions"
34
+
35
+ # The middleware and processor
32
36
  require "roger_sassc/middleware"
33
37
  require "roger_sassc/processor"
@@ -0,0 +1,60 @@
1
+ require "test_helper"
2
+ require "sassc"
3
+ require "./lib/roger_sassc/sassc/asset_functions"
4
+
5
+ module RogerSassc
6
+ # Test for AssetFunctions module
7
+ class TestAssetFunctions < ::Test::Unit::TestCase
8
+ def test_asset_path_fingerprinting_non_existing_file
9
+ scss_path = "test/fixtures/asset_functions/asset_path_non_existing.scss"
10
+ engine = get_engine_for(scss_path)
11
+
12
+ assert_equal <<-EXPECTED_SCSS, engine.render
13
+ div {
14
+ background-image: url(./images/logo.svg); }
15
+ EXPECTED_SCSS
16
+ end
17
+
18
+ def test_asset_path_fingerprinting_relative_path
19
+ scss_path = "test/fixtures/asset_functions/asset_path_relative_path.scss"
20
+ engine = get_engine_for(scss_path)
21
+ # rubocop:disable LineLength
22
+ assert_equal <<-EXPECTED_SCSS, engine.render
23
+ div {
24
+ background-image: url(../images/logo.svg?v=73001d8781487200a29e7d3602b59d2770060934fbd738bfdcd2bc06a2861464); }
25
+ EXPECTED_SCSS
26
+ # rubocop:enable LineLength
27
+ end
28
+
29
+ def test_asset_path_asset_fingerprinting_http_path
30
+ scss_path = "test/fixtures/asset_functions/asset_path_http_path.scss"
31
+ engine = get_engine_for(scss_path)
32
+
33
+ assert_equal <<-EXPECTED_SCSS, engine.render
34
+ div {
35
+ background-image: url(http://google.com/images/logo.svg); }
36
+ EXPECTED_SCSS
37
+ end
38
+
39
+ def test_asset_path_fingerprinting_absolute_path
40
+ scss_path = "test/fixtures/asset_functions/asset_path_absolute_path.scss"
41
+ engine = get_engine_for(scss_path)
42
+
43
+ # rubocop:disable LineLength
44
+ assert_equal <<-EXPECTED_SCSS, engine.render
45
+ div {
46
+ background-image: url(/images/logo.svg?v=73001d8781487200a29e7d3602b59d2770060934fbd738bfdcd2bc06a2861464); }
47
+ EXPECTED_SCSS
48
+ # rubocop:enable LineLength
49
+ end
50
+
51
+ private
52
+
53
+ def get_engine_for(scss_path)
54
+ options = {}
55
+ options[:roger_html_path] = Pathname.new("test/fixtures").expand_path
56
+ options[:filename] = scss_path.to_s
57
+ ::SassC::Engine.new(File.read(scss_path), options)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ div {
2
+ background-image: asset-path('/images/logo.svg');
3
+ }
@@ -0,0 +1,3 @@
1
+ div {
2
+ background-image: asset-path('http://google.com/images/logo.svg');
3
+ }
@@ -0,0 +1,3 @@
1
+ div {
2
+ background-image: asset-path('./images/logo.svg');
3
+ }
@@ -0,0 +1,3 @@
1
+ div {
2
+ background-image: asset-path('../images/logo.svg');
3
+ }
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.0"
3
+ width="38" height="32" viewBox="0 0 39.875 33.6667">
4
+ <path style="stroke: none; fill: #323296;" d="M 10,0 L 30.5,0 39.875,17.5 30.5,33.6667 10,33.6667 L 0,17.5 L 10,0 z"/>
5
+ </svg>
@@ -1,4 +1,6 @@
1
1
  require "test_helper"
2
+ require "roger/testing/mock_project"
3
+
2
4
  require "./lib/roger_sassc/middleware"
3
5
 
4
6
  module RogerSassc
@@ -11,9 +13,19 @@ module RogerSassc
11
13
  @app = proc { [200, {}, ["YAM"]] } # Yet another middleware
12
14
  @middleware = Middleware.new @app
13
15
 
16
+ # Inject mock project
17
+ @middleware.project = Roger::Testing::MockProject.new
18
+
19
+ # Avoid side-effect of cwd dir of test_construct
20
+ @middleware.project.construct.revert_cwd
21
+
14
22
  @request = Rack::MockRequest.new(@middleware)
15
23
  end
16
24
 
25
+ def teardown
26
+ @middleware.project.destroy
27
+ end
28
+
17
29
  def test_middleware_can_be_called
18
30
  assert(@middleware.respond_to?(:call))
19
31
  end
@@ -1,5 +1,6 @@
1
1
  require "test_helper"
2
2
  require "fileutils"
3
+ require "roger/testing/mock_release"
3
4
  require "./lib/roger_sassc/processor"
4
5
 
5
6
  module RogerSassc
@@ -7,39 +8,40 @@ module RogerSassc
7
8
  class TestProcessor < ::Test::Unit::TestCase
8
9
  include FixtureHelper
9
10
 
10
- TEST_OUTPUT = "../../tmp/test/fixtures/"
11
-
12
11
  def setup
13
- @processor = Processor.new {}
14
- @processor.stubs(:build_path).returns("./")
15
-
16
- # Copy fixtures files to fixtures/out
17
- output_path = fixture_path(TEST_OUTPUT)
18
- FileUtils.rm_rf output_path
19
- FileUtils.mkdir_p output_path
20
- FileUtils.cp_r fixture_path("."), output_path
12
+ @release = Roger::Testing::MockRelease.new
13
+ @release.project.construct.directory "build" do |dir|
14
+ @test_output = dir.directory "test/fixtures/"
15
+ FileUtils.cp_r fixture_path("."), @test_output
16
+ end
17
+
18
+ @processor = Processor.new
19
+ end
20
+
21
+ def teardown
22
+ @release.destroy
21
23
  end
22
24
 
23
25
  def test_processor_can_be_called
24
26
  assert_respond_to(@processor, :call)
25
27
  end
26
28
 
27
- # Meh :(
28
29
  def test_call_processor
29
30
  files = [
30
- fixture_path(TEST_OUTPUT + "general.scss"),
31
- fixture_path(TEST_OUTPUT + "src/_variables.scss")
31
+ (@test_output + "general.scss").to_s,
32
+ (@test_output + "src/_variables.scss").to_s
32
33
  ]
33
34
 
34
- release = release_mock(files)
35
+ stub_get_files(files)
36
+
35
37
  expected_css = fixture "output.css"
36
- @processor.call release
38
+ @processor.call @release
37
39
 
38
40
  # File is created
39
- assert_path_exist fixture_path(TEST_OUTPUT + "general.css")
41
+ assert_path_exist @test_output + "general.css"
40
42
 
41
43
  # And matches earlier output
42
- assert_equal fixture(TEST_OUTPUT + "general.css"), expected_css
44
+ assert_equal File.read(@test_output + "general.css"), expected_css
43
45
 
44
46
  # Check clean up
45
47
  assert_path_not_exist files[0]
@@ -48,23 +50,22 @@ module RogerSassc
48
50
 
49
51
  def test_processor_raises_on_compilation_errors
50
52
  files = [
51
- fixture_path(TEST_OUTPUT + "raise.scss")
53
+ (@test_output + "raise.scss").to_s
52
54
  ]
53
55
 
54
- release = release_mock(files)
56
+ stub_get_files(files)
55
57
 
56
- assert_raise SassC::SyntaxError do
57
- @processor.call release
58
+ assert_raise ::SassC::SyntaxError do
59
+ @processor.call @release
58
60
  end
59
61
  end
60
62
 
61
63
  private
62
64
 
63
- def release_mock(files)
64
- release = mock(get_files: files,
65
- log: ->(_s, _m) {})
66
-
67
- release
65
+ # Stub is used so we can controll what files
66
+ # are ran through the processor.
67
+ def stub_get_files(files)
68
+ @release.stubs(:get_files).returns(files)
68
69
  end
69
70
  end
70
71
  end
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roger_sassc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin van der Graaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sassc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: roger
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rack
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
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
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: test-unit
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
89
  version: 3.1.2
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.1.2
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ~>
102
102
  - !ruby/object:Gem::Version
103
103
  version: 0.10.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.10.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
117
  version: 0.31.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.31.0
125
125
  description:
@@ -129,10 +129,10 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
- - ".gitignore"
133
- - ".hound.yml"
134
- - ".rubocop.yml"
135
- - ".travis.yml"
132
+ - .gitignore
133
+ - .hound.yml
134
+ - .rubocop.yml
135
+ - .travis.yml
136
136
  - Gemfile
137
137
  - LICENSE.txt
138
138
  - README.md
@@ -140,12 +140,19 @@ files:
140
140
  - lib/roger_sassc.rb
141
141
  - lib/roger_sassc/middleware.rb
142
142
  - lib/roger_sassc/processor.rb
143
+ - lib/roger_sassc/sassc/asset_functions.rb
143
144
  - lib/roger_sassc/version.rb
144
145
  - roger_sassc.gemspec
146
+ - test/asset_functions_test.rb
147
+ - test/fixtures/asset_functions/asset_path_absolute_path.scss
148
+ - test/fixtures/asset_functions/asset_path_http_path.scss
149
+ - test/fixtures/asset_functions/asset_path_non_existing.scss
150
+ - test/fixtures/asset_functions/asset_path_relative_path.scss
145
151
  - test/fixtures/errors/import.scss
146
152
  - test/fixtures/errors/syntax.css
147
153
  - test/fixtures/errors/syntax.scss
148
154
  - test/fixtures/general.scss
155
+ - test/fixtures/images/logo.svg
149
156
  - test/fixtures/output.css
150
157
  - test/fixtures/raise.scss
151
158
  - test/fixtures/src/_variables.scss
@@ -164,12 +171,12 @@ require_paths:
164
171
  - lib
165
172
  required_ruby_version: !ruby/object:Gem::Requirement
166
173
  requirements:
167
- - - ">="
174
+ - - '>='
168
175
  - !ruby/object:Gem::Version
169
176
  version: '0'
170
177
  required_rubygems_version: !ruby/object:Gem::Requirement
171
178
  requirements:
172
- - - ">="
179
+ - - '>='
173
180
  - !ruby/object:Gem::Version
174
181
  version: '0'
175
182
  requirements: []
@@ -179,10 +186,16 @@ signing_key:
179
186
  specification_version: 4
180
187
  summary: Sass plugin for Roger based on libsass
181
188
  test_files:
189
+ - test/asset_functions_test.rb
190
+ - test/fixtures/asset_functions/asset_path_absolute_path.scss
191
+ - test/fixtures/asset_functions/asset_path_http_path.scss
192
+ - test/fixtures/asset_functions/asset_path_non_existing.scss
193
+ - test/fixtures/asset_functions/asset_path_relative_path.scss
182
194
  - test/fixtures/errors/import.scss
183
195
  - test/fixtures/errors/syntax.css
184
196
  - test/fixtures/errors/syntax.scss
185
197
  - test/fixtures/general.scss
198
+ - test/fixtures/images/logo.svg
186
199
  - test/fixtures/output.css
187
200
  - test/fixtures/raise.scss
188
201
  - test/fixtures/src/_variables.scss