sprockets-sass 2.0.0.beta1 → 2.0.0.beta2

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: 9af094799e7e501a8bd0e4d69f7a7fd79e2f3056
4
- data.tar.gz: d889b5fba8d6296978821c0c12aa8b063f8a4324
3
+ metadata.gz: e93b8e4aef5fc9d0fcc2e1a59a42b2942f73de0b
4
+ data.tar.gz: 52d6ac715c3bf79e861b3a66977d3d6883e92495
5
5
  SHA512:
6
- metadata.gz: 759bf41724fa6f5a2cafe99eb39ce7f0f15a820dce7cf1979589ecf13c93e245597a9c93cbb98602beba937da69463bed6441ef7eec20d0a70dce4e46ed0fd86
7
- data.tar.gz: 63fa7d50c5350bfd57ce0e0c2fdba2cf902632a767ed950a541e71ee7c82249abee870d7fe7a94a0724bd11608cf7be4ea30f87ac5e38ec875bb9045c186cf64
6
+ metadata.gz: eebe585d42892338ca846c7d0ad6ed922459c6944a06447bb100034bdf07fd4cdd74c87a4c4bdee7b834dcdfe9f421f68d4b318d26baf50d48ebb6ef408ce71a
7
+ data.tar.gz: 21be3f03e533819ac78355160727abc4cb2c00f0c709791d6a0ca0b538cac7c0e268546fb1c166bdeea9d830cb7590ddccd45c9d0cae332c19f0ddfc62874a9b
@@ -5,8 +5,6 @@ before_install:
5
5
  - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
6
6
  - gem install bundler
7
7
  rvm:
8
- - 2.0.0
9
- - 2.1.5
10
8
  - 2.2.2
11
9
  - 2.2.3
12
10
  - 2.3.1
@@ -171,12 +171,12 @@ module Sprockets
171
171
  []
172
172
  end
173
173
 
174
- def get_engines_from_attributes(attributes)
174
+ def get_engines_from_attributes(context, attributes)
175
175
  attributes.engines
176
176
  end
177
177
 
178
178
  def get_all_processors_for_evaluate(context, content_type, attributes, path)
179
- engines = get_engines_from_attributes(attributes)
179
+ engines = get_engines_from_attributes(context, attributes)
180
180
  preprocessors = get_context_preprocessors(context, content_type)
181
181
  additional_transformers = get_context_transformers(context, content_type, path)
182
182
  additional_transformers.reverse + preprocessors + engines.reverse
@@ -6,8 +6,8 @@ module Sprockets
6
6
  # class used for importing files from SCCS and SASS files
7
7
  class Importer < Sprockets::Sass::V2::Importer
8
8
  GLOB = /\*|\[.+\]/
9
-
10
- protected
9
+
10
+ protected
11
11
 
12
12
  def resolve_path_with_load_paths(context, path, root_path, file)
13
13
  context.resolve(file.to_s, load_paths: context.environment.paths, base_path: root_path, accept: syntax_mime_type(path))
@@ -43,10 +43,10 @@ module Sprockets
43
43
 
44
44
  def asset_requirable?(context, path)
45
45
  pathname = begin
46
- context.resolve(path)
47
- rescue
48
- nil
49
- end
46
+ context.resolve(path)
47
+ rescue
48
+ nil
49
+ end
50
50
  return false if pathname.nil?
51
51
  stat = stat_of_pathname(context, pathname, path)
52
52
  return false unless stat && stat.file?
@@ -118,6 +118,7 @@ module Sprockets
118
118
  metadata = (input[:metadata] || {}).dup
119
119
  metadata[:data] = input[:data]
120
120
  result = processor.call(input)
121
+ processors.delete(processor)
121
122
  handle_process_result(context, result, processors, metadata)
122
123
  end
123
124
 
@@ -137,14 +138,14 @@ module Sprockets
137
138
  def handle_process_result(context, result, processors, metadata)
138
139
  data = nil
139
140
  case result
140
- when NilClass
141
- data = metadata[:data]
142
- when Hash
143
- data = handle_complex_process_result(context, result, processors)
144
- when String
145
- data = result
146
- else
147
- raise Error, "invalid processor return type: #{result.class}"
141
+ when NilClass
142
+ data = metadata[:data]
143
+ when Hash
144
+ data = handle_complex_process_result(context, result, processors)
145
+ when String
146
+ data = result
147
+ else
148
+ raise Error, "invalid processor return type: #{result.class}"
148
149
  end
149
150
  data
150
151
  end
@@ -156,7 +157,6 @@ module Sprockets
156
157
  path = check_path_before_process(context, path)
157
158
  data = Sprockets::Sass::Utils.read_template_file(path.to_s)
158
159
  input = build_input_for_process(context, path, data)
159
-
160
160
  processors.each do |processor|
161
161
  data = call_processor_input(processor, context, input, processors)
162
162
  end
@@ -174,15 +174,27 @@ module Sprockets
174
174
  additional_transformers.is_a?(Array) ? additional_transformers : [additional_transformers]
175
175
  end
176
176
 
177
- def get_engines_from_attributes(_attributes)
178
- []
177
+ def get_engines_from_attributes(context, attributes)
178
+ engines = []
179
+ attributes[2].each do |extension|
180
+ ext = ::Sprockets::Utils.normalize_extension(extension)
181
+ ext_engines = context.environment.engines[ext]
182
+ ext_engines = ext_engines.is_a?(Array) ? ext_engines : [ext_engines]
183
+ engines.concat(ext_engines)
184
+ end
185
+ engines
179
186
  end
180
187
 
181
188
  def get_all_processors_for_evaluate(context, content_type, attributes, path)
182
- engines = get_engines_from_attributes(attributes)
189
+ engines = get_engines_from_attributes(context, attributes)
183
190
  preprocessors = get_context_preprocessors(context, content_type)
184
191
  additional_transformers = get_context_transformers(context, content_type, path)
185
- additional_transformers.reverse + preprocessors + engines.reverse
192
+ postprocessors = get_context_postprocessors(context, content_type)
193
+ engines.reverse + preprocessors + additional_transformers.reverse + postprocessors
194
+ end
195
+
196
+ def get_context_postprocessors(context, content_type)
197
+ context.environment.postprocessors[content_type].map { |a| a.class == Class ? a : a.class }
186
198
  end
187
199
 
188
200
  def filter_all_processors(processors)
@@ -85,6 +85,10 @@ module Sprockets
85
85
  end
86
86
  end
87
87
 
88
+ def get_engines_from_attributes(_context, _attributes)
89
+ []
90
+ end
91
+
88
92
  def call_processor_input(processor, context, input, processors)
89
93
  if processor.respond_to?(:processors)
90
94
  processor.processors = filter_all_processors(processor.processors)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Sprockets
3
3
  module Sass
4
- VERSION = '2.0.0.beta1'
4
+ VERSION = '2.0.0.beta2'
5
5
  end
6
6
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sprockets::Sass do
4
+
5
+
6
+ before :each do
7
+ @root = create_construct
8
+ @assets = @root.directory 'assets'
9
+ @public_dir = @root.directory 'public'
10
+ @env = Sprockets::Environment.new @root.to_s
11
+ @env.append_path @assets.to_s
12
+ @env.register_postprocessor 'text/css', FailPostProcessor
13
+ @test_registration = Sprockets::Sass::TestRegistration.new(@env)
14
+ @test_registration.register_engines('.xyz' => Sprockets::Sass::FakeEngine)
15
+ @importer_class = Sprockets::Sass::Utils.get_class_by_version("Importer")
16
+ end
17
+
18
+ before(:each) do
19
+ @assets.file 'main.css.scss', %(@import "dep")
20
+ @dep_path = @assets.file 'dep.css.xyz', "$color: blue;\nbody { color: $color; }"
21
+ end
22
+
23
+ after :each do
24
+ @root.destroy!
25
+ end
26
+
27
+ if (3...4).include?(Sprockets::Sass::Utils.version_of_sprockets)
28
+ it 'allow calls the get engines from attributes with proper arguments' do
29
+ expect_any_instance_of(@importer_class).to receive(:get_engines_from_attributes).with(anything, [@dep_path.to_s.gsub('.css.xyz', ''), "text/css", [".xyz"], nil]).at_least(:once).and_call_original
30
+ asset = @env['main.css']
31
+ end
32
+
33
+ it 'calls the normalize extension from sprockets utils' do
34
+ expect(::Sprockets::Utils).to receive(:normalize_extension).with('.xyz').at_least(:once).and_call_original
35
+ asset = @env['main.css']
36
+ end
37
+
38
+ it 'retursn the engines registered on the file path' do
39
+ expect_any_instance_of(@importer_class).to receive(:filter_all_processors).with(array_including(Sprockets::Sass::FakeEngine)).at_least(:once).and_call_original
40
+ asset = @env['main.css']
41
+ end
42
+ end
43
+
44
+ end
@@ -7,6 +7,15 @@ require 'compass'
7
7
  require 'test_construct'
8
8
 
9
9
  RSpec.configure do |config|
10
+ # rspec-expectations config goes here. You can use an alternate
11
+ # assertion/expectation library such as wrong or the stdlib/minitest
12
+ # assertions if you prefer.
13
+ config.expect_with :rspec
14
+ # rspec-mocks config goes here. You can use an alternate test double
15
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
16
+ config.mock_with :rspec
17
+
18
+ config.include RSpec::Matchers
10
19
  config.include TestConstruct::Helpers
11
20
  end
12
21
 
@@ -396,7 +396,7 @@ describe Sprockets::Sass do
396
396
  expect(res).to eql("div{color:red}\n")
397
397
  end
398
398
  end
399
-
399
+
400
400
 
401
401
  describe Sprockets::Sass::SassTemplate do
402
402
 
@@ -410,15 +410,15 @@ describe Sprockets::Sass do
410
410
  it 'does add Sass functions if sprockets-helpers is not available' do
411
411
  Sprockets::Sass::SassTemplate.sass_functions_initialized = false
412
412
  Sprockets::Sass.add_sass_functions = true
413
- Sprockets::Sass::SassTemplate.any_instance.should_receive(:require).with('sprockets/helpers').and_raise LoadError
414
- Sprockets::Sass::SassTemplate.any_instance.should_not_receive(:require).with 'sprockets/sass/functions'
413
+ expect_any_instance_of(Sprockets::Sass::SassTemplate).to receive(:require).with('sprockets/helpers').and_raise LoadError
414
+ expect_any_instance_of(Sprockets::Sass::SassTemplate).to_not receive(:require).with 'sprockets/sass/functions'
415
415
  template
416
416
  expect(Sprockets::Sass::SassTemplate.engine_initialized?).to be_falsy
417
417
  end
418
418
 
419
419
  it 'does not add Sass functions if add_sass_functions is false' do
420
420
  Sprockets::Sass.add_sass_functions = false
421
- template.should_not_receive(:require).with 'sprockets/sass/functions'
421
+ expect(template).to_not receive(:require).with 'sprockets/sass/functions'
422
422
  template.initialize_engine
423
423
  expect(Sprockets::Sass::SassTemplate.engine_initialized?).to be_falsy
424
424
  Sprockets::Sass.add_sass_functions = true
@@ -11,11 +11,11 @@ RSpec::Matchers.define :be_fresh do |env, old_asset|
11
11
  end
12
12
  end
13
13
 
14
- failure_message_for_should do |env|
14
+ failure_message do |env|
15
15
  'expected asset to be fresh'
16
16
  end
17
17
 
18
- failure_message_for_should_not do |env|
18
+ failure_message_when_negated do |env|
19
19
  'expected asset to be stale'
20
20
  end
21
21
  end
@@ -0,0 +1,50 @@
1
+ module Sprockets
2
+ module Sass
3
+ class FakeEngine
4
+ VERSION = '1'
5
+
6
+ def self.default_mime_type
7
+ 'text/xyx'
8
+ end
9
+
10
+ # Public: Return singleton instance with default options.
11
+ #
12
+ # Returns SassProcessor object.
13
+ def self.instance
14
+ @instance ||= new
15
+ end
16
+
17
+ def self.call(input)
18
+ instance.call(input)
19
+ end
20
+
21
+ attr_accessor :has_been_used
22
+ attr_reader :context
23
+
24
+ def initialize(*_args, &block)
25
+ @has_been_used = false
26
+ end
27
+
28
+ def call(input)
29
+ @context = input[:environment].context_class.new(input)
30
+ run
31
+ end
32
+
33
+ def render(context, _empty_hash_wtf)
34
+ @context = context
35
+ run
36
+ end
37
+
38
+ def run
39
+ @has_been_used = true
40
+ result = ""
41
+ if context.respond_to?(:metadata)
42
+ context.metadata.merge(data: result, sass_dependencies: Set.new([]))
43
+ else
44
+ result
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ module Sprockets
2
+ module Sass
3
+ class TestRegistration < Sprockets::Sass::Registration
4
+
5
+ def register_engines(hash)
6
+ _register_engines(hash)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
 
39
39
  s.add_dependency 'sprockets', '>= 2.0', '< 4.0'
40
40
 
41
- s.add_development_dependency 'rspec', '~> 2.13'
41
+ s.add_development_dependency 'rspec', '~> 3.5'
42
42
  s.add_development_dependency 'test_construct', '~> 2.0'
43
43
  s.add_development_dependency 'sprockets-helpers', '~> 1.0'
44
44
  s.add_development_dependency 'sass', '~> 3.3'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta1
4
+ version: 2.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Browne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-23 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.13'
39
+ version: '3.5'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.13'
46
+ version: '3.5'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: test_construct
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -212,12 +212,15 @@ files:
212
212
  - lib/sprockets/sass/version.rb
213
213
  - spec/custom_importer_spec.rb
214
214
  - spec/fixtures/image.jpg
215
+ - spec/importer_spec.rb
215
216
  - spec/spec_helper.rb
216
217
  - spec/sprockets-sass_spec.rb
217
218
  - spec/support/be_fresh_matcher.rb
218
219
  - spec/support/dummy_importer.rb
219
220
  - spec/support/fail_postprocessor.rb
221
+ - spec/support/fake_engine.rb
220
222
  - spec/support/sass_template.rb
223
+ - spec/support/test_registration.rb
221
224
  - sprockets-sass.gemspec
222
225
  homepage: http://github.com/petebrowne/sprockets-sass
223
226
  licenses:
@@ -248,9 +251,12 @@ summary: Better Sass integration with Sprockets 2.0
248
251
  test_files:
249
252
  - spec/custom_importer_spec.rb
250
253
  - spec/fixtures/image.jpg
254
+ - spec/importer_spec.rb
251
255
  - spec/spec_helper.rb
252
256
  - spec/sprockets-sass_spec.rb
253
257
  - spec/support/be_fresh_matcher.rb
254
258
  - spec/support/dummy_importer.rb
255
259
  - spec/support/fail_postprocessor.rb
260
+ - spec/support/fake_engine.rb
256
261
  - spec/support/sass_template.rb
262
+ - spec/support/test_registration.rb