sass 3.2.19 → 3.4.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +3 -1
- data/CODE_OF_CONDUCT.md +10 -0
- data/CONTRIBUTING.md +148 -0
- data/MIT-LICENSE +1 -1
- data/README.md +87 -61
- data/Rakefile +119 -15
- data/VERSION +1 -1
- data/VERSION_DATE +1 -1
- data/VERSION_NAME +1 -1
- data/bin/sass +1 -1
- data/bin/scss +1 -1
- data/extra/sass-spec-ref.sh +32 -0
- data/extra/update_watch.rb +1 -1
- data/lib/sass/cache_stores/base.rb +2 -2
- data/lib/sass/cache_stores/chain.rb +2 -1
- data/lib/sass/cache_stores/filesystem.rb +8 -12
- data/lib/sass/cache_stores/memory.rb +5 -6
- data/lib/sass/cache_stores/null.rb +2 -2
- data/lib/sass/callbacks.rb +3 -2
- data/lib/sass/css.rb +22 -23
- data/lib/sass/deprecation.rb +55 -0
- data/lib/sass/engine.rb +487 -191
- data/lib/sass/environment.rb +172 -58
- data/lib/sass/error.rb +21 -24
- data/lib/sass/exec/base.rb +199 -0
- data/lib/sass/exec/sass_convert.rb +283 -0
- data/lib/sass/exec/sass_scss.rb +440 -0
- data/lib/sass/exec.rb +5 -703
- data/lib/sass/features.rb +47 -0
- data/lib/sass/importers/base.rb +50 -7
- data/lib/sass/importers/deprecated_path.rb +51 -0
- data/lib/sass/importers/filesystem.rb +54 -21
- data/lib/sass/importers.rb +1 -0
- data/lib/sass/logger/base.rb +9 -5
- data/lib/sass/logger/delayed.rb +50 -0
- data/lib/sass/logger/log_level.rb +3 -7
- data/lib/sass/logger.rb +9 -7
- data/lib/sass/media.rb +20 -23
- data/lib/sass/plugin/compiler.rb +321 -145
- data/lib/sass/plugin/configuration.rb +45 -34
- data/lib/sass/plugin/merb.rb +3 -3
- data/lib/sass/plugin/rack.rb +3 -3
- data/lib/sass/plugin/rails.rb +1 -1
- data/lib/sass/plugin/staleness_checker.rb +6 -6
- data/lib/sass/plugin.rb +9 -8
- data/lib/sass/repl.rb +3 -3
- data/lib/sass/script/css_lexer.rb +8 -4
- data/lib/sass/script/css_parser.rb +4 -2
- data/lib/sass/script/css_variable_warning.rb +52 -0
- data/lib/sass/script/functions.rb +1583 -433
- data/lib/sass/script/lexer.rb +198 -79
- data/lib/sass/script/parser.rb +463 -133
- data/lib/sass/script/tree/funcall.rb +313 -0
- data/lib/sass/script/tree/interpolation.rb +223 -0
- data/lib/sass/script/tree/list_literal.rb +104 -0
- data/lib/sass/script/tree/literal.rb +49 -0
- data/lib/sass/script/tree/map_literal.rb +64 -0
- data/lib/sass/script/{node.rb → tree/node.rb} +42 -14
- data/lib/sass/script/tree/operation.rb +156 -0
- data/lib/sass/script/tree/selector.rb +26 -0
- data/lib/sass/script/tree/string_interpolation.rb +125 -0
- data/lib/sass/script/{unary_operation.rb → tree/unary_operation.rb} +6 -6
- data/lib/sass/script/tree/variable.rb +57 -0
- data/lib/sass/script/tree.rb +16 -0
- data/lib/sass/script/{arg_list.rb → value/arg_list.rb} +9 -25
- data/lib/sass/script/value/base.rb +241 -0
- data/lib/sass/script/value/bool.rb +35 -0
- data/lib/sass/script/value/color.rb +698 -0
- data/lib/sass/script/value/helpers.rb +272 -0
- data/lib/sass/script/value/list.rb +113 -0
- data/lib/sass/script/value/map.rb +70 -0
- data/lib/sass/script/{null.rb → value/null.rb} +14 -7
- data/lib/sass/script/{number.rb → value/number.rb} +196 -86
- data/lib/sass/script/value/string.rb +138 -0
- data/lib/sass/script/value.rb +11 -0
- data/lib/sass/script.rb +38 -11
- data/lib/sass/scss/css_parser.rb +25 -5
- data/lib/sass/scss/parser.rb +532 -458
- data/lib/sass/scss/rx.rb +21 -14
- data/lib/sass/scss/static_parser.rb +328 -9
- data/lib/sass/scss.rb +0 -2
- data/lib/sass/selector/abstract_sequence.rb +36 -19
- data/lib/sass/selector/comma_sequence.rb +125 -26
- data/lib/sass/selector/pseudo.rb +266 -0
- data/lib/sass/selector/sequence.rb +200 -71
- data/lib/sass/selector/simple.rb +30 -32
- data/lib/sass/selector/simple_sequence.rb +193 -64
- data/lib/sass/selector.rb +65 -194
- data/lib/sass/shared.rb +2 -2
- data/lib/sass/source/map.rb +213 -0
- data/lib/sass/source/position.rb +39 -0
- data/lib/sass/source/range.rb +41 -0
- data/lib/sass/stack.rb +120 -0
- data/lib/sass/supports.rb +19 -23
- data/lib/sass/tree/at_root_node.rb +83 -0
- data/lib/sass/tree/charset_node.rb +1 -1
- data/lib/sass/tree/comment_node.rb +4 -4
- data/lib/sass/tree/css_import_node.rb +19 -11
- data/lib/sass/tree/debug_node.rb +2 -2
- data/lib/sass/tree/directive_node.rb +21 -4
- data/lib/sass/tree/each_node.rb +8 -8
- data/lib/sass/tree/error_node.rb +18 -0
- data/lib/sass/tree/extend_node.rb +14 -7
- data/lib/sass/tree/for_node.rb +4 -4
- data/lib/sass/tree/function_node.rb +14 -4
- data/lib/sass/tree/if_node.rb +1 -1
- data/lib/sass/tree/import_node.rb +10 -10
- data/lib/sass/tree/keyframe_rule_node.rb +15 -0
- data/lib/sass/tree/media_node.rb +4 -14
- data/lib/sass/tree/mixin_def_node.rb +4 -4
- data/lib/sass/tree/mixin_node.rb +21 -8
- data/lib/sass/tree/node.rb +59 -15
- data/lib/sass/tree/prop_node.rb +42 -24
- data/lib/sass/tree/return_node.rb +3 -2
- data/lib/sass/tree/root_node.rb +19 -3
- data/lib/sass/tree/rule_node.rb +49 -26
- data/lib/sass/tree/supports_node.rb +0 -13
- data/lib/sass/tree/trace_node.rb +2 -1
- data/lib/sass/tree/variable_node.rb +9 -3
- data/lib/sass/tree/visitors/base.rb +5 -8
- data/lib/sass/tree/visitors/check_nesting.rb +62 -36
- data/lib/sass/tree/visitors/convert.rb +111 -76
- data/lib/sass/tree/visitors/cssize.rb +206 -74
- data/lib/sass/tree/visitors/deep_copy.rb +11 -6
- data/lib/sass/tree/visitors/extend.rb +19 -17
- data/lib/sass/tree/visitors/perform.rb +308 -190
- data/lib/sass/tree/visitors/set_options.rb +21 -7
- data/lib/sass/tree/visitors/to_css.rb +273 -92
- data/lib/sass/tree/warn_node.rb +2 -2
- data/lib/sass/tree/while_node.rb +2 -2
- data/lib/sass/util/cross_platform_random.rb +19 -0
- data/lib/sass/util/normalized_map.rb +129 -0
- data/lib/sass/util/ordered_hash.rb +192 -0
- data/lib/sass/util/subset_map.rb +5 -5
- data/lib/sass/util/test.rb +0 -1
- data/lib/sass/util.rb +620 -193
- data/lib/sass/version.rb +22 -24
- data/lib/sass.rb +27 -13
- data/test/sass/cache_test.rb +62 -20
- data/test/sass/callbacks_test.rb +1 -1
- data/test/sass/compiler_test.rb +236 -0
- data/test/sass/conversion_test.rb +472 -44
- data/test/sass/css2sass_test.rb +73 -5
- data/test/sass/css_variable_test.rb +132 -0
- data/test/sass/encoding_test.rb +219 -0
- data/test/sass/engine_test.rb +618 -415
- data/test/sass/exec_test.rb +12 -2
- data/test/sass/extend_test.rb +419 -168
- data/test/sass/functions_test.rb +931 -93
- data/test/sass/importer_test.rb +250 -21
- data/test/sass/logger_test.rb +1 -1
- data/test/sass/more_results/more_import.css +1 -1
- data/test/sass/more_templates/more1.sass +10 -10
- data/test/sass/more_templates/more_import.sass +2 -2
- data/test/sass/plugin_test.rb +26 -34
- data/test/sass/results/compact.css +1 -1
- data/test/sass/results/complex.css +4 -4
- data/test/sass/results/expanded.css +1 -1
- data/test/sass/results/import.css +1 -1
- data/test/sass/results/import_charset_ibm866.css +2 -2
- data/test/sass/results/mixins.css +17 -17
- data/test/sass/results/nested.css +1 -1
- data/test/sass/results/parent_ref.css +2 -2
- data/test/sass/results/script.css +5 -5
- data/test/sass/results/scss_import.css +1 -1
- data/test/sass/script_conversion_test.rb +97 -39
- data/test/sass/script_test.rb +911 -102
- data/test/sass/scss/css_test.rb +215 -34
- data/test/sass/scss/rx_test.rb +8 -4
- data/test/sass/scss/scss_test.rb +2424 -325
- data/test/sass/source_map_test.rb +1055 -0
- data/test/sass/superselector_test.rb +210 -0
- data/test/sass/templates/_partial.sass +1 -1
- data/test/sass/templates/basic.sass +10 -10
- data/test/sass/templates/bork1.sass +1 -1
- data/test/sass/templates/bork5.sass +1 -1
- data/test/sass/templates/compact.sass +10 -10
- data/test/sass/templates/complex.sass +187 -187
- data/test/sass/templates/compressed.sass +10 -10
- data/test/sass/templates/expanded.sass +10 -10
- data/test/sass/templates/import.sass +2 -2
- data/test/sass/templates/importee.sass +3 -3
- data/test/sass/templates/mixins.sass +22 -22
- data/test/sass/templates/multiline.sass +4 -4
- data/test/sass/templates/nested.sass +13 -13
- data/test/sass/templates/parent_ref.sass +12 -12
- data/test/sass/templates/script.sass +70 -70
- data/test/sass/templates/scss_import.scss +2 -1
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +1 -1
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +2 -2
- data/test/sass/templates/subdir/subdir.sass +3 -3
- data/test/sass/templates/units.sass +10 -10
- data/test/sass/test_helper.rb +1 -1
- data/test/sass/util/multibyte_string_scanner_test.rb +11 -3
- data/test/sass/util/normalized_map_test.rb +51 -0
- data/test/sass/util/subset_map_test.rb +2 -2
- data/test/sass/util_test.rb +99 -43
- data/test/sass/value_helpers_test.rb +179 -0
- data/test/sass-spec.yml +3 -0
- data/test/test_helper.rb +42 -12
- data/vendor/listen/CHANGELOG.md +1 -228
- data/vendor/listen/Gemfile +5 -15
- data/vendor/listen/README.md +111 -77
- data/vendor/listen/Rakefile +0 -42
- data/vendor/listen/lib/listen/adapter.rb +195 -82
- data/vendor/listen/lib/listen/adapters/bsd.rb +27 -64
- data/vendor/listen/lib/listen/adapters/darwin.rb +21 -58
- data/vendor/listen/lib/listen/adapters/linux.rb +23 -55
- data/vendor/listen/lib/listen/adapters/polling.rb +25 -34
- data/vendor/listen/lib/listen/adapters/windows.rb +50 -46
- data/vendor/listen/lib/listen/directory_record.rb +96 -61
- data/vendor/listen/lib/listen/listener.rb +135 -37
- data/vendor/listen/lib/listen/turnstile.rb +9 -5
- data/vendor/listen/lib/listen/version.rb +1 -1
- data/vendor/listen/lib/listen.rb +33 -19
- data/vendor/listen/listen.gemspec +6 -0
- data/vendor/listen/spec/listen/adapter_spec.rb +43 -77
- data/vendor/listen/spec/listen/adapters/polling_spec.rb +8 -8
- data/vendor/listen/spec/listen/directory_record_spec.rb +81 -56
- data/vendor/listen/spec/listen/listener_spec.rb +128 -39
- data/vendor/listen/spec/listen_spec.rb +15 -21
- data/vendor/listen/spec/spec_helper.rb +4 -0
- data/vendor/listen/spec/support/adapter_helper.rb +52 -15
- data/vendor/listen/spec/support/directory_record_helper.rb +7 -5
- data/vendor/listen/spec/support/listeners_helper.rb +30 -7
- metadata +161 -111
- data/CONTRIBUTING +0 -3
- data/lib/sass/script/bool.rb +0 -18
- data/lib/sass/script/color.rb +0 -606
- data/lib/sass/script/funcall.rb +0 -245
- data/lib/sass/script/interpolation.rb +0 -79
- data/lib/sass/script/list.rb +0 -85
- data/lib/sass/script/literal.rb +0 -221
- data/lib/sass/script/operation.rb +0 -110
- data/lib/sass/script/string.rb +0 -51
- data/lib/sass/script/string_interpolation.rb +0 -103
- data/lib/sass/script/variable.rb +0 -58
- data/lib/sass/scss/script_lexer.rb +0 -15
- data/lib/sass/scss/script_parser.rb +0 -25
- data/test/Gemfile +0 -3
- data/test/Gemfile.lock +0 -10
- data/vendor/listen/lib/listen/dependency_manager.rb +0 -126
- data/vendor/listen/lib/listen/multi_listener.rb +0 -143
- data/vendor/listen/spec/listen/dependency_manager_spec.rb +0 -107
- data/vendor/listen/spec/listen/multi_listener_spec.rb +0 -174
data/lib/sass/plugin/compiler.rb
CHANGED
@@ -7,7 +7,6 @@ require 'sass/plugin/configuration'
|
|
7
7
|
require 'sass/plugin/staleness_checker'
|
8
8
|
|
9
9
|
module Sass::Plugin
|
10
|
-
|
11
10
|
# The Compiler class handles compilation of multiple files and/or directories,
|
12
11
|
# including checking which CSS files are out-of-date and need to be updated
|
13
12
|
# and calling Sass to perform the compilation on those files.
|
@@ -26,31 +25,42 @@ module Sass::Plugin
|
|
26
25
|
# * `:never_update`
|
27
26
|
# * `:always_check`
|
28
27
|
class Compiler
|
29
|
-
include Sass::Util
|
30
28
|
include Configuration
|
31
29
|
extend Sass::Callbacks
|
32
30
|
|
33
31
|
# Creates a new compiler.
|
34
32
|
#
|
35
|
-
# @param
|
36
|
-
# See {file:SASS_REFERENCE.md#
|
37
|
-
def initialize(
|
38
|
-
|
33
|
+
# @param opts [{Symbol => Object}]
|
34
|
+
# See {file:SASS_REFERENCE.md#Options the Sass options documentation}.
|
35
|
+
def initialize(opts = {})
|
36
|
+
@watched_files = Set.new
|
37
|
+
options.merge!(opts)
|
39
38
|
end
|
40
39
|
|
41
|
-
# Register a callback to be run
|
40
|
+
# Register a callback to be run before stylesheets are mass-updated.
|
42
41
|
# This is run whenever \{#update\_stylesheets} is called,
|
43
42
|
# unless the \{file:SASS_REFERENCE.md#never_update-option `:never_update` option}
|
44
43
|
# is enabled.
|
45
44
|
#
|
46
|
-
# @yield [
|
47
|
-
# @yieldparam
|
48
|
-
# Individual files to be updated
|
49
|
-
# specified in the options.
|
45
|
+
# @yield [files]
|
46
|
+
# @yieldparam files [<(String, String, String)>]
|
47
|
+
# Individual files to be updated. Files in directories specified are included in this list.
|
50
48
|
# The first element of each pair is the source file,
|
51
|
-
# the second is the target CSS file
|
49
|
+
# the second is the target CSS file,
|
50
|
+
# the third is the target sourcemap file.
|
52
51
|
define_callback :updating_stylesheets
|
53
52
|
|
53
|
+
# Register a callback to be run after stylesheets are mass-updated.
|
54
|
+
# This is run whenever \{#update\_stylesheets} is called,
|
55
|
+
# unless the \{file:SASS_REFERENCE.md#never_update-option `:never_update` option}
|
56
|
+
# is enabled.
|
57
|
+
#
|
58
|
+
# @yield [updated_files]
|
59
|
+
# @yieldparam updated_files [<(String, String)>]
|
60
|
+
# Individual files that were updated.
|
61
|
+
# The first element of each pair is the source file, the second is the target CSS file.
|
62
|
+
define_callback :updated_stylesheets
|
63
|
+
|
54
64
|
# Register a callback to be run after a single stylesheet is updated.
|
55
65
|
# The callback is only run if the stylesheet is really updated;
|
56
66
|
# if the CSS file is fresh, this won't be run.
|
@@ -60,35 +70,29 @@ module Sass::Plugin
|
|
60
70
|
# when an exception CSS file is being written.
|
61
71
|
# To run an action for those files, use \{#on\_compilation\_error}.
|
62
72
|
#
|
63
|
-
# @yield [template, css]
|
73
|
+
# @yield [template, css, sourcemap]
|
64
74
|
# @yieldparam template [String]
|
65
75
|
# The location of the Sass/SCSS file being updated.
|
66
76
|
# @yieldparam css [String]
|
67
77
|
# The location of the CSS file being generated.
|
78
|
+
# @yieldparam sourcemap [String]
|
79
|
+
# The location of the sourcemap being generated, if any.
|
68
80
|
define_callback :updated_stylesheet
|
69
81
|
|
70
|
-
# Register a callback to be run
|
71
|
-
# The callback is only run if the stylesheet is guaranteed to be updated;
|
72
|
-
# if the CSS file is fresh, this won't be run.
|
82
|
+
# Register a callback to be run when compilation starts.
|
73
83
|
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
# To run an action for those files, use \{#on\_compilation\_error}.
|
84
|
+
# In combination with on_updated_stylesheet, this could be used
|
85
|
+
# to collect compilation statistics like timing or to take a
|
86
|
+
# diff of the changes to the output file.
|
78
87
|
#
|
79
|
-
# @yield [template, css]
|
88
|
+
# @yield [template, css, sourcemap]
|
80
89
|
# @yieldparam template [String]
|
81
90
|
# The location of the Sass/SCSS file being updated.
|
82
91
|
# @yieldparam css [String]
|
83
92
|
# The location of the CSS file being generated.
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
Sass::Util.sass_warn("Sass::Compiler#on_updating_stylesheet callback is deprecated and will be removed in a future release. Use Sass::Compiler#on_updated_stylesheet instead, which is run after stylesheet compilation.")
|
88
|
-
on_updating_stylesheet_without_deprecation_warning(&block)
|
89
|
-
end
|
90
|
-
alias_method :on_updating_stylesheet_without_deprecation_warning, :on_updating_stylesheet
|
91
|
-
alias_method :on_updating_stylesheet, :on_updating_stylesheet_with_deprecation_warning
|
93
|
+
# @yieldparam sourcemap [String]
|
94
|
+
# The location of the sourcemap being generated, if any.
|
95
|
+
define_callback :compilation_starting
|
92
96
|
|
93
97
|
# Register a callback to be run when Sass decides not to update a stylesheet.
|
94
98
|
# In particular, the callback is run when Sass finds that
|
@@ -162,49 +166,98 @@ module Sass::Plugin
|
|
162
166
|
define_callback :template_deleted
|
163
167
|
|
164
168
|
# Register a callback to be run when Sass deletes a CSS file.
|
165
|
-
# This happens when the corresponding Sass/SCSS file has been deleted
|
169
|
+
# This happens when the corresponding Sass/SCSS file has been deleted
|
170
|
+
# and when the compiler cleans the output files.
|
166
171
|
#
|
167
172
|
# @yield [filename]
|
168
173
|
# @yieldparam filename [String]
|
169
174
|
# The location of the CSS file that was deleted.
|
170
175
|
define_callback :deleting_css
|
171
176
|
|
177
|
+
# Register a callback to be run when Sass deletes a sourcemap file.
|
178
|
+
# This happens when the corresponding Sass/SCSS file has been deleted
|
179
|
+
# and when the compiler cleans the output files.
|
180
|
+
#
|
181
|
+
# @yield [filename]
|
182
|
+
# @yieldparam filename [String]
|
183
|
+
# The location of the sourcemap file that was deleted.
|
184
|
+
define_callback :deleting_sourcemap
|
185
|
+
|
172
186
|
# Updates out-of-date stylesheets.
|
173
187
|
#
|
174
|
-
# Checks each Sass/SCSS file in
|
188
|
+
# Checks each Sass/SCSS file in
|
189
|
+
# {file:SASS_REFERENCE.md#template_location-option `:template_location`}
|
175
190
|
# to see if it's been modified more recently than the corresponding CSS file
|
176
191
|
# in {file:SASS_REFERENCE.md#css_location-option `:css_location`}.
|
177
192
|
# If it has, it updates the CSS file.
|
178
193
|
#
|
179
|
-
# @param individual_files [Array<(String, String)>]
|
194
|
+
# @param individual_files [Array<(String, String[, String])>]
|
180
195
|
# A list of files to check for updates
|
181
196
|
# **in addition to those specified by the
|
182
197
|
# {file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
|
183
198
|
# The first string in each pair is the location of the Sass/SCSS file,
|
184
199
|
# the second is the location of the CSS file that it should be compiled to.
|
200
|
+
# The third string, if provided, is the location of the Sourcemap file.
|
185
201
|
def update_stylesheets(individual_files = [])
|
186
|
-
individual_files = individual_files.dup
|
187
202
|
Sass::Plugin.checked_for_updates = true
|
188
203
|
staleness_checker = StalenessChecker.new(engine_options)
|
189
204
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
205
|
+
files = file_list(individual_files)
|
206
|
+
run_updating_stylesheets(files)
|
207
|
+
|
208
|
+
updated_stylesheets = []
|
209
|
+
files.each do |file, css, sourcemap|
|
210
|
+
# TODO: Does staleness_checker need to check the sourcemap file as well?
|
211
|
+
if options[:always_update] || staleness_checker.stylesheet_needs_update?(css, file)
|
212
|
+
# XXX For consistency, this should return the sourcemap too, but it would
|
213
|
+
# XXX be an API change.
|
214
|
+
updated_stylesheets << [file, css]
|
215
|
+
update_stylesheet(file, css, sourcemap)
|
216
|
+
else
|
217
|
+
run_not_updating_stylesheet(file, css, sourcemap)
|
196
218
|
end
|
197
219
|
end
|
220
|
+
run_updated_stylesheets(updated_stylesheets)
|
221
|
+
end
|
198
222
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
223
|
+
# Construct a list of files that might need to be compiled
|
224
|
+
# from the provided individual_files and the template_locations.
|
225
|
+
#
|
226
|
+
# Note: this method does not cache the results as they can change
|
227
|
+
# across invocations when sass files are added or removed.
|
228
|
+
#
|
229
|
+
# @param individual_files [Array<(String, String[, String])>]
|
230
|
+
# A list of files to check for updates
|
231
|
+
# **in addition to those specified by the
|
232
|
+
# {file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
|
233
|
+
# The first string in each pair is the location of the Sass/SCSS file,
|
234
|
+
# the second is the location of the CSS file that it should be compiled to.
|
235
|
+
# The third string, if provided, is the location of the Sourcemap file.
|
236
|
+
# @return [Array<(String, String, String)>]
|
237
|
+
# A list of [sass_file, css_file, sourcemap_file] tuples similar
|
238
|
+
# to what was passed in, but expanded to include the current state
|
239
|
+
# of the directories being updated.
|
240
|
+
def file_list(individual_files = [])
|
241
|
+
files = individual_files.map do |tuple|
|
242
|
+
if engine_options[:sourcemap] == :none
|
243
|
+
tuple[0..1]
|
244
|
+
elsif tuple.size < 3
|
245
|
+
[tuple[0], tuple[1], Sass::Util.sourcemap_name(tuple[1])]
|
204
246
|
else
|
205
|
-
|
247
|
+
tuple.dup
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
template_location_array.each do |template_location, css_location|
|
252
|
+
Sass::Util.glob(File.join(template_location, "**", "[^_]*.s[ca]ss")).sort.each do |file|
|
253
|
+
# Get the relative path to the file
|
254
|
+
name = Sass::Util.relative_path_from(file, template_location).to_s
|
255
|
+
css = css_filename(name, css_location)
|
256
|
+
sourcemap = Sass::Util.sourcemap_name(css) unless engine_options[:sourcemap] == :none
|
257
|
+
files << [file, css, sourcemap]
|
206
258
|
end
|
207
259
|
end
|
260
|
+
files
|
208
261
|
end
|
209
262
|
|
210
263
|
# Watches the template directory (or directories)
|
@@ -225,73 +278,67 @@ module Sass::Plugin
|
|
225
278
|
# The version of Listen distributed with Sass is loaded by default,
|
226
279
|
# but if another version has already been loaded that will be used instead.
|
227
280
|
#
|
228
|
-
# @param individual_files [Array<(String, String)>]
|
229
|
-
# A list of files to
|
281
|
+
# @param individual_files [Array<(String, String[, String])>]
|
282
|
+
# A list of files to check for updates
|
230
283
|
# **in addition to those specified by the
|
231
284
|
# {file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
|
232
285
|
# The first string in each pair is the location of the Sass/SCSS file,
|
233
286
|
# the second is the location of the CSS file that it should be compiled to.
|
234
|
-
|
235
|
-
|
287
|
+
# The third string, if provided, is the location of the Sourcemap file.
|
288
|
+
# @param options [Hash] The options that control how watching works.
|
289
|
+
# @option options [Boolean] :skip_initial_update
|
290
|
+
# Don't do an initial update when starting the watcher when true
|
291
|
+
def watch(individual_files = [], options = {})
|
292
|
+
@inferred_directories = []
|
293
|
+
options, individual_files = individual_files, [] if individual_files.is_a?(Hash)
|
294
|
+
update_stylesheets(individual_files) unless options[:skip_initial_update]
|
295
|
+
|
296
|
+
directories = watched_paths
|
297
|
+
individual_files.each do |(source, _, _)|
|
298
|
+
source = File.expand_path(source)
|
299
|
+
@watched_files << Sass::Util.realpath(source).to_s
|
300
|
+
@inferred_directories << File.dirname(source)
|
301
|
+
end
|
236
302
|
|
237
|
-
|
303
|
+
directories += @inferred_directories
|
304
|
+
directories = remove_redundant_directories(directories)
|
238
305
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
306
|
+
# A Listen version prior to 2.0 will write a test file to a directory to
|
307
|
+
# see if a watcher supports watching that directory. That breaks horribly
|
308
|
+
# on read-only directories, so we filter those out.
|
309
|
+
unless Sass::Util.listen_geq_2?
|
310
|
+
directories = directories.select {|d| File.directory?(d) && File.writable?(d)}
|
244
311
|
end
|
245
|
-
directories = template_paths + individual_files_hash.keys +
|
246
|
-
[{:relative_paths => true}]
|
247
312
|
|
248
313
|
# TODO: Keep better track of what depends on what
|
249
314
|
# so we don't have to run a global update every time anything changes.
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
if files = individual_files_hash[parent]
|
264
|
-
next unless files.first == f
|
265
|
-
else
|
266
|
-
next unless f =~ /\.s[ac]ss$/
|
267
|
-
end
|
268
|
-
run_template_created(f)
|
269
|
-
end
|
270
|
-
|
271
|
-
removed.each do |f|
|
272
|
-
parent = File.dirname(f)
|
273
|
-
if files = individual_files_hash[parent]
|
274
|
-
next unless files.first == f
|
275
|
-
try_delete_css files[1]
|
276
|
-
else
|
277
|
-
next unless f =~ /\.s[ac]ss$/
|
278
|
-
try_delete_css f.gsub(/\.s[ac]ss$/, '.css')
|
279
|
-
end
|
280
|
-
run_template_deleted(f)
|
281
|
-
end
|
282
|
-
|
283
|
-
update_stylesheets(individual_files)
|
315
|
+
# XXX The :additional_watch_paths option exists for Compass to use until
|
316
|
+
# a deprecated feature is removed. It may be removed without warning.
|
317
|
+
listener_args = directories +
|
318
|
+
Array(options[:additional_watch_paths]) +
|
319
|
+
[{:relative_paths => false}]
|
320
|
+
|
321
|
+
# The native windows listener is much slower than the polling option, according to
|
322
|
+
# https://github.com/nex3/sass/commit/a3031856b22bc834a5417dedecb038b7be9b9e3e
|
323
|
+
poll = @options[:poll] || Sass::Util.windows?
|
324
|
+
if poll && Sass::Util.listen_geq_2?
|
325
|
+
# In Listen 2.0.0 and on, :force_polling is an option. In earlier
|
326
|
+
# versions, it's a method on the listener (called below).
|
327
|
+
listener_args.last[:force_polling] = true
|
284
328
|
end
|
285
329
|
|
286
|
-
|
287
|
-
|
288
|
-
|
330
|
+
listener = create_listener(*listener_args) do |modified, added, removed|
|
331
|
+
on_file_changed(individual_files, modified, added, removed)
|
332
|
+
yield(modified, added, removed) if block_given?
|
333
|
+
end
|
289
334
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
335
|
+
if poll && !Sass::Util.listen_geq_2?
|
336
|
+
# In Listen 2.0.0 and on, :force_polling is an option (set above). In
|
337
|
+
# earlier versions, it's a method on the listener.
|
338
|
+
listener.force_polling(true)
|
294
339
|
end
|
340
|
+
|
341
|
+
listen_to(listener)
|
295
342
|
end
|
296
343
|
|
297
344
|
# Non-destructively modifies \{#options} so that default values are properly set,
|
@@ -302,6 +349,8 @@ module Sass::Plugin
|
|
302
349
|
def engine_options(additional_options = {})
|
303
350
|
opts = options.merge(additional_options)
|
304
351
|
opts[:load_paths] = load_paths(opts)
|
352
|
+
options[:sourcemap] = :auto if options[:sourcemap] == true
|
353
|
+
options[:sourcemap] = :none if options[:sourcemap] == false
|
305
354
|
opts
|
306
355
|
end
|
307
356
|
|
@@ -310,81 +359,196 @@ module Sass::Plugin
|
|
310
359
|
StalenessChecker.stylesheet_needs_update?(css_file, template_file)
|
311
360
|
end
|
312
361
|
|
362
|
+
# Remove all output files that would be created by calling update_stylesheets, if they exist.
|
363
|
+
#
|
364
|
+
# This method runs the deleting_css and deleting_sourcemap callbacks for
|
365
|
+
# the files that are deleted.
|
366
|
+
#
|
367
|
+
# @param individual_files [Array<(String, String[, String])>]
|
368
|
+
# A list of files to check for updates
|
369
|
+
# **in addition to those specified by the
|
370
|
+
# {file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
|
371
|
+
# The first string in each pair is the location of the Sass/SCSS file,
|
372
|
+
# the second is the location of the CSS file that it should be compiled to.
|
373
|
+
# The third string, if provided, is the location of the Sourcemap file.
|
374
|
+
def clean(individual_files = [])
|
375
|
+
file_list(individual_files).each do |(_, css_file, sourcemap_file)|
|
376
|
+
if File.exist?(css_file)
|
377
|
+
run_deleting_css css_file
|
378
|
+
File.delete(css_file)
|
379
|
+
end
|
380
|
+
if sourcemap_file && File.exist?(sourcemap_file)
|
381
|
+
run_deleting_sourcemap sourcemap_file
|
382
|
+
File.delete(sourcemap_file)
|
383
|
+
end
|
384
|
+
end
|
385
|
+
nil
|
386
|
+
end
|
387
|
+
|
313
388
|
private
|
314
389
|
|
315
|
-
def
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
dir
|
322
|
-
$LOAD_PATH.unshift dir
|
323
|
-
begin
|
324
|
-
require 'listen'
|
325
|
-
rescue LoadError => e
|
326
|
-
e.message << "\n" <<
|
327
|
-
if File.exists?(scope(".git"))
|
328
|
-
'Run "git submodule update --init" to get the recommended version.'
|
329
|
-
else
|
330
|
-
'Run "gem install listen" to get it.'
|
331
|
-
end
|
332
|
-
raise e
|
333
|
-
end
|
390
|
+
def create_listener(*args, &block)
|
391
|
+
Sass::Util.load_listen!
|
392
|
+
if Sass::Util.listen_geq_2?
|
393
|
+
# Work around guard/listen#243.
|
394
|
+
options = args.pop if args.last.is_a?(Hash)
|
395
|
+
args.map do |dir|
|
396
|
+
Listen.to(dir, options, &block)
|
334
397
|
end
|
335
398
|
else
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
399
|
+
Listen::Listener.new(*args, &block)
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
def listen_to(listener)
|
404
|
+
if Sass::Util.listen_geq_2?
|
405
|
+
listener.map {|l| l.start}
|
406
|
+
sleep
|
407
|
+
else
|
408
|
+
listener.start!
|
409
|
+
end
|
410
|
+
rescue Interrupt
|
411
|
+
# Squelch Interrupt for clean exit from Listen::Listener
|
412
|
+
end
|
413
|
+
|
414
|
+
def remove_redundant_directories(directories)
|
415
|
+
dedupped = []
|
416
|
+
directories.each do |new_directory|
|
417
|
+
# no need to add a directory that is already watched.
|
418
|
+
next if dedupped.any? do |existing_directory|
|
419
|
+
child_of_directory?(existing_directory, new_directory)
|
420
|
+
end
|
421
|
+
# get rid of any sub directories of this new directory
|
422
|
+
dedupped.reject! do |existing_directory|
|
423
|
+
child_of_directory?(new_directory, existing_directory)
|
424
|
+
end
|
425
|
+
dedupped << new_directory
|
426
|
+
end
|
427
|
+
dedupped
|
428
|
+
end
|
429
|
+
|
430
|
+
def on_file_changed(individual_files, modified, added, removed)
|
431
|
+
recompile_required = false
|
432
|
+
|
433
|
+
modified.uniq.each do |f|
|
434
|
+
next unless watched_file?(f)
|
435
|
+
recompile_required = true
|
436
|
+
run_template_modified(relative_to_pwd(f))
|
437
|
+
end
|
438
|
+
|
439
|
+
added.uniq.each do |f|
|
440
|
+
next unless watched_file?(f)
|
441
|
+
recompile_required = true
|
442
|
+
run_template_created(relative_to_pwd(f))
|
443
|
+
end
|
444
|
+
|
445
|
+
removed.uniq.each do |f|
|
446
|
+
next unless watched_file?(f)
|
447
|
+
run_template_deleted(relative_to_pwd(f))
|
448
|
+
if (files = individual_files.find {|(source, _, _)| File.expand_path(source) == f})
|
449
|
+
recompile_required = true
|
450
|
+
# This was a file we were watching explicitly and compiling to a particular location.
|
451
|
+
# Delete the corresponding file.
|
452
|
+
try_delete_css files[1]
|
453
|
+
else
|
454
|
+
next unless watched_file?(f)
|
455
|
+
recompile_required = true
|
456
|
+
# Look for the sass directory that contained the sass file
|
457
|
+
# And try to remove the css file that corresponds to it
|
458
|
+
template_location_array.each do |(sass_dir, css_dir)|
|
459
|
+
sass_dir = File.expand_path(sass_dir)
|
460
|
+
next unless child_of_directory?(sass_dir, f)
|
461
|
+
remainder = f[(sass_dir.size + 1)..-1]
|
462
|
+
try_delete_css(css_filename(remainder, css_dir))
|
463
|
+
break
|
347
464
|
end
|
348
465
|
end
|
349
466
|
end
|
467
|
+
|
468
|
+
return unless recompile_required
|
469
|
+
|
470
|
+
# In case a file we're watching is removed and then recreated we
|
471
|
+
# prune out the non-existant files here.
|
472
|
+
watched_files_remaining = individual_files.select {|(source, _, _)| File.exist?(source)}
|
473
|
+
update_stylesheets(watched_files_remaining)
|
350
474
|
end
|
351
475
|
|
352
|
-
def update_stylesheet(filename, css)
|
476
|
+
def update_stylesheet(filename, css, sourcemap)
|
353
477
|
dir = File.dirname(css)
|
354
|
-
unless File.
|
478
|
+
unless File.exist?(dir)
|
355
479
|
run_creating_directory dir
|
356
480
|
FileUtils.mkdir_p dir
|
357
481
|
end
|
358
482
|
|
359
483
|
begin
|
360
484
|
File.read(filename) unless File.readable?(filename) # triggers an error for handling
|
361
|
-
engine_opts = engine_options(:css_filename => css,
|
362
|
-
|
363
|
-
|
485
|
+
engine_opts = engine_options(:css_filename => css,
|
486
|
+
:filename => filename,
|
487
|
+
:sourcemap_filename => sourcemap)
|
488
|
+
mapping = nil
|
489
|
+
run_compilation_starting(filename, css, sourcemap)
|
490
|
+
engine = Sass::Engine.for_file(filename, engine_opts)
|
491
|
+
if sourcemap
|
492
|
+
rendered, mapping = engine.render_with_sourcemap(File.basename(sourcemap))
|
493
|
+
else
|
494
|
+
rendered = engine.render
|
495
|
+
end
|
496
|
+
rescue StandardError => e
|
364
497
|
compilation_error_occured = true
|
365
|
-
run_compilation_error e, filename, css
|
366
|
-
|
367
|
-
|
368
|
-
run_updating_stylesheet filename, css
|
498
|
+
run_compilation_error e, filename, css, sourcemap
|
499
|
+
raise e unless options[:full_exception]
|
500
|
+
rendered = Sass::SyntaxError.exception_to_css(e, options[:line] || 1)
|
369
501
|
end
|
370
502
|
|
371
|
-
write_file(css,
|
372
|
-
|
503
|
+
write_file(css, rendered)
|
504
|
+
if mapping
|
505
|
+
write_file(
|
506
|
+
sourcemap,
|
507
|
+
mapping.to_json(
|
508
|
+
:css_path => css, :sourcemap_path => sourcemap, :type => options[:sourcemap]))
|
509
|
+
end
|
510
|
+
run_updated_stylesheet(filename, css, sourcemap) unless compilation_error_occured
|
373
511
|
end
|
374
512
|
|
375
|
-
def write_file(
|
513
|
+
def write_file(fileName, content)
|
376
514
|
flag = 'w'
|
377
515
|
flag = 'wb' if Sass::Util.windows? && options[:unix_newlines]
|
378
|
-
File.open(
|
516
|
+
File.open(fileName, flag) do |file|
|
379
517
|
file.set_encoding(content.encoding) unless Sass::Util.ruby1_8?
|
380
518
|
file.print(content)
|
381
519
|
end
|
382
520
|
end
|
383
521
|
|
384
522
|
def try_delete_css(css)
|
385
|
-
|
386
|
-
|
387
|
-
|
523
|
+
if File.exist?(css)
|
524
|
+
run_deleting_css css
|
525
|
+
File.delete css
|
526
|
+
end
|
527
|
+
map = Sass::Util.sourcemap_name(css)
|
528
|
+
|
529
|
+
return unless File.exist?(map)
|
530
|
+
|
531
|
+
run_deleting_sourcemap map
|
532
|
+
File.delete map
|
533
|
+
end
|
534
|
+
|
535
|
+
def watched_file?(file)
|
536
|
+
@watched_files.include?(file) ||
|
537
|
+
normalized_load_paths.any? {|lp| lp.watched_file?(file)} ||
|
538
|
+
@inferred_directories.any? {|d| sass_file_in_directory?(d, file)}
|
539
|
+
end
|
540
|
+
|
541
|
+
def sass_file_in_directory?(directory, filename)
|
542
|
+
filename =~ /\.s[ac]ss$/ && filename.start_with?(directory + File::SEPARATOR)
|
543
|
+
end
|
544
|
+
|
545
|
+
def watched_paths
|
546
|
+
@watched_paths ||= normalized_load_paths.map {|lp| lp.directories_to_watch}.compact.flatten
|
547
|
+
end
|
548
|
+
|
549
|
+
def normalized_load_paths
|
550
|
+
@normalized_load_paths ||=
|
551
|
+
Sass::Engine.normalize_options(:load_paths => load_paths)[:load_paths]
|
388
552
|
end
|
389
553
|
|
390
554
|
def load_paths(opts = options)
|
@@ -400,7 +564,19 @@ module Sass::Plugin
|
|
400
564
|
end
|
401
565
|
|
402
566
|
def css_filename(name, path)
|
403
|
-
"#{path}
|
567
|
+
"#{path}#{File::SEPARATOR unless path.end_with?(File::SEPARATOR)}#{name}".
|
568
|
+
gsub(/\.s[ac]ss$/, '.css')
|
569
|
+
end
|
570
|
+
|
571
|
+
def relative_to_pwd(f)
|
572
|
+
Sass::Util.relative_path_from(f, Dir.pwd).to_s
|
573
|
+
rescue ArgumentError # when a relative path cannot be computed
|
574
|
+
f
|
575
|
+
end
|
576
|
+
|
577
|
+
def child_of_directory?(parent, child)
|
578
|
+
parent_dir = parent.end_with?(File::SEPARATOR) ? parent : (parent + File::SEPARATOR)
|
579
|
+
child.start_with?(parent_dir) || parent == child
|
404
580
|
end
|
405
581
|
end
|
406
582
|
end
|