sprockets-sass 1.3.1 → 2.0.0.beta1

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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.reek +12 -0
  3. data/.rubocop.yml +77 -0
  4. data/.travis.yml +16 -0
  5. data/Appraisals +32 -15
  6. data/Gemfile +5 -0
  7. data/README.md +41 -4
  8. data/Rakefile +15 -3
  9. data/gemfiles/compass_0.11.gemfile +1 -1
  10. data/gemfiles/sass_3.1.gemfile +1 -1
  11. data/gemfiles/sass_3.3.gemfile +8 -0
  12. data/gemfiles/sass_3.4.gemfile +8 -0
  13. data/gemfiles/sprockets_2.10.gemfile +1 -1
  14. data/gemfiles/sprockets_2.11.gemfile +1 -1
  15. data/gemfiles/sprockets_2.2.gemfile +1 -1
  16. data/gemfiles/sprockets_2.3.gemfile +1 -1
  17. data/gemfiles/sprockets_2.4.gemfile +1 -1
  18. data/gemfiles/sprockets_2.5.gemfile +1 -1
  19. data/gemfiles/sprockets_2.6.gemfile +1 -1
  20. data/gemfiles/sprockets_2.7.gemfile +1 -1
  21. data/gemfiles/sprockets_2.8.gemfile +1 -1
  22. data/gemfiles/sprockets_2.9.gemfile +1 -1
  23. data/gemfiles/sprockets_3.7.gemfile +9 -0
  24. data/gemfiles/sprockets_4.0.gemfile +10 -0
  25. data/gemfiles/sprockets_4.0_beta2.gemfile +9 -0
  26. data/lib/sprockets-sass.rb +1 -0
  27. data/lib/sprockets/sass.rb +37 -12
  28. data/lib/sprockets/sass/functions.rb +24 -159
  29. data/lib/sprockets/sass/registration.rb +126 -0
  30. data/lib/sprockets/sass/utils.rb +115 -0
  31. data/lib/sprockets/sass/v2/cache_store.rb +26 -0
  32. data/lib/sprockets/sass/v2/compressor.rb +31 -0
  33. data/lib/sprockets/sass/v2/functions.rb +142 -0
  34. data/lib/sprockets/sass/v2/importer.rb +209 -0
  35. data/lib/sprockets/sass/v2/sass_template.rb +221 -0
  36. data/lib/sprockets/sass/v2/scss_template.rb +14 -0
  37. data/lib/sprockets/sass/v3/cache_store.rb +28 -0
  38. data/lib/sprockets/sass/v3/compressor.rb +97 -0
  39. data/lib/sprockets/sass/v3/functions.rb +12 -0
  40. data/lib/sprockets/sass/v3/importer.rb +212 -0
  41. data/lib/sprockets/sass/v3/sass_template.rb +37 -0
  42. data/lib/sprockets/sass/v3/scss_template.rb +15 -0
  43. data/lib/sprockets/sass/v4/cache_store.rb +11 -0
  44. data/lib/sprockets/sass/v4/compressor.rb +11 -0
  45. data/lib/sprockets/sass/v4/functions.rb +12 -0
  46. data/lib/sprockets/sass/v4/importer.rb +105 -0
  47. data/lib/sprockets/sass/v4/sass_template.rb +27 -0
  48. data/lib/sprockets/sass/v4/scss_template.rb +16 -0
  49. data/lib/sprockets/sass/version.rb +2 -1
  50. data/spec/custom_importer_spec.rb +4 -6
  51. data/spec/spec_helper.rb +30 -3
  52. data/spec/sprockets-sass_spec.rb +101 -61
  53. data/spec/support/be_fresh_matcher.rb +10 -6
  54. data/spec/support/dummy_importer.rb +1 -1
  55. data/spec/support/fail_postprocessor.rb +23 -0
  56. data/spec/support/sass_template.rb +11 -0
  57. data/sprockets-sass.gemspec +27 -8
  58. metadata +92 -95
  59. data/gemfiles/compass_0.12.gemfile +0 -7
  60. data/gemfiles/sass_3.2.gemfile +0 -7
  61. data/gemfiles/sprockets_2.0.gemfile +0 -7
  62. data/gemfiles/sprockets_2.1.gemfile +0 -9
  63. data/lib/sprockets/sass/cache_store.rb +0 -27
  64. data/lib/sprockets/sass/compressor.rb +0 -22
  65. data/lib/sprockets/sass/importer.rb +0 -142
  66. data/lib/sprockets/sass/sass_template.rb +0 -115
  67. data/lib/sprockets/sass/scss_template.rb +0 -12
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../v3/functions'
3
+ module Sprockets
4
+ module Sass
5
+ module V4
6
+ # Module used to inject helpers into SASS engine
7
+ module Functions
8
+ include Sprockets::Sass::V3::Functions
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../v3/importer'
3
+ module Sprockets
4
+ module Sass
5
+ module V4
6
+ # class used for importing files from SCCS and SASS files
7
+ class Importer < Sprockets::Sass::V3::Importer
8
+ def syntax_mime_type(path)
9
+ "text/#{syntax(path)}"
10
+ end
11
+
12
+ def engine_from_glob(glob, base_path, options)
13
+ context = options[:custom][:sprockets_context]
14
+ engine_imports = resolve_glob(context, glob, base_path).reduce(''.dup) do |imports, path|
15
+ context.depend_on path[:file_url]
16
+ relative_path = path[:path].relative_path_from Pathname.new(base_path).dirname
17
+ imports << %(@import "#{relative_path}";\n)
18
+ end
19
+ return nil if engine_imports.empty?
20
+ ::Sass::Engine.new engine_imports, options.merge(
21
+ filename: base_path.to_s,
22
+ syntax: syntax(base_path.to_s),
23
+ importer: self,
24
+ custom: { sprockets_context: context }
25
+ )
26
+ end
27
+
28
+ # Finds all of the assets using the given glob.
29
+ def resolve_glob(context, glob, base_path)
30
+ base_path = Pathname.new(base_path)
31
+ path_with_glob = base_path.dirname.join(glob).to_s
32
+
33
+ glob_files = Pathname.glob(path_with_glob).sort.reduce([]) do |imports, path|
34
+ pathname = resolve(context, path, base_path)
35
+ asset_requirable = asset_requirable?(context, pathname)
36
+ imports << { file_url: pathname, path: path } if path != context.filename && asset_requirable
37
+ end
38
+ glob_files
39
+ end
40
+
41
+ def possible_files(context, path, base_path)
42
+ filename = check_path_before_process(context, base_path)
43
+ base_path = (filename.is_a?(Pathname) ? filename : Pathname.new(filename))
44
+ super(context, path, base_path)
45
+ end
46
+
47
+ def check_path_before_process(context, path, a = nil)
48
+ if path.to_s.start_with?('file://')
49
+ path = Pathname.new(path.to_s.gsub(/\?type\=(.*)/, "?type=text/#{syntax(path)}")) # @TODO : investigate why sometimes file:/// URLS are ending in ?type=text instead of ?type=text/scss
50
+ asset = context.environment.load(path) # because resolve now returns file://
51
+ asset.filename
52
+ else
53
+ path
54
+ end
55
+ end
56
+
57
+ def stat_of_pathname(context, pathname, _path)
58
+ filename = check_path_before_process(context, pathname)
59
+ context.environment.stat(filename)
60
+ end
61
+
62
+ # @TODO find better alternative than scanning file:// string for mime type
63
+ def content_type_of_path(context, path)
64
+ pathname = context.resolve(path)
65
+ content_type = pathname.nil? ? nil : pathname.to_s.scan(/\?type\=(.*)/).flatten.first unless pathname.nil?
66
+ attributes = {}
67
+ [content_type, attributes]
68
+ end
69
+
70
+ def get_context_transformers(context, content_type, path)
71
+ available_transformers = context.environment.transformers[content_type]
72
+ additional_transformers = available_transformers.key?(syntax_mime_type(path)) ? available_transformers[syntax_mime_type(path)] : []
73
+ additional_transformers.is_a?(Array) ? additional_transformers : [additional_transformers]
74
+ css_transformers = available_transformers.key?('text/css') ? available_transformers['text/css'] : []
75
+ css_transformers = css_transformers.is_a?(Array) ? css_transformers : [css_transformers]
76
+ additional_transformers = additional_transformers.concat(css_transformers)
77
+ additional_transformers
78
+ end
79
+
80
+ def filter_all_processors(processors)
81
+ processors.delete_if do |processor|
82
+ filtered_processor_classes.include?(processor) || filtered_processor_classes.any? do |filtered_processor|
83
+ !processor.is_a?(Proc) && ((processor.class != Class && processor.class < filtered_processor) || (processor.class == Class && processor < filtered_processor))
84
+ end
85
+ end
86
+ end
87
+
88
+ def call_processor_input(processor, context, input, processors)
89
+ if processor.respond_to?(:processors)
90
+ processor.processors = filter_all_processors(processor.processors)
91
+ end
92
+ super(processor, context, input, processors)
93
+ end
94
+
95
+ def filtered_processor_classes
96
+ classes = super
97
+ classes << Sprockets::SassCompressor if defined?(Sprockets::SassCompressor)
98
+ classes << Sprockets::SasscCompressor if defined?(Sprockets::SasscCompressor)
99
+ classes << Sprockets::YUICompressor if defined?(Sprockets::YUICompressor)
100
+ classes
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../v3/sass_template'
3
+ module Sprockets
4
+ module Sass
5
+ module V4
6
+ # Preprocessor for SASS files
7
+ class SassTemplate < Sprockets::Sass::V3::SassTemplate
8
+ # This is removed
9
+ # def self.default_mime_type
10
+ # "text/#{syntax}"
11
+ # end
12
+ #
13
+ def self.syntax
14
+ :sass
15
+ end
16
+
17
+ def custom_cache_store(*args)
18
+ Sprockets::Sass::V4::CacheStore.new(*args)
19
+ end
20
+
21
+ def custom_importer_class(*_args)
22
+ Sprockets::Sass::V4::Importer.new
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require_relative './sass_template'
3
+
4
+ # @TODO refactor the Sprockets::Sass::Functions , logical_path is unavailable
5
+ module Sprockets
6
+ module Sass
7
+ module V4
8
+ # Preprocessor for SCSS files
9
+ class ScssTemplate < Sprockets::Sass::V4::SassTemplate
10
+ def self.syntax
11
+ :scss
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module Sprockets
2
3
  module Sass
3
- VERSION = '1.3.1'
4
+ VERSION = '2.0.0.beta1'
4
5
  end
5
6
  end
@@ -12,20 +12,18 @@ describe Sprockets::Sass::SassTemplate do
12
12
  @assets = @root.directory 'assets'
13
13
  @env = Sprockets::Environment.new @root.to_s
14
14
  @env.append_path @assets.to_s
15
- @env.register_postprocessor 'text/css', :fail_postprocessor do |_, data|
16
- data.gsub /@import/, 'fail engine'
17
- end
15
+ @env.register_postprocessor 'text/css', FailPostProcessor
18
16
  end
19
17
 
20
18
  after :each do
21
19
  @root.destroy!
20
+ #Sprockets::Sass.options[:importer] = nil
22
21
  end
23
22
 
24
23
  it 'allow specifying custom sass importer' do
25
- @assets.file 'main.css.scss', %(@import "dep";)
24
+ @assets.file 'main.css.scss', %(@import "dep")
26
25
  @assets.file 'dep.css.scss', "$color: blue;\nbody { color: $color; }"
27
- @env['main.css']
28
-
26
+ asset = @env['main.css']
29
27
  expect(@custom_importer.has_been_used).to be_truthy
30
28
  end
31
29
 
@@ -1,18 +1,45 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
1
3
  require 'sprockets'
2
4
  require 'sprockets-sass'
3
5
  require 'sprockets-helpers'
4
6
  require 'compass'
5
7
  require 'test_construct'
6
8
 
9
+ RSpec.configure do |config|
10
+ config.include TestConstruct::Helpers
11
+ end
12
+
7
13
  Compass.configuration do |compass|
8
14
  compass.line_comments = false
9
15
  compass.output_style = :nested
10
16
  end
11
-
12
17
  # Requires supporting files with custom matchers and macros, etc,
13
18
  # in ./support/ and its subdirectories.
14
19
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
20
 
16
- RSpec.configure do |config|
17
- config.include TestConstruct::Helpers
21
+
22
+ def compile_asset_and_return_compilation(env, public_dir, filename )
23
+ if Sprockets::Sass::Utils.version_of_sprockets < 3
24
+ manifest = Sprockets::Manifest.new(env, public_dir)
25
+ else
26
+ manifest = Sprockets::Manifest.new(env, public_dir, File.join(public_dir ,'manifest.json'))
27
+ end
28
+ manifest.compile(filename)
29
+ res = File.read(File.join(public_dir, manifest.files.keys.first))
30
+ manifest.clobber
31
+ res
32
+ end
33
+
34
+ def write_asset(filename, contents, mtime = nil)
35
+ mtime ||= [Time.now.to_i, File.stat(filename).mtime.to_i].max + 1
36
+ File.open(filename, 'w') do |f|
37
+ f.write(contents)
38
+ end
39
+ if Sprockets::Sass::Utils.version_of_sprockets >= 3
40
+ File.utime(mtime, mtime, filename)
41
+ else
42
+ mtime = Time.now + 1
43
+ filename.utime mtime, mtime
44
+ end
18
45
  end
@@ -4,11 +4,10 @@ describe Sprockets::Sass do
4
4
  before :each do
5
5
  @root = create_construct
6
6
  @assets = @root.directory 'assets'
7
+ @public_dir = @root.directory 'public'
7
8
  @env = Sprockets::Environment.new @root.to_s
8
9
  @env.append_path @assets.to_s
9
- @env.register_postprocessor 'text/css', :fail_postprocessor do |context, data|
10
- data.gsub /@import/, 'fail engine'
11
- end
10
+ @env.register_postprocessor 'text/css', FailPostProcessor
12
11
  end
13
12
 
14
13
  after :each do
@@ -16,12 +15,21 @@ describe Sprockets::Sass do
16
15
  end
17
16
 
18
17
  it 'processes scss files normally' do
19
- @assets.file 'main.css.scss', '//= require dep'
20
- @assets.file 'dep.css.scss', 'body { color: blue; }'
18
+ @assets.file 'main.css.scss', '//= require "dep"'
19
+ @assets.file 'dep.css.scss', 'body{ color: blue; }'
21
20
  asset = @env['main.css']
22
21
  expect(asset.to_s).to eql("body {\n color: blue; }\n")
23
22
  end
24
23
 
24
+ if Sprockets::Sass::Utils.version_of_sprockets < 4
25
+ it 'processes scss files normally without the .css extension' do
26
+ @assets.file 'main.scss', '//= require dep'
27
+ @assets.file 'dep.scss', 'body { color: blue; }'
28
+ asset = @env['main']
29
+ expect(asset.to_s).to eql("body {\n color: blue; }\n")
30
+ end
31
+ end
32
+
25
33
  it 'processes sass files normally' do
26
34
  @assets.file 'main.css.sass', '//= require dep'
27
35
  @assets.file 'dep.css.sass', "body\n color: blue"
@@ -45,7 +53,7 @@ describe Sprockets::Sass do
45
53
 
46
54
  it 'imports other syntax' do
47
55
  @assets.file 'main.css.scss', %(@import "dep";\nbody { color: $color; })
48
- @assets.file 'dep.sass', "$color: blue\nhtml\n height: 100%"
56
+ @assets.file 'dep.css.sass', "$color: blue\nhtml\n height: 100%"
49
57
  asset = @env['main.css']
50
58
  expect(asset.to_s).to eql("html {\n height: 100%; }\n\nbody {\n color: blue; }\n")
51
59
  end
@@ -69,7 +77,7 @@ describe Sprockets::Sass do
69
77
  it 'imports files with additional processors' do
70
78
  @assets.file 'main.css.scss', %(@import "dep";\nbody { color: $color; })
71
79
  @assets.file 'dep.css.scss.erb', "$color: <%= 'blue' %>;"
72
- asset = @env['main.css']
80
+ asset = @env['main.css.scss']
73
81
  expect(asset.to_s).to eql("body {\n color: blue; }\n")
74
82
  end
75
83
 
@@ -90,10 +98,10 @@ describe Sprockets::Sass do
90
98
  end
91
99
 
92
100
  it 'imports deeply nested relative partials' do
93
- @assets.file 'package-prime/stylesheets/main.scss', %(@import "package-dep/src/stylesheets/variables";\nbody { background-color: $background-color; color: $color; })
94
- @assets.file 'package-dep/src/stylesheets/_variables.scss', %(@import "./colors";\n$background-color: red;)
95
- @assets.file 'package-dep/src/stylesheets/_colors.scss', '$color: blue;'
96
- asset = @env['package-prime/stylesheets/main.scss']
101
+ @assets.file 'package-prime/stylesheets/main.css.scss', %(@import "package-dep/src/stylesheets/variables";\nbody { background-color: $background-color; color: $color; })
102
+ @assets.file 'package-dep/src/stylesheets/_variables.css.scss', %(@import "./colors";\n$background-color: red;)
103
+ @assets.file 'package-dep/src/stylesheets/_colors.css.scss', '$color: blue;'
104
+ asset = @env['package-prime/stylesheets/main.css.scss']
97
105
  expect(asset.to_s).to eql("body {\n background-color: red;\n color: blue; }\n")
98
106
  end
99
107
 
@@ -129,8 +137,8 @@ describe Sprockets::Sass do
129
137
 
130
138
  it 'shares Sass environment with other imports' do
131
139
  @assets.file 'main.css.scss', %(@import "dep-1";\n@import "dep-2";)
132
- @assets.file '_dep-1.scss', '$color: blue;'
133
- @assets.file '_dep-2.scss', 'body { color: $color; }'
140
+ @assets.file '_dep-1.css.scss', '$color: blue;'
141
+ @assets.file '_dep-2.css.scss', 'body { color: $color; }'
134
142
  asset = @env['main.css']
135
143
  expect(asset.to_s).to eql("body {\n color: blue; }\n")
136
144
  end
@@ -151,8 +159,8 @@ describe Sprockets::Sass do
151
159
 
152
160
  @assets.file 'folder/main.css.scss', %(@import "dep";\nbody { color: $color; })
153
161
  vendor.file 'dep.css.scss', '@import "folder1/dep1";'
154
- vendor.file 'folder1/_dep1.scss', '@import "folder2/dep2";'
155
- vendor.file 'folder1/folder2/_dep2.scss', '$color: blue;'
162
+ vendor.file 'folder1/_dep1.css.scss', '@import "folder2/dep2";'
163
+ vendor.file 'folder1/folder2/_dep2.css.scss', '$color: blue;'
156
164
  asset = @env['folder/main.css']
157
165
  expect(asset.to_s).to eql("body {\n color: blue; }\n")
158
166
  end
@@ -163,8 +171,8 @@ describe Sprockets::Sass do
163
171
 
164
172
  @assets.file 'folder/main.css.scss', %(@import "dep";\nbody { color: $color; })
165
173
  vendor.file 'dep.css.scss', '@import "folder1/dep1";'
166
- vendor.file 'folder1/_dep1.scss', '@import "folder2/*";'
167
- vendor.file 'folder1/folder2/_dep2.scss', '$color: blue;'
174
+ vendor.file 'folder1/_dep1.css.scss', '@import "folder2/*";'
175
+ vendor.file 'folder1/folder2/_dep2.css.scss', '$color: blue;'
168
176
  asset = @env['folder/main.css']
169
177
  expect(asset.to_s).to eql("body {\n color: blue; }\n")
170
178
  end
@@ -209,13 +217,13 @@ describe Sprockets::Sass do
209
217
  dep = @assets.file 'dep.css.scss', '$color: blue;'
210
218
 
211
219
  asset = @env['main.css']
212
- expect(asset).to be_fresh(@env)
220
+ old_asset = asset.dup
221
+ expect(asset).to be_fresh(@env, old_asset)
213
222
 
214
- mtime = Time.now + 1
215
- dep.open('w') { |f| f.write '$color: red;' }
216
- dep.utime mtime, mtime
223
+ write_asset(dep, '$color: red;')
217
224
 
218
- expect(asset).to_not be_fresh(@env)
225
+ asset = Sprockets::Sass::Utils.version_of_sprockets >= 3 ? @env['main.css'] : asset
226
+ expect(asset).to_not be_fresh(@env, old_asset)
219
227
  end
220
228
 
221
229
  it 'adds dependencies from assets when imported' do
@@ -224,28 +232,29 @@ describe Sprockets::Sass do
224
232
  dep = @assets.file 'dep-2.css.scss', '$color: blue;'
225
233
 
226
234
  asset = @env['main.css']
227
- expect(asset).to be_fresh(@env)
235
+ old_asset = asset.dup
236
+ expect(asset).to be_fresh(@env, old_asset)
228
237
 
229
- mtime = Time.now + 1
230
- dep.open('w') { |f| f.write '$color: red;' }
231
- dep.utime mtime, mtime
238
+ write_asset(dep, '$color: red;')
232
239
 
233
- expect(asset).to_not be_fresh(@env)
240
+ asset = Sprockets::Sass::Utils.version_of_sprockets >= 3 ? @env['main.css'] : asset
241
+ expect(asset).to_not be_fresh(@env, old_asset)
234
242
  end
235
243
 
236
244
  it 'adds dependencies when imported from a glob' do
237
245
  @assets.file 'main.css.scss', %(@import "folder/*";\nbody { color: $color; background: $bg-color; })
238
- @assets.file 'folder/_dep-1.scss', '$color: blue;'
239
- dep = @assets.file 'folder/_dep-2.scss', '$bg-color: red;'
246
+ @assets.file 'folder/_dep-1.css.scss', '$color: blue;'
247
+ dep = @assets.file 'folder/_dep-2.css.scss', '$bg-color: red;'
240
248
 
241
249
  asset = @env['main.css']
242
- expect(asset).to be_fresh(@env)
250
+ old_asset = asset.dup
251
+ expect(asset).to be_fresh(@env, old_asset)
252
+
253
+ write_asset(dep, "$bg-color: white;" )
243
254
 
244
- mtime = Time.now + 1
245
- dep.open('w') { |f| f.write "$bg-color: white;" }
246
- dep.utime mtime, mtime
255
+ asset = Sprockets::Sass::Utils.version_of_sprockets >= 3 ? @env['main.css'] : asset
247
256
 
248
- expect(asset).to_not be_fresh(@env)
257
+ expect(asset).to_not be_fresh(@env, old_asset)
249
258
  end
250
259
 
251
260
  it "uses the environment's cache" do
@@ -255,10 +264,14 @@ describe Sprockets::Sass do
255
264
  @assets.file 'main.css.scss', %($color: blue;\nbody { color: $color; })
256
265
 
257
266
  @env['main.css'].to_s
258
- if Sass.version[:minor] > 2
259
- sass_cache = cache.detect.detect { |key, value| value['pathname'] =~ /main\.css\.scss/ }
267
+ if Sprockets::Sass::Utils.version_of_sprockets < 3
268
+ if Sass.version[:minor] > 2
269
+ sass_cache = cache.detect { |key, value| value['pathname'] =~ /main\.css\.scss/ }
270
+ else
271
+ sass_cache = cache.keys.detect { |key| key =~ /main\.css\.scss/ }
272
+ end
260
273
  else
261
- sass_cache = cache.keys.detect { |key| key =~ /main\.css\.scss/ }
274
+ sass_cache = cache.detect { |key, value| value =~ /main\.css\.scss/ }
262
275
  end
263
276
  expect(sass_cache).to_not be_nil
264
277
  end
@@ -345,42 +358,69 @@ describe Sprockets::Sass do
345
358
  expect(@env['bullets.css'].to_s).to match(%r[background: url\("/assets/bullet\.gif"\)])
346
359
  end
347
360
 
348
- it 'compresses css' do
349
- css = "div {\n color: red;\n}\n"
350
- compressed_css = Sprockets::Sass::Compressor.new.compress(css)
351
- expect(compressed_css).to eql("div{color:red}\n")
361
+ if Sprockets::Sass::Utils.version_of_sprockets < 3
362
+ it 'compresses css from string' do
363
+ compressor = Sprockets::Sass::V2::Compressor.new
364
+ compressed_css = compressor.compress("div {\n color: red;\n}\n")
365
+ expect(compressed_css).to eql("div{color:red}\n")
366
+ end
367
+ end
368
+
369
+ if Sprockets::Sass::Utils.version_of_sprockets >= 3
370
+ it 'compresses css from filename' do
371
+ file_path = @assets.file 'asset_path.css.scss', %(div {\n color: red;\n}\n)
372
+ compressor = Sprockets::Sass::V3::Compressor.new
373
+ compressed_css = compressor.run(file_path)
374
+ expect(compressed_css).to eql("div{color:red}\n")
375
+ end
376
+
377
+ it 'compresses css from string' do
378
+ compressor = Sprockets::Sass::V3::Compressor.new
379
+ compressed_css = compressor.run("div {\n color: red;\n}\n")
380
+ expect(compressed_css).to eql("div{color:red}\n")
381
+ end
382
+ end
383
+
384
+ if Sprockets::Sass::Utils.version_of_sprockets < 3
385
+ it 'compresses css using the environment compressor' do
386
+ @env.css_compressor = Sprockets::Sass::V2::Compressor
387
+ @assets.file 'asset_path.css.scss', %(div {\n color: red;\n}\n)
388
+ res = compile_asset_and_return_compilation(@env, @public_dir, "asset_path.css")
389
+ expect(res).to eql("div{color:red}\n")
390
+ end
391
+ else
392
+ it 'compresses css using the environment compressor' do
393
+ @env.css_compressor = :sprockets_sass
394
+ @assets.file 'asset_path.css.scss', %(div {\n color: red;\n}\n)
395
+ res = compile_asset_and_return_compilation(@env, @public_dir, "asset_path.css")
396
+ expect(res).to eql("div{color:red}\n")
397
+ end
352
398
  end
399
+
353
400
 
354
401
  describe Sprockets::Sass::SassTemplate do
355
- describe 'initialize_engine' do
356
- it 'initializes super if super is uninitinalized' do
357
- Tilt::SassTemplate.stub(:engine_initialized?).and_return false
358
- template = Sprockets::Sass::SassTemplate.new {}
359
- template.should_receive(:require_template_library) # called from Tilt::SassTemplate.initialize
360
- template.initialize_engine
361
- end
362
402
 
363
- it 'does not initializes super if super is initinalized to silence warnings' do
364
- Tilt::SassTemplate.stub(:engine_initialized?).and_return true
365
- template = Sprockets::Sass::SassTemplate.new {}
366
- template.should_not_receive(:require_template_library) # called from Tilt::SassTemplate.initialize
367
- template.initialize_engine
403
+ let(:template) do
404
+ Sprockets::Sass::SassTemplate.new(@assets.file 'bullet.gif') do
405
+ # nothing
368
406
  end
407
+ end
408
+ describe 'initialize_engine' do
369
409
 
370
- it 'does not add Sass functions if sprockets-helpers is not available' do
371
- template = Sprockets::Sass::SassTemplate.new {}
372
- template.should_receive(:require).with('sprockets/helpers').and_raise LoadError
373
- template.should_not_receive(:require).with 'sprockets/sass/functions'
374
- template.initialize_engine
375
- expect(Sprockets::Sass::SassTemplate.engine_initialized?).to be_truthy
410
+ it 'does add Sass functions if sprockets-helpers is not available' do
411
+ Sprockets::Sass::SassTemplate.sass_functions_initialized = false
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'
415
+ template
416
+ expect(Sprockets::Sass::SassTemplate.engine_initialized?).to be_falsy
376
417
  end
377
418
 
378
419
  it 'does not add Sass functions if add_sass_functions is false' do
379
420
  Sprockets::Sass.add_sass_functions = false
380
- template = Sprockets::Sass::SassTemplate.new {}
381
421
  template.should_not_receive(:require).with 'sprockets/sass/functions'
382
422
  template.initialize_engine
383
- expect(Sprockets::Sass::SassTemplate.engine_initialized?).to be_truthy
423
+ expect(Sprockets::Sass::SassTemplate.engine_initialized?).to be_falsy
384
424
  Sprockets::Sass.add_sass_functions = true
385
425
  end
386
426
  end