sprockets-sass 1.3.1 → 2.0.0.beta2
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 +7 -0
- data/.reek +12 -0
- data/.rspec +1 -0
- data/.rubocop.yml +77 -0
- data/.travis.yml +14 -0
- data/Appraisals +32 -15
- data/Gemfile +5 -0
- data/README.md +41 -4
- data/Rakefile +15 -3
- data/gemfiles/compass_0.11.gemfile +1 -1
- data/gemfiles/sass_3.1.gemfile +1 -1
- data/gemfiles/sass_3.3.gemfile +8 -0
- data/gemfiles/sass_3.4.gemfile +8 -0
- data/gemfiles/sprockets_2.10.gemfile +1 -1
- data/gemfiles/sprockets_2.11.gemfile +1 -1
- data/gemfiles/sprockets_2.2.gemfile +1 -1
- data/gemfiles/sprockets_2.3.gemfile +1 -1
- data/gemfiles/sprockets_2.4.gemfile +1 -1
- data/gemfiles/sprockets_2.5.gemfile +1 -1
- data/gemfiles/sprockets_2.6.gemfile +1 -1
- data/gemfiles/sprockets_2.7.gemfile +1 -1
- data/gemfiles/sprockets_2.8.gemfile +1 -1
- data/gemfiles/sprockets_2.9.gemfile +1 -1
- data/gemfiles/sprockets_3.7.gemfile +9 -0
- data/gemfiles/sprockets_4.0.gemfile +10 -0
- data/gemfiles/sprockets_4.0_beta2.gemfile +9 -0
- data/lib/sprockets/sass/functions.rb +24 -159
- data/lib/sprockets/sass/registration.rb +126 -0
- data/lib/sprockets/sass/utils.rb +115 -0
- data/lib/sprockets/sass/v2/cache_store.rb +26 -0
- data/lib/sprockets/sass/v2/compressor.rb +31 -0
- data/lib/sprockets/sass/v2/functions.rb +142 -0
- data/lib/sprockets/sass/v2/importer.rb +209 -0
- data/lib/sprockets/sass/v2/sass_template.rb +221 -0
- data/lib/sprockets/sass/v2/scss_template.rb +14 -0
- data/lib/sprockets/sass/v3/cache_store.rb +28 -0
- data/lib/sprockets/sass/v3/compressor.rb +97 -0
- data/lib/sprockets/sass/v3/functions.rb +12 -0
- data/lib/sprockets/sass/v3/importer.rb +224 -0
- data/lib/sprockets/sass/v3/sass_template.rb +37 -0
- data/lib/sprockets/sass/v3/scss_template.rb +15 -0
- data/lib/sprockets/sass/v4/cache_store.rb +11 -0
- data/lib/sprockets/sass/v4/compressor.rb +11 -0
- data/lib/sprockets/sass/v4/functions.rb +12 -0
- data/lib/sprockets/sass/v4/importer.rb +109 -0
- data/lib/sprockets/sass/v4/sass_template.rb +27 -0
- data/lib/sprockets/sass/v4/scss_template.rb +16 -0
- data/lib/sprockets/sass/version.rb +2 -1
- data/lib/sprockets/sass.rb +37 -12
- data/lib/sprockets-sass.rb +1 -0
- data/spec/custom_importer_spec.rb +4 -6
- data/spec/importer_spec.rb +44 -0
- data/spec/spec_helper.rb +39 -3
- data/spec/sprockets-sass_spec.rb +102 -62
- data/spec/support/be_fresh_matcher.rb +12 -8
- data/spec/support/dummy_importer.rb +1 -1
- data/spec/support/fail_postprocessor.rb +23 -0
- data/spec/support/fake_engine.rb +50 -0
- data/spec/support/sass_template.rb +11 -0
- data/spec/support/test_registration.rb +11 -0
- data/sprockets-sass.gemspec +28 -9
- metadata +100 -97
- data/gemfiles/compass_0.12.gemfile +0 -7
- data/gemfiles/sass_3.2.gemfile +0 -7
- data/gemfiles/sprockets_2.0.gemfile +0 -7
- data/gemfiles/sprockets_2.1.gemfile +0 -9
- data/lib/sprockets/sass/cache_store.rb +0 -27
- data/lib/sprockets/sass/compressor.rb +0 -22
- data/lib/sprockets/sass/importer.rb +0 -142
- data/lib/sprockets/sass/sass_template.rb +0 -115
- data/lib/sprockets/sass/scss_template.rb +0 -12
|
@@ -0,0 +1,109 @@
|
|
|
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 get_engines_from_attributes(_context, _attributes)
|
|
89
|
+
[]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def call_processor_input(processor, context, input, processors)
|
|
93
|
+
if processor.respond_to?(:processors)
|
|
94
|
+
processor.processors = filter_all_processors(processor.processors)
|
|
95
|
+
end
|
|
96
|
+
super(processor, context, input, processors)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def filtered_processor_classes
|
|
100
|
+
classes = super
|
|
101
|
+
classes << Sprockets::SassCompressor if defined?(Sprockets::SassCompressor)
|
|
102
|
+
classes << Sprockets::SasscCompressor if defined?(Sprockets::SasscCompressor)
|
|
103
|
+
classes << Sprockets::YUICompressor if defined?(Sprockets::YUICompressor)
|
|
104
|
+
classes
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
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
|
data/lib/sprockets/sass.rb
CHANGED
|
@@ -1,29 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'sprockets'
|
|
2
3
|
require 'sprockets/sass/version'
|
|
3
|
-
require 'sprockets/sass/
|
|
4
|
-
require 'sprockets/sass/
|
|
5
|
-
require '
|
|
4
|
+
require 'sprockets/sass/utils'
|
|
5
|
+
require 'sprockets/sass/registration'
|
|
6
|
+
require 'sass'
|
|
7
|
+
require 'sass/importers/base'
|
|
6
8
|
|
|
9
|
+
require 'json'
|
|
10
|
+
require 'pathname'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# the module of Sprockets
|
|
7
14
|
module Sprockets
|
|
15
|
+
# The internal Sass module used to load and acessing configuration
|
|
8
16
|
module Sass
|
|
9
|
-
autoload :CacheStore, 'sprockets/sass/cache_store'
|
|
10
|
-
autoload :Compressor, 'sprockets/sass/compressor'
|
|
11
|
-
autoload :Importer, 'sprockets/sass/importer'
|
|
12
|
-
|
|
13
17
|
class << self
|
|
14
18
|
# Global configuration for `Sass::Engine` instances.
|
|
15
19
|
attr_accessor :options
|
|
16
|
-
|
|
20
|
+
|
|
17
21
|
# When false, the asset path helpers provided by
|
|
18
22
|
# sprockets-helpers will not be added as Sass functions.
|
|
19
23
|
# `true` by default.
|
|
20
24
|
attr_accessor :add_sass_functions
|
|
21
25
|
end
|
|
22
|
-
|
|
26
|
+
|
|
23
27
|
@options = {}
|
|
24
28
|
@add_sass_functions = true
|
|
25
29
|
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
begin
|
|
32
|
+
require 'sprockets/directive_processor'
|
|
33
|
+
require 'sprockets/sass_processor'
|
|
34
|
+
require 'sprockets/sassc_processor'
|
|
35
|
+
require 'sprockets/digest_utils'
|
|
36
|
+
require 'sprockets/engines'
|
|
37
|
+
rescue LoadError; end
|
|
38
|
+
|
|
39
|
+
if Sprockets::Sass::Utils.version_of_sprockets >= 3
|
|
40
|
+
# We need this only for Sprockets > 3 in order to be able to register anything.
|
|
41
|
+
# For Sprockets 2.x , although the file and the module name exist,
|
|
42
|
+
# they can't be used because it will give errors about undefined methods, because this is included only on Sprockets::Base
|
|
43
|
+
# and in order to use them we would have to subclass it and define methods to expire cache and other methods for registration ,
|
|
44
|
+
# which are not needed since Sprockets already knows about that using the environment instead internally
|
|
45
|
+
require 'sprockets/processing'
|
|
46
|
+
extend Sprockets::Processing
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
registration = Sprockets::Sass::Registration.new(self)
|
|
50
|
+
registration.run
|
|
29
51
|
end
|
|
52
|
+
|
|
53
|
+
# Sprockets 4 needs this , becasue it doesnt use ::Sass in code, which results in a conflict with this gem :(
|
|
54
|
+
Sprockets::Sass::Importers = ::Sass::Importers
|
data/lib/sprockets-sass.rb
CHANGED
|
@@ -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',
|
|
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
|
|
|
@@ -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
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,18 +1,54 @@
|
|
|
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
|
+
# 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
|
|
19
|
+
config.include TestConstruct::Helpers
|
|
20
|
+
end
|
|
21
|
+
|
|
7
22
|
Compass.configuration do |compass|
|
|
8
23
|
compass.line_comments = false
|
|
9
24
|
compass.output_style = :nested
|
|
10
25
|
end
|
|
11
|
-
|
|
12
26
|
# Requires supporting files with custom matchers and macros, etc,
|
|
13
27
|
# in ./support/ and its subdirectories.
|
|
14
28
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
15
29
|
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
|
|
31
|
+
def compile_asset_and_return_compilation(env, public_dir, filename )
|
|
32
|
+
if Sprockets::Sass::Utils.version_of_sprockets < 3
|
|
33
|
+
manifest = Sprockets::Manifest.new(env, public_dir)
|
|
34
|
+
else
|
|
35
|
+
manifest = Sprockets::Manifest.new(env, public_dir, File.join(public_dir ,'manifest.json'))
|
|
36
|
+
end
|
|
37
|
+
manifest.compile(filename)
|
|
38
|
+
res = File.read(File.join(public_dir, manifest.files.keys.first))
|
|
39
|
+
manifest.clobber
|
|
40
|
+
res
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def write_asset(filename, contents, mtime = nil)
|
|
44
|
+
mtime ||= [Time.now.to_i, File.stat(filename).mtime.to_i].max + 1
|
|
45
|
+
File.open(filename, 'w') do |f|
|
|
46
|
+
f.write(contents)
|
|
47
|
+
end
|
|
48
|
+
if Sprockets::Sass::Utils.version_of_sprockets >= 3
|
|
49
|
+
File.utime(mtime, mtime, filename)
|
|
50
|
+
else
|
|
51
|
+
mtime = Time.now + 1
|
|
52
|
+
filename.utime mtime, mtime
|
|
53
|
+
end
|
|
18
54
|
end
|
data/spec/sprockets-sass_spec.rb
CHANGED
|
@@ -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',
|
|
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
|
|
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
|
-
|
|
220
|
+
old_asset = asset.dup
|
|
221
|
+
expect(asset).to be_fresh(@env, old_asset)
|
|
213
222
|
|
|
214
|
-
|
|
215
|
-
dep.open('w') { |f| f.write '$color: red;' }
|
|
216
|
-
dep.utime mtime, mtime
|
|
223
|
+
write_asset(dep, '$color: red;')
|
|
217
224
|
|
|
218
|
-
|
|
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
|
-
|
|
235
|
+
old_asset = asset.dup
|
|
236
|
+
expect(asset).to be_fresh(@env, old_asset)
|
|
228
237
|
|
|
229
|
-
|
|
230
|
-
dep.open('w') { |f| f.write '$color: red;' }
|
|
231
|
-
dep.utime mtime, mtime
|
|
238
|
+
write_asset(dep, '$color: red;')
|
|
232
239
|
|
|
233
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
259
|
-
|
|
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.
|
|
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
|
-
|
|
349
|
-
css
|
|
350
|
-
|
|
351
|
-
|
|
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
|
|
353
399
|
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
+
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
|
+
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
|
|
381
|
-
template.should_not_receive(:require).with 'sprockets/sass/functions'
|
|
421
|
+
expect(template).to_not receive(:require).with 'sprockets/sass/functions'
|
|
382
422
|
template.initialize_engine
|
|
383
|
-
expect(Sprockets::Sass::SassTemplate.engine_initialized?).to
|
|
423
|
+
expect(Sprockets::Sass::SassTemplate.engine_initialized?).to be_falsy
|
|
384
424
|
Sprockets::Sass.add_sass_functions = true
|
|
385
425
|
end
|
|
386
426
|
end
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
RSpec::Matchers.define :be_fresh do |env|
|
|
1
|
+
RSpec::Matchers.define :be_fresh do |env, old_asset|
|
|
2
2
|
match do |actual|
|
|
3
|
-
if actual.
|
|
4
|
-
actual.fresh?
|
|
3
|
+
if actual.respond_to?(:fresh?)
|
|
4
|
+
if actual.method(:fresh?).arity == 1
|
|
5
|
+
actual.fresh?(env)
|
|
6
|
+
else
|
|
7
|
+
actual.fresh?
|
|
8
|
+
end
|
|
5
9
|
else
|
|
6
|
-
actual.
|
|
10
|
+
actual.eql?(old_asset)
|
|
7
11
|
end
|
|
8
12
|
end
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
|
|
14
|
+
failure_message do |env|
|
|
11
15
|
'expected asset to be fresh'
|
|
12
16
|
end
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
|
|
18
|
+
failure_message_when_negated do |env|
|
|
15
19
|
'expected asset to be stale'
|
|
16
20
|
end
|
|
17
21
|
end
|