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/exec.rb
CHANGED
@@ -1,707 +1,9 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
1
|
module Sass
|
5
|
-
# This module handles the
|
2
|
+
# This module handles the Sass executables (`sass` and `sass-convert`).
|
6
3
|
module Exec
|
7
|
-
# An abstract class that encapsulates the executable code for all three executables.
|
8
|
-
class Generic
|
9
|
-
# @param args [Array<String>] The command-line arguments
|
10
|
-
def initialize(args)
|
11
|
-
@args = args
|
12
|
-
@options = {}
|
13
|
-
end
|
14
|
-
|
15
|
-
# Parses the command-line arguments and runs the executable.
|
16
|
-
# Calls `Kernel#exit` at the end, so it never returns.
|
17
|
-
#
|
18
|
-
# @see #parse
|
19
|
-
def parse!
|
20
|
-
begin
|
21
|
-
parse
|
22
|
-
rescue Exception => e
|
23
|
-
raise e if @options[:trace] || e.is_a?(SystemExit)
|
24
|
-
|
25
|
-
$stderr.print "#{e.class}: " unless e.class == RuntimeError
|
26
|
-
$stderr.puts "#{e.message}"
|
27
|
-
$stderr.puts " Use --trace for backtrace."
|
28
|
-
exit 1
|
29
|
-
end
|
30
|
-
exit 0
|
31
|
-
end
|
32
|
-
|
33
|
-
# Parses the command-line arguments and runs the executable.
|
34
|
-
# This does not handle exceptions or exit the program.
|
35
|
-
#
|
36
|
-
# @see #parse!
|
37
|
-
def parse
|
38
|
-
@opts = OptionParser.new(&method(:set_opts))
|
39
|
-
@opts.parse!(@args)
|
40
|
-
|
41
|
-
process_result
|
42
|
-
|
43
|
-
@options
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [String] A description of the executable
|
47
|
-
def to_s
|
48
|
-
@opts.to_s
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
# Finds the line of the source template
|
54
|
-
# on which an exception was raised.
|
55
|
-
#
|
56
|
-
# @param exception [Exception] The exception
|
57
|
-
# @return [String] The line number
|
58
|
-
def get_line(exception)
|
59
|
-
# SyntaxErrors have weird line reporting
|
60
|
-
# when there's trailing whitespace
|
61
|
-
return (exception.message.scan(/:(\d+)/).first || ["??"]).first if exception.is_a?(::SyntaxError)
|
62
|
-
(exception.backtrace[0].scan(/:(\d+)/).first || ["??"]).first
|
63
|
-
end
|
64
|
-
|
65
|
-
# Tells optparse how to parse the arguments
|
66
|
-
# available for all executables.
|
67
|
-
#
|
68
|
-
# This is meant to be overridden by subclasses
|
69
|
-
# so they can add their own options.
|
70
|
-
#
|
71
|
-
# @param opts [OptionParser]
|
72
|
-
def set_opts(opts)
|
73
|
-
opts.on('-s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
|
74
|
-
@options[:input] = $stdin
|
75
|
-
end
|
76
|
-
|
77
|
-
opts.on('--trace', :NONE, 'Show a full traceback on error') do
|
78
|
-
@options[:trace] = true
|
79
|
-
end
|
80
|
-
|
81
|
-
opts.on('--unix-newlines', 'Use Unix-style newlines in written files.') do
|
82
|
-
@options[:unix_newlines] = true if ::Sass::Util.windows?
|
83
|
-
end
|
84
|
-
|
85
|
-
opts.on_tail("-?", "-h", "--help", "Show this message") do
|
86
|
-
puts opts
|
87
|
-
exit
|
88
|
-
end
|
89
|
-
|
90
|
-
opts.on_tail("-v", "--version", "Print version") do
|
91
|
-
puts("Sass #{::Sass.version[:string]}")
|
92
|
-
exit
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Processes the options set by the command-line arguments.
|
97
|
-
# In particular, sets `@options[:input]` and `@options[:output]`
|
98
|
-
# to appropriate IO streams.
|
99
|
-
#
|
100
|
-
# This is meant to be overridden by subclasses
|
101
|
-
# so they can run their respective programs.
|
102
|
-
def process_result
|
103
|
-
input, output = @options[:input], @options[:output]
|
104
|
-
args = @args.dup
|
105
|
-
input ||=
|
106
|
-
begin
|
107
|
-
filename = args.shift
|
108
|
-
@options[:filename] = filename
|
109
|
-
open_file(filename) || $stdin
|
110
|
-
end
|
111
|
-
output ||= args.shift || $stdout
|
112
|
-
|
113
|
-
@options[:input], @options[:output] = input, output
|
114
|
-
end
|
115
|
-
|
116
|
-
COLORS = { :red => 31, :green => 32, :yellow => 33 }
|
117
|
-
|
118
|
-
# Prints a status message about performing the given action,
|
119
|
-
# colored using the given color (via terminal escapes) if possible.
|
120
|
-
#
|
121
|
-
# @param name [#to_s] A short name for the action being performed.
|
122
|
-
# Shouldn't be longer than 11 characters.
|
123
|
-
# @param color [Symbol] The name of the color to use for this action.
|
124
|
-
# Can be `:red`, `:green`, or `:yellow`.
|
125
|
-
def puts_action(name, color, arg)
|
126
|
-
return if @options[:for_engine][:quiet]
|
127
|
-
printf color(color, "%11s %s\n"), name, arg
|
128
|
-
STDOUT.flush
|
129
|
-
end
|
130
|
-
|
131
|
-
# Same as \{Kernel.puts}, but doesn't print anything if the `--quiet` option is set.
|
132
|
-
#
|
133
|
-
# @param args [Array] Passed on to \{Kernel.puts}
|
134
|
-
def puts(*args)
|
135
|
-
return if @options[:for_engine][:quiet]
|
136
|
-
Kernel.puts(*args)
|
137
|
-
end
|
138
|
-
|
139
|
-
# Wraps the given string in terminal escapes
|
140
|
-
# causing it to have the given color.
|
141
|
-
# If terminal esapes aren't supported on this platform,
|
142
|
-
# just returns the string instead.
|
143
|
-
#
|
144
|
-
# @param color [Symbol] The name of the color to use.
|
145
|
-
# Can be `:red`, `:green`, or `:yellow`.
|
146
|
-
# @param str [String] The string to wrap in the given color.
|
147
|
-
# @return [String] The wrapped string.
|
148
|
-
def color(color, str)
|
149
|
-
raise "[BUG] Unrecognized color #{color}" unless COLORS[color]
|
150
|
-
|
151
|
-
# Almost any real Unix terminal will support color,
|
152
|
-
# so we just filter for Windows terms (which don't set TERM)
|
153
|
-
# and not-real terminals, which aren't ttys.
|
154
|
-
return str if ENV["TERM"].nil? || ENV["TERM"].empty? || !STDOUT.tty?
|
155
|
-
return "\e[#{COLORS[color]}m#{str}\e[0m"
|
156
|
-
end
|
157
|
-
|
158
|
-
def write_output(text, destination)
|
159
|
-
if destination.is_a?(String)
|
160
|
-
open_file(destination, 'w') {|file| file.write(text)}
|
161
|
-
else
|
162
|
-
destination.write(text)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
private
|
167
|
-
|
168
|
-
def open_file(filename, flag = 'r')
|
169
|
-
return if filename.nil?
|
170
|
-
flag = 'wb' if @options[:unix_newlines] && flag == 'w'
|
171
|
-
file = File.open(filename, flag)
|
172
|
-
return file unless block_given?
|
173
|
-
yield file
|
174
|
-
file.close
|
175
|
-
end
|
176
|
-
|
177
|
-
def handle_load_error(err)
|
178
|
-
dep = err.message[/^no such file to load -- (.*)/, 1]
|
179
|
-
raise err if @options[:trace] || dep.nil? || dep.empty?
|
180
|
-
$stderr.puts <<MESSAGE
|
181
|
-
Required dependency #{dep} not found!
|
182
|
-
Run "gem install #{dep}" to get it.
|
183
|
-
Use --trace for backtrace.
|
184
|
-
MESSAGE
|
185
|
-
exit 1
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
# The `sass` executable.
|
190
|
-
class Sass < Generic
|
191
|
-
attr_reader :default_syntax
|
192
|
-
|
193
|
-
# @param args [Array<String>] The command-line arguments
|
194
|
-
def initialize(args)
|
195
|
-
super
|
196
|
-
@options[:for_engine] = {
|
197
|
-
:load_paths => ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
|
198
|
-
}
|
199
|
-
@default_syntax = :sass
|
200
|
-
end
|
201
|
-
|
202
|
-
protected
|
203
|
-
|
204
|
-
# Tells optparse how to parse the arguments.
|
205
|
-
#
|
206
|
-
# @param opts [OptionParser]
|
207
|
-
def set_opts(opts)
|
208
|
-
super
|
209
|
-
|
210
|
-
opts.banner = <<END
|
211
|
-
Usage: #{default_syntax} [options] [INPUT] [OUTPUT]
|
212
|
-
|
213
|
-
Description:
|
214
|
-
Converts SCSS or Sass files to CSS.
|
215
|
-
|
216
|
-
Options:
|
217
|
-
END
|
218
|
-
|
219
|
-
if @default_syntax == :sass
|
220
|
-
opts.on('--scss',
|
221
|
-
'Use the CSS-superset SCSS syntax.') do
|
222
|
-
@options[:for_engine][:syntax] = :scss
|
223
|
-
end
|
224
|
-
else
|
225
|
-
opts.on('--sass',
|
226
|
-
'Use the Indented syntax.') do
|
227
|
-
@options[:for_engine][:syntax] = :sass
|
228
|
-
end
|
229
|
-
end
|
230
|
-
opts.on('--watch', 'Watch files or directories for changes.',
|
231
|
-
'The location of the generated CSS can be set using a colon:',
|
232
|
-
" #{@default_syntax} --watch input.#{@default_syntax}:output.css",
|
233
|
-
" #{@default_syntax} --watch input-dir:output-dir") do
|
234
|
-
@options[:watch] = true
|
235
|
-
end
|
236
|
-
opts.on('--update', 'Compile files or directories to CSS.',
|
237
|
-
'Locations are set like --watch.') do
|
238
|
-
@options[:update] = true
|
239
|
-
end
|
240
|
-
opts.on('--stop-on-error', 'If a file fails to compile, exit immediately.',
|
241
|
-
'Only meaningful for --watch and --update.') do
|
242
|
-
@options[:stop_on_error] = true
|
243
|
-
end
|
244
|
-
opts.on('--poll', 'Check for file changes manually, rather than relying on the OS.',
|
245
|
-
'Only meaningful for --watch.') do
|
246
|
-
@options[:poll] = true
|
247
|
-
end
|
248
|
-
opts.on('-f', '--force', 'Recompile all Sass files, even if the CSS file is newer.',
|
249
|
-
'Only meaningful for --update.') do
|
250
|
-
@options[:force] = true
|
251
|
-
end
|
252
|
-
opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
|
253
|
-
require 'stringio'
|
254
|
-
@options[:check_syntax] = true
|
255
|
-
@options[:output] = StringIO.new
|
256
|
-
end
|
257
|
-
opts.on('-t', '--style NAME',
|
258
|
-
'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
|
259
|
-
@options[:for_engine][:style] = name.to_sym
|
260
|
-
end
|
261
|
-
opts.on('--precision NUMBER_OF_DIGITS', Integer,
|
262
|
-
'How many digits of precision to use when outputting decimal numbers. Defaults to 3.') do |precision|
|
263
|
-
::Sass::Script::Number.precision = precision
|
264
|
-
end
|
265
|
-
opts.on('-q', '--quiet', 'Silence warnings and status messages during compilation.') do
|
266
|
-
@options[:for_engine][:quiet] = true
|
267
|
-
end
|
268
|
-
opts.on('--compass', 'Make Compass imports available and load project configuration.') do
|
269
|
-
@options[:compass] = true
|
270
|
-
end
|
271
|
-
opts.on('-g', '--debug-info',
|
272
|
-
'Emit extra information in the generated CSS that can be used by the FireSass Firebug plugin.') do
|
273
|
-
@options[:for_engine][:debug_info] = true
|
274
|
-
end
|
275
|
-
opts.on('-l', '--line-numbers', '--line-comments',
|
276
|
-
'Emit comments in the generated CSS indicating the corresponding source line.') do
|
277
|
-
@options[:for_engine][:line_numbers] = true
|
278
|
-
end
|
279
|
-
opts.on('-i', '--interactive',
|
280
|
-
'Run an interactive SassScript shell.') do
|
281
|
-
@options[:interactive] = true
|
282
|
-
end
|
283
|
-
opts.on('-I', '--load-path PATH', 'Add a sass import path.') do |path|
|
284
|
-
@options[:for_engine][:load_paths] << path
|
285
|
-
end
|
286
|
-
opts.on('-r', '--require LIB', 'Require a Ruby library before running Sass.') do |lib|
|
287
|
-
require lib
|
288
|
-
end
|
289
|
-
opts.on('--cache-location PATH', 'The path to put cached Sass files. Defaults to .sass-cache.') do |loc|
|
290
|
-
@options[:for_engine][:cache_location] = loc
|
291
|
-
end
|
292
|
-
opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
|
293
|
-
@options[:for_engine][:cache] = false
|
294
|
-
end
|
295
|
-
|
296
|
-
encoding_desc = if ::Sass::Util.ruby1_8?
|
297
|
-
'Does not work in ruby 1.8.'
|
298
|
-
else
|
299
|
-
'Specify the default encoding for Sass files.'
|
300
|
-
end
|
301
|
-
opts.on('-E encoding', encoding_desc) do |encoding|
|
302
|
-
if ::Sass::Util.ruby1_8?
|
303
|
-
$stderr.puts "Specifying the encoding is not supported in ruby 1.8."
|
304
|
-
exit 1
|
305
|
-
else
|
306
|
-
Encoding.default_external = encoding
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
# Processes the options set by the command-line arguments,
|
312
|
-
# and runs the Sass compiler appropriately.
|
313
|
-
def process_result
|
314
|
-
require 'sass'
|
315
|
-
|
316
|
-
if !@options[:update] && !@options[:watch] &&
|
317
|
-
@args.first && colon_path?(@args.first)
|
318
|
-
if @args.size == 1
|
319
|
-
@args = split_colon_path(@args.first)
|
320
|
-
else
|
321
|
-
@options[:update] = true
|
322
|
-
end
|
323
|
-
end
|
324
|
-
load_compass if @options[:compass]
|
325
|
-
return interactive if @options[:interactive]
|
326
|
-
return watch_or_update if @options[:watch] || @options[:update]
|
327
|
-
super
|
328
|
-
@options[:for_engine][:filename] = @options[:filename]
|
329
|
-
@options[:for_engine][:css_filename] = @options[:output] if @options[:output].is_a?(String)
|
330
|
-
|
331
|
-
begin
|
332
|
-
input = @options[:input]
|
333
|
-
output = @options[:output]
|
334
|
-
|
335
|
-
@options[:for_engine][:syntax] ||= :scss if input.is_a?(File) && input.path =~ /\.scss$/
|
336
|
-
@options[:for_engine][:syntax] ||= @default_syntax
|
337
|
-
engine =
|
338
|
-
if input.is_a?(File) && !@options[:check_syntax]
|
339
|
-
::Sass::Engine.for_file(input.path, @options[:for_engine])
|
340
|
-
else
|
341
|
-
# We don't need to do any special handling of @options[:check_syntax] here,
|
342
|
-
# because the Sass syntax checking happens alongside evaluation
|
343
|
-
# and evaluation doesn't actually evaluate any code anyway.
|
344
|
-
::Sass::Engine.new(input.read(), @options[:for_engine])
|
345
|
-
end
|
346
|
-
|
347
|
-
input.close() if input.is_a?(File)
|
348
|
-
|
349
|
-
write_output(engine.render, output)
|
350
|
-
rescue ::Sass::SyntaxError => e
|
351
|
-
raise e if @options[:trace]
|
352
|
-
raise e.sass_backtrace_str("standard input")
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
private
|
357
|
-
|
358
|
-
def load_compass
|
359
|
-
begin
|
360
|
-
require 'compass'
|
361
|
-
rescue LoadError
|
362
|
-
require 'rubygems'
|
363
|
-
begin
|
364
|
-
require 'compass'
|
365
|
-
rescue LoadError
|
366
|
-
puts "ERROR: Cannot load compass."
|
367
|
-
exit 1
|
368
|
-
end
|
369
|
-
end
|
370
|
-
Compass.add_project_configuration
|
371
|
-
Compass.configuration.project_path ||= Dir.pwd
|
372
|
-
@options[:for_engine][:load_paths] += Compass.configuration.sass_load_paths
|
373
|
-
end
|
374
|
-
|
375
|
-
def interactive
|
376
|
-
require 'sass/repl'
|
377
|
-
::Sass::Repl.new(@options).run
|
378
|
-
end
|
379
|
-
|
380
|
-
def watch_or_update
|
381
|
-
require 'sass/plugin'
|
382
|
-
::Sass::Plugin.options.merge! @options[:for_engine]
|
383
|
-
::Sass::Plugin.options[:unix_newlines] = @options[:unix_newlines]
|
384
|
-
::Sass::Plugin.options[:poll] = @options[:poll]
|
385
|
-
|
386
|
-
if @options[:force]
|
387
|
-
raise "The --force flag may only be used with --update." unless @options[:update]
|
388
|
-
::Sass::Plugin.options[:always_update] = true
|
389
|
-
end
|
390
|
-
|
391
|
-
raise <<MSG if @args.empty?
|
392
|
-
What files should I watch? Did you mean something like:
|
393
|
-
#{@default_syntax} --watch input.#{@default_syntax}:output.css
|
394
|
-
#{@default_syntax} --watch input-dir:output-dir
|
395
|
-
MSG
|
396
|
-
|
397
|
-
if !colon_path?(@args[0]) && probably_dest_dir?(@args[1])
|
398
|
-
flag = @options[:update] ? "--update" : "--watch"
|
399
|
-
err =
|
400
|
-
if !File.exist?(@args[1])
|
401
|
-
"doesn't exist"
|
402
|
-
elsif @args[1] =~ /\.css$/
|
403
|
-
"is a CSS file"
|
404
|
-
end
|
405
|
-
raise <<MSG if err
|
406
|
-
File #{@args[1]} #{err}.
|
407
|
-
Did you mean: #{@default_syntax} #{flag} #{@args[0]}:#{@args[1]}
|
408
|
-
MSG
|
409
|
-
end
|
410
|
-
|
411
|
-
dirs, files = @args.map {|name| split_colon_path(name)}.
|
412
|
-
partition {|i, _| File.directory? i}
|
413
|
-
files.map! {|from, to| [from, to || from.gsub(/\.[^.]*?$/, '.css')]}
|
414
|
-
dirs.map! {|from, to| [from, to || from]}
|
415
|
-
::Sass::Plugin.options[:template_location] = dirs
|
416
|
-
|
417
|
-
::Sass::Plugin.on_updated_stylesheet do |_, css|
|
418
|
-
if File.exists? css
|
419
|
-
puts_action :overwrite, :yellow, css
|
420
|
-
else
|
421
|
-
puts_action :create, :green, css
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
had_error = false
|
426
|
-
::Sass::Plugin.on_creating_directory {|dirname| puts_action :directory, :green, dirname}
|
427
|
-
::Sass::Plugin.on_deleting_css {|filename| puts_action :delete, :yellow, filename}
|
428
|
-
::Sass::Plugin.on_compilation_error do |error, _, _|
|
429
|
-
if error.is_a?(SystemCallError) && !@options[:stop_on_error]
|
430
|
-
had_error = true
|
431
|
-
puts_action :error, :red, error.message
|
432
|
-
STDOUT.flush
|
433
|
-
next
|
434
|
-
end
|
435
|
-
|
436
|
-
raise error unless error.is_a?(::Sass::SyntaxError) && !@options[:stop_on_error]
|
437
|
-
had_error = true
|
438
|
-
puts_action :error, :red, "#{error.sass_filename} (Line #{error.sass_line}: #{error.message})"
|
439
|
-
STDOUT.flush
|
440
|
-
end
|
441
|
-
|
442
|
-
if @options[:update]
|
443
|
-
::Sass::Plugin.update_stylesheets(files)
|
444
|
-
exit 1 if had_error
|
445
|
-
return
|
446
|
-
end
|
447
|
-
|
448
|
-
puts ">>> Sass is watching for changes. Press Ctrl-C to stop."
|
449
|
-
|
450
|
-
::Sass::Plugin.on_template_modified do |template|
|
451
|
-
puts ">>> Change detected to: #{template}"
|
452
|
-
STDOUT.flush
|
453
|
-
end
|
454
|
-
::Sass::Plugin.on_template_created do |template|
|
455
|
-
puts ">>> New template detected: #{template}"
|
456
|
-
STDOUT.flush
|
457
|
-
end
|
458
|
-
::Sass::Plugin.on_template_deleted do |template|
|
459
|
-
puts ">>> Deleted template detected: #{template}"
|
460
|
-
STDOUT.flush
|
461
|
-
end
|
462
|
-
|
463
|
-
::Sass::Plugin.watch(files)
|
464
|
-
end
|
465
|
-
|
466
|
-
def colon_path?(path)
|
467
|
-
!split_colon_path(path)[1].nil?
|
468
|
-
end
|
469
|
-
|
470
|
-
def split_colon_path(path)
|
471
|
-
one, two = path.split(':', 2)
|
472
|
-
if one && two && ::Sass::Util.windows? &&
|
473
|
-
one =~ /\A[A-Za-z]\Z/ && two =~ /\A[\/\\]/
|
474
|
-
# If we're on Windows and we were passed a drive letter path,
|
475
|
-
# don't split on that colon.
|
476
|
-
one2, two = two.split(':', 2)
|
477
|
-
one = one + ':' + one2
|
478
|
-
end
|
479
|
-
return one, two
|
480
|
-
end
|
481
|
-
|
482
|
-
# Whether path is likely to be meant as the destination
|
483
|
-
# in a source:dest pair.
|
484
|
-
def probably_dest_dir?(path)
|
485
|
-
return false unless path
|
486
|
-
return false if colon_path?(path)
|
487
|
-
return ::Sass::Util.glob(File.join(path, "*.s[ca]ss")).empty?
|
488
|
-
end
|
489
|
-
end
|
490
|
-
|
491
|
-
class Scss < Sass
|
492
|
-
# @param args [Array<String>] The command-line arguments
|
493
|
-
def initialize(args)
|
494
|
-
super
|
495
|
-
@default_syntax = :scss
|
496
|
-
end
|
497
|
-
end
|
498
|
-
|
499
|
-
# The `sass-convert` executable.
|
500
|
-
class SassConvert < Generic
|
501
|
-
# @param args [Array<String>] The command-line arguments
|
502
|
-
def initialize(args)
|
503
|
-
super
|
504
|
-
require 'sass'
|
505
|
-
@options[:for_tree] = {}
|
506
|
-
@options[:for_engine] = {:cache => false, :read_cache => true}
|
507
|
-
end
|
508
|
-
|
509
|
-
# Tells optparse how to parse the arguments.
|
510
|
-
#
|
511
|
-
# @param opts [OptionParser]
|
512
|
-
def set_opts(opts)
|
513
|
-
opts.banner = <<END
|
514
|
-
Usage: sass-convert [options] [INPUT] [OUTPUT]
|
515
|
-
|
516
|
-
Description:
|
517
|
-
Converts between CSS, Sass, and SCSS files.
|
518
|
-
E.g. converts from SCSS to Sass,
|
519
|
-
or converts from CSS to SCSS (adding appropriate nesting).
|
520
|
-
|
521
|
-
Options:
|
522
|
-
END
|
523
|
-
|
524
|
-
opts.on('-F', '--from FORMAT',
|
525
|
-
'The format to convert from. Can be css, scss, sass.',
|
526
|
-
'By default, this is inferred from the input filename.',
|
527
|
-
'If there is none, defaults to css.') do |name|
|
528
|
-
@options[:from] = name.downcase.to_sym
|
529
|
-
raise "sass-convert no longer supports LessCSS." if @options[:from] == :less
|
530
|
-
unless [:css, :scss, :sass].include?(@options[:from])
|
531
|
-
raise "Unknown format for sass-convert --from: #{name}"
|
532
|
-
end
|
533
|
-
end
|
534
|
-
|
535
|
-
opts.on('-T', '--to FORMAT',
|
536
|
-
'The format to convert to. Can be scss or sass.',
|
537
|
-
'By default, this is inferred from the output filename.',
|
538
|
-
'If there is none, defaults to sass.') do |name|
|
539
|
-
@options[:to] = name.downcase.to_sym
|
540
|
-
unless [:scss, :sass].include?(@options[:to])
|
541
|
-
raise "Unknown format for sass-convert --to: #{name}"
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
|
-
opts.on('-R', '--recursive',
|
546
|
-
'Convert all the files in a directory. Requires --from and --to.') do
|
547
|
-
@options[:recursive] = true
|
548
|
-
end
|
549
|
-
|
550
|
-
opts.on('-i', '--in-place',
|
551
|
-
'Convert a file to its own syntax.',
|
552
|
-
'This can be used to update some deprecated syntax.') do
|
553
|
-
@options[:in_place] = true
|
554
|
-
end
|
555
|
-
|
556
|
-
opts.on('--dasherize', 'Convert underscores to dashes') do
|
557
|
-
@options[:for_tree][:dasherize] = true
|
558
|
-
end
|
559
|
-
|
560
|
-
opts.on('--indent NUM',
|
561
|
-
'How many spaces to use for each level of indentation. Defaults to 2.',
|
562
|
-
'"t" means use hard tabs.') do |indent|
|
563
|
-
|
564
|
-
if indent == 't'
|
565
|
-
@options[:for_tree][:indent] = "\t"
|
566
|
-
else
|
567
|
-
@options[:for_tree][:indent] = " " * indent.to_i
|
568
|
-
end
|
569
|
-
end
|
570
|
-
|
571
|
-
opts.on('--old', 'Output the old-style ":prop val" property syntax.',
|
572
|
-
'Only meaningful when generating Sass.') do
|
573
|
-
@options[:for_tree][:old] = true
|
574
|
-
end
|
575
|
-
|
576
|
-
opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
|
577
|
-
@options[:for_engine][:read_cache] = false
|
578
|
-
end
|
579
|
-
|
580
|
-
unless ::Sass::Util.ruby1_8?
|
581
|
-
opts.on('-E encoding', 'Specify the default encoding for Sass and CSS files.') do |encoding|
|
582
|
-
Encoding.default_external = encoding
|
583
|
-
end
|
584
|
-
end
|
585
|
-
|
586
|
-
super
|
587
|
-
end
|
588
|
-
|
589
|
-
# Processes the options set by the command-line arguments,
|
590
|
-
# and runs the CSS compiler appropriately.
|
591
|
-
def process_result
|
592
|
-
require 'sass'
|
593
|
-
|
594
|
-
if @options[:recursive]
|
595
|
-
process_directory
|
596
|
-
return
|
597
|
-
end
|
598
|
-
|
599
|
-
super
|
600
|
-
input = @options[:input]
|
601
|
-
raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)" if File.directory?(input)
|
602
|
-
output = @options[:output]
|
603
|
-
output = input if @options[:in_place]
|
604
|
-
process_file(input, output)
|
605
|
-
end
|
606
|
-
|
607
|
-
private
|
608
|
-
|
609
|
-
def process_directory
|
610
|
-
unless input = @options[:input] = @args.shift
|
611
|
-
raise "Error: directory required when using --recursive."
|
612
|
-
end
|
613
|
-
|
614
|
-
output = @options[:output] = @args.shift
|
615
|
-
raise "Error: --from required when using --recursive." unless @options[:from]
|
616
|
-
raise "Error: --to required when using --recursive." unless @options[:to]
|
617
|
-
raise "Error: '#{@options[:input]}' is not a directory" unless File.directory?(@options[:input])
|
618
|
-
if @options[:output] && File.exists?(@options[:output]) && !File.directory?(@options[:output])
|
619
|
-
raise "Error: '#{@options[:output]}' is not a directory"
|
620
|
-
end
|
621
|
-
@options[:output] ||= @options[:input]
|
622
|
-
|
623
|
-
if @options[:to] == @options[:from] && !@options[:in_place]
|
624
|
-
fmt = @options[:from]
|
625
|
-
raise "Error: converting from #{fmt} to #{fmt} without --in-place"
|
626
|
-
end
|
627
|
-
|
628
|
-
ext = @options[:from]
|
629
|
-
::Sass::Util.glob("#{@options[:input]}/**/*.#{ext}") do |f|
|
630
|
-
output =
|
631
|
-
if @options[:in_place]
|
632
|
-
f
|
633
|
-
elsif @options[:output]
|
634
|
-
output_name = f.gsub(/\.(c|sa|sc|le)ss$/, ".#{@options[:to]}")
|
635
|
-
output_name[0...@options[:input].size] = @options[:output]
|
636
|
-
output_name
|
637
|
-
else
|
638
|
-
f.gsub(/\.(c|sa|sc|le)ss$/, ".#{@options[:to]}")
|
639
|
-
end
|
640
|
-
|
641
|
-
unless File.directory?(File.dirname(output))
|
642
|
-
puts_action :directory, :green, File.dirname(output)
|
643
|
-
FileUtils.mkdir_p(File.dirname(output))
|
644
|
-
end
|
645
|
-
puts_action :convert, :green, f
|
646
|
-
if File.exists?(output)
|
647
|
-
puts_action :overwrite, :yellow, output
|
648
|
-
else
|
649
|
-
puts_action :create, :green, output
|
650
|
-
end
|
651
|
-
|
652
|
-
input = open_file(f)
|
653
|
-
process_file(input, output)
|
654
|
-
end
|
655
|
-
end
|
656
|
-
|
657
|
-
def process_file(input, output)
|
658
|
-
if input.is_a?(File)
|
659
|
-
@options[:from] ||=
|
660
|
-
case input.path
|
661
|
-
when /\.scss$/; :scss
|
662
|
-
when /\.sass$/; :sass
|
663
|
-
when /\.less$/; raise "sass-convert no longer supports LessCSS."
|
664
|
-
when /\.css$/; :css
|
665
|
-
end
|
666
|
-
elsif @options[:in_place]
|
667
|
-
raise "Error: the --in-place option requires a filename."
|
668
|
-
end
|
669
|
-
|
670
|
-
if output.is_a?(File)
|
671
|
-
@options[:to] ||=
|
672
|
-
case output.path
|
673
|
-
when /\.scss$/; :scss
|
674
|
-
when /\.sass$/; :sass
|
675
|
-
end
|
676
|
-
end
|
677
|
-
|
678
|
-
@options[:from] ||= :css
|
679
|
-
@options[:to] ||= :sass
|
680
|
-
@options[:for_engine][:syntax] = @options[:from]
|
681
|
-
|
682
|
-
out =
|
683
|
-
::Sass::Util.silence_sass_warnings do
|
684
|
-
if @options[:from] == :css
|
685
|
-
require 'sass/css'
|
686
|
-
::Sass::CSS.new(input.read, @options[:for_tree]).render(@options[:to])
|
687
|
-
else
|
688
|
-
if input.is_a?(File)
|
689
|
-
::Sass::Engine.for_file(input.path, @options[:for_engine])
|
690
|
-
else
|
691
|
-
::Sass::Engine.new(input.read, @options[:for_engine])
|
692
|
-
end.to_tree.send("to_#{@options[:to]}", @options[:for_tree])
|
693
|
-
end
|
694
|
-
end
|
695
|
-
|
696
|
-
output = input.path if @options[:in_place]
|
697
|
-
write_output(out, output)
|
698
|
-
rescue ::Sass::SyntaxError => e
|
699
|
-
raise e if @options[:trace]
|
700
|
-
file = " of #{e.sass_filename}" if e.sass_filename
|
701
|
-
raise "Error on line #{e.sass_line}#{file}: #{e.message}\n Use --trace for backtrace"
|
702
|
-
rescue LoadError => err
|
703
|
-
handle_load_error(err)
|
704
|
-
end
|
705
|
-
end
|
706
4
|
end
|
707
5
|
end
|
6
|
+
|
7
|
+
require 'sass/exec/base'
|
8
|
+
require 'sass/exec/sass_scss'
|
9
|
+
require 'sass/exec/sass_convert'
|