sass4 4.0.0
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/.yardopts +13 -0
- data/AGENTS.md +534 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/CONTRIBUTING.md +148 -0
- data/MIT-LICENSE +20 -0
- data/README.md +242 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/sass +13 -0
- data/bin/sass-convert +12 -0
- data/bin/scss +13 -0
- data/extra/sass-spec-ref.sh +40 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +18 -0
- data/lib/sass/cache_stores/base.rb +88 -0
- data/lib/sass/cache_stores/chain.rb +34 -0
- data/lib/sass/cache_stores/filesystem.rb +60 -0
- data/lib/sass/cache_stores/memory.rb +46 -0
- data/lib/sass/cache_stores/null.rb +25 -0
- data/lib/sass/cache_stores.rb +15 -0
- data/lib/sass/callbacks.rb +67 -0
- data/lib/sass/css.rb +407 -0
- data/lib/sass/deprecation.rb +55 -0
- data/lib/sass/engine.rb +1236 -0
- data/lib/sass/environment.rb +236 -0
- data/lib/sass/error.rb +198 -0
- data/lib/sass/exec/base.rb +188 -0
- data/lib/sass/exec/sass_convert.rb +283 -0
- data/lib/sass/exec/sass_scss.rb +436 -0
- data/lib/sass/exec.rb +9 -0
- data/lib/sass/features.rb +48 -0
- data/lib/sass/importers/base.rb +182 -0
- data/lib/sass/importers/deprecated_path.rb +51 -0
- data/lib/sass/importers/filesystem.rb +221 -0
- data/lib/sass/importers.rb +23 -0
- data/lib/sass/logger/base.rb +47 -0
- data/lib/sass/logger/delayed.rb +50 -0
- data/lib/sass/logger/log_level.rb +45 -0
- data/lib/sass/logger.rb +17 -0
- data/lib/sass/media.rb +210 -0
- data/lib/sass/plugin/compiler.rb +552 -0
- data/lib/sass/plugin/configuration.rb +134 -0
- data/lib/sass/plugin/generic.rb +15 -0
- data/lib/sass/plugin/merb.rb +48 -0
- data/lib/sass/plugin/rack.rb +60 -0
- data/lib/sass/plugin/rails.rb +47 -0
- data/lib/sass/plugin/staleness_checker.rb +199 -0
- data/lib/sass/plugin.rb +134 -0
- data/lib/sass/railtie.rb +10 -0
- data/lib/sass/repl.rb +57 -0
- data/lib/sass/root.rb +7 -0
- data/lib/sass/script/css_lexer.rb +33 -0
- data/lib/sass/script/css_parser.rb +36 -0
- data/lib/sass/script/functions.rb +3103 -0
- data/lib/sass/script/lexer.rb +518 -0
- data/lib/sass/script/parser.rb +1164 -0
- data/lib/sass/script/tree/funcall.rb +314 -0
- data/lib/sass/script/tree/interpolation.rb +220 -0
- data/lib/sass/script/tree/list_literal.rb +119 -0
- data/lib/sass/script/tree/literal.rb +49 -0
- data/lib/sass/script/tree/map_literal.rb +64 -0
- data/lib/sass/script/tree/node.rb +119 -0
- data/lib/sass/script/tree/operation.rb +149 -0
- data/lib/sass/script/tree/selector.rb +26 -0
- data/lib/sass/script/tree/string_interpolation.rb +125 -0
- data/lib/sass/script/tree/unary_operation.rb +69 -0
- data/lib/sass/script/tree/variable.rb +57 -0
- data/lib/sass/script/tree.rb +16 -0
- data/lib/sass/script/value/arg_list.rb +36 -0
- data/lib/sass/script/value/base.rb +258 -0
- data/lib/sass/script/value/bool.rb +35 -0
- data/lib/sass/script/value/callable.rb +25 -0
- data/lib/sass/script/value/color.rb +704 -0
- data/lib/sass/script/value/function.rb +19 -0
- data/lib/sass/script/value/helpers.rb +298 -0
- data/lib/sass/script/value/list.rb +135 -0
- data/lib/sass/script/value/map.rb +70 -0
- data/lib/sass/script/value/null.rb +44 -0
- data/lib/sass/script/value/number.rb +564 -0
- data/lib/sass/script/value/string.rb +138 -0
- data/lib/sass/script/value.rb +13 -0
- data/lib/sass/script.rb +66 -0
- data/lib/sass/scss/css_parser.rb +61 -0
- data/lib/sass/scss/parser.rb +1343 -0
- data/lib/sass/scss/rx.rb +134 -0
- data/lib/sass/scss/static_parser.rb +351 -0
- data/lib/sass/scss.rb +14 -0
- data/lib/sass/selector/abstract_sequence.rb +112 -0
- data/lib/sass/selector/comma_sequence.rb +195 -0
- data/lib/sass/selector/pseudo.rb +291 -0
- data/lib/sass/selector/sequence.rb +661 -0
- data/lib/sass/selector/simple.rb +124 -0
- data/lib/sass/selector/simple_sequence.rb +348 -0
- data/lib/sass/selector.rb +327 -0
- data/lib/sass/shared.rb +76 -0
- data/lib/sass/source/map.rb +209 -0
- data/lib/sass/source/position.rb +39 -0
- data/lib/sass/source/range.rb +41 -0
- data/lib/sass/stack.rb +140 -0
- data/lib/sass/supports.rb +225 -0
- data/lib/sass/tree/at_root_node.rb +83 -0
- data/lib/sass/tree/charset_node.rb +22 -0
- data/lib/sass/tree/comment_node.rb +82 -0
- data/lib/sass/tree/content_node.rb +9 -0
- data/lib/sass/tree/css_import_node.rb +68 -0
- data/lib/sass/tree/debug_node.rb +18 -0
- data/lib/sass/tree/directive_node.rb +59 -0
- data/lib/sass/tree/each_node.rb +24 -0
- data/lib/sass/tree/error_node.rb +18 -0
- data/lib/sass/tree/extend_node.rb +43 -0
- data/lib/sass/tree/for_node.rb +36 -0
- data/lib/sass/tree/function_node.rb +44 -0
- data/lib/sass/tree/if_node.rb +52 -0
- data/lib/sass/tree/import_node.rb +75 -0
- data/lib/sass/tree/keyframe_rule_node.rb +15 -0
- data/lib/sass/tree/media_node.rb +48 -0
- data/lib/sass/tree/mixin_def_node.rb +38 -0
- data/lib/sass/tree/mixin_node.rb +52 -0
- data/lib/sass/tree/node.rb +240 -0
- data/lib/sass/tree/prop_node.rb +162 -0
- data/lib/sass/tree/return_node.rb +19 -0
- data/lib/sass/tree/root_node.rb +44 -0
- data/lib/sass/tree/rule_node.rb +153 -0
- data/lib/sass/tree/supports_node.rb +38 -0
- data/lib/sass/tree/trace_node.rb +33 -0
- data/lib/sass/tree/variable_node.rb +36 -0
- data/lib/sass/tree/visitors/base.rb +72 -0
- data/lib/sass/tree/visitors/check_nesting.rb +173 -0
- data/lib/sass/tree/visitors/convert.rb +350 -0
- data/lib/sass/tree/visitors/cssize.rb +362 -0
- data/lib/sass/tree/visitors/deep_copy.rb +107 -0
- data/lib/sass/tree/visitors/extend.rb +64 -0
- data/lib/sass/tree/visitors/perform.rb +572 -0
- data/lib/sass/tree/visitors/set_options.rb +139 -0
- data/lib/sass/tree/visitors/to_css.rb +440 -0
- data/lib/sass/tree/warn_node.rb +18 -0
- data/lib/sass/tree/while_node.rb +18 -0
- data/lib/sass/util/multibyte_string_scanner.rb +151 -0
- data/lib/sass/util/normalized_map.rb +122 -0
- data/lib/sass/util/subset_map.rb +109 -0
- data/lib/sass/util/test.rb +9 -0
- data/lib/sass/util.rb +1137 -0
- data/lib/sass/version.rb +120 -0
- data/lib/sass.rb +102 -0
- data/rails/init.rb +1 -0
- metadata +283 -0
@@ -0,0 +1,283 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Sass::Exec
|
5
|
+
# The `sass-convert` executable.
|
6
|
+
class SassConvert < Base
|
7
|
+
# @param args [Array<String>] The command-line arguments
|
8
|
+
def initialize(args)
|
9
|
+
super
|
10
|
+
require 'sass'
|
11
|
+
@options[:for_tree] = {}
|
12
|
+
@options[:for_engine] = {:cache => false, :read_cache => true}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Tells optparse how to parse the arguments.
|
16
|
+
#
|
17
|
+
# @param opts [OptionParser]
|
18
|
+
def set_opts(opts)
|
19
|
+
opts.banner = <<END
|
20
|
+
Usage: sass-convert [options] [INPUT] [OUTPUT]
|
21
|
+
|
22
|
+
Description:
|
23
|
+
Converts between CSS, indented syntax, and SCSS files. For example,
|
24
|
+
this can convert from the indented syntax to SCSS, or from CSS to
|
25
|
+
SCSS (adding appropriate nesting).
|
26
|
+
END
|
27
|
+
|
28
|
+
common_options(opts)
|
29
|
+
style(opts)
|
30
|
+
input_and_output(opts)
|
31
|
+
miscellaneous(opts)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Processes the options set by the command-line arguments,
|
35
|
+
# and runs the CSS compiler appropriately.
|
36
|
+
def process_result
|
37
|
+
require 'sass'
|
38
|
+
|
39
|
+
if @options[:recursive]
|
40
|
+
process_directory
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
super
|
45
|
+
input = @options[:input]
|
46
|
+
if File.directory?(input)
|
47
|
+
raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)"
|
48
|
+
end
|
49
|
+
output = @options[:output]
|
50
|
+
output = input if @options[:in_place]
|
51
|
+
process_file(input, output)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def common_options(opts)
|
57
|
+
opts.separator ''
|
58
|
+
opts.separator 'Common Options:'
|
59
|
+
|
60
|
+
opts.on('-F', '--from FORMAT',
|
61
|
+
'The format to convert from. Can be css, scss, sass.',
|
62
|
+
'By default, this is inferred from the input filename.',
|
63
|
+
'If there is none, defaults to css.') do |name|
|
64
|
+
@options[:from] = name.downcase.to_sym
|
65
|
+
raise "sass-convert no longer supports LessCSS." if @options[:from] == :less
|
66
|
+
unless [:css, :scss, :sass].include?(@options[:from])
|
67
|
+
raise "Unknown format for sass-convert --from: #{name}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on('-T', '--to FORMAT',
|
72
|
+
'The format to convert to. Can be scss or sass.',
|
73
|
+
'By default, this is inferred from the output filename.',
|
74
|
+
'If there is none, defaults to sass.') do |name|
|
75
|
+
@options[:to] = name.downcase.to_sym
|
76
|
+
unless [:scss, :sass].include?(@options[:to])
|
77
|
+
raise "Unknown format for sass-convert --to: #{name}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on('-i', '--in-place',
|
82
|
+
'Convert a file to its own syntax.',
|
83
|
+
'This can be used to update some deprecated syntax.') do
|
84
|
+
@options[:in_place] = true
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.on('-R', '--recursive',
|
88
|
+
'Convert all the files in a directory. Requires --from and --to.') do
|
89
|
+
@options[:recursive] = true
|
90
|
+
end
|
91
|
+
|
92
|
+
opts.on("-?", "-h", "--help", "Show this help message.") do
|
93
|
+
puts opts
|
94
|
+
exit
|
95
|
+
end
|
96
|
+
|
97
|
+
opts.on("-v", "--version", "Print the Sass version.") do
|
98
|
+
puts("Sass #{Sass.version[:string]}")
|
99
|
+
exit
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def style(opts)
|
104
|
+
opts.separator ''
|
105
|
+
opts.separator 'Style:'
|
106
|
+
|
107
|
+
opts.on('--dasherize', 'Convert underscores to dashes.') do
|
108
|
+
@options[:for_tree][:dasherize] = true
|
109
|
+
end
|
110
|
+
|
111
|
+
opts.on(
|
112
|
+
'--indent NUM',
|
113
|
+
'How many spaces to use for each level of indentation. Defaults to 2.',
|
114
|
+
'"t" means use hard tabs.'
|
115
|
+
) do |indent|
|
116
|
+
if indent == 't'
|
117
|
+
@options[:for_tree][:indent] = "\t"
|
118
|
+
else
|
119
|
+
@options[:for_tree][:indent] = " " * indent.to_i
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
opts.on('--old', 'Output the old-style ":prop val" property syntax.',
|
124
|
+
'Only meaningful when generating Sass.') do
|
125
|
+
@options[:for_tree][:old] = true
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def input_and_output(opts)
|
130
|
+
opts.separator ''
|
131
|
+
opts.separator 'Input and Output:'
|
132
|
+
|
133
|
+
opts.on('-s', '--stdin', :NONE,
|
134
|
+
'Read input from standard input instead of an input file.',
|
135
|
+
'This is the default if no input file is specified. Requires --from.') do
|
136
|
+
@options[:input] = $stdin
|
137
|
+
end
|
138
|
+
|
139
|
+
encoding_option(opts)
|
140
|
+
|
141
|
+
opts.on('--unix-newlines', 'Use Unix-style newlines in written files.',
|
142
|
+
('Always true on Unix.' unless Sass::Util.windows?)) do
|
143
|
+
@options[:unix_newlines] = true if Sass::Util.windows?
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def miscellaneous(opts)
|
148
|
+
opts.separator ''
|
149
|
+
opts.separator 'Miscellaneous:'
|
150
|
+
|
151
|
+
opts.on('--cache-location PATH',
|
152
|
+
'The path to save parsed Sass files. Defaults to .sass-cache.') do |loc|
|
153
|
+
@options[:for_engine][:cache_location] = loc
|
154
|
+
end
|
155
|
+
|
156
|
+
opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
|
157
|
+
@options[:for_engine][:read_cache] = false
|
158
|
+
end
|
159
|
+
|
160
|
+
opts.on('-q', '--quiet', 'Silence warnings and status messages during conversion.') do |bool|
|
161
|
+
@options[:for_engine][:quiet] = bool
|
162
|
+
end
|
163
|
+
|
164
|
+
opts.on('--trace', :NONE, 'Show a full Ruby stack trace on error') do
|
165
|
+
@options[:trace] = true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def process_directory
|
170
|
+
@options[:input] = @args.shift
|
171
|
+
unless @options[:input]
|
172
|
+
raise "Error: directory required when using --recursive."
|
173
|
+
end
|
174
|
+
|
175
|
+
output = @options[:output] = @args.shift
|
176
|
+
raise "Error: --from required when using --recursive." unless @options[:from]
|
177
|
+
raise "Error: --to required when using --recursive." unless @options[:to]
|
178
|
+
unless File.directory?(@options[:input])
|
179
|
+
raise "Error: '#{@options[:input]}' is not a directory"
|
180
|
+
end
|
181
|
+
if @options[:output] && File.exist?(@options[:output]) &&
|
182
|
+
!File.directory?(@options[:output])
|
183
|
+
raise "Error: '#{@options[:output]}' is not a directory"
|
184
|
+
end
|
185
|
+
@options[:output] ||= @options[:input]
|
186
|
+
|
187
|
+
if @options[:to] == @options[:from] && !@options[:in_place]
|
188
|
+
fmt = @options[:from]
|
189
|
+
raise "Error: converting from #{fmt} to #{fmt} without --in-place"
|
190
|
+
end
|
191
|
+
|
192
|
+
ext = @options[:from]
|
193
|
+
Sass::Util.glob("#{@options[:input]}/**/*.#{ext}") do |f|
|
194
|
+
output =
|
195
|
+
if @options[:in_place]
|
196
|
+
f
|
197
|
+
elsif @options[:output]
|
198
|
+
output_name = f.gsub(/\.(c|sa|sc|le)ss$/, ".#{@options[:to]}")
|
199
|
+
output_name[0...@options[:input].size] = @options[:output]
|
200
|
+
output_name
|
201
|
+
else
|
202
|
+
f.gsub(/\.(c|sa|sc|le)ss$/, ".#{@options[:to]}")
|
203
|
+
end
|
204
|
+
|
205
|
+
unless File.directory?(File.dirname(output))
|
206
|
+
puts_action :directory, :green, File.dirname(output)
|
207
|
+
FileUtils.mkdir_p(File.dirname(output))
|
208
|
+
end
|
209
|
+
puts_action :convert, :green, f
|
210
|
+
if File.exist?(output)
|
211
|
+
puts_action :overwrite, :yellow, output
|
212
|
+
else
|
213
|
+
puts_action :create, :green, output
|
214
|
+
end
|
215
|
+
|
216
|
+
process_file(f, output)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def process_file(input, output)
|
221
|
+
input_path, output_path = path_for(input), path_for(output)
|
222
|
+
if input_path
|
223
|
+
@options[:from] ||=
|
224
|
+
case input_path
|
225
|
+
when /\.scss$/; :scss
|
226
|
+
when /\.sass$/; :sass
|
227
|
+
when /\.less$/; raise "sass-convert no longer supports LessCSS."
|
228
|
+
when /\.css$/; :css
|
229
|
+
end
|
230
|
+
elsif @options[:in_place]
|
231
|
+
raise "Error: the --in-place option requires a filename."
|
232
|
+
end
|
233
|
+
|
234
|
+
if output_path
|
235
|
+
@options[:to] ||=
|
236
|
+
case output_path
|
237
|
+
when /\.scss$/; :scss
|
238
|
+
when /\.sass$/; :sass
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
@options[:from] ||= :css
|
243
|
+
@options[:to] ||= :sass
|
244
|
+
@options[:for_engine][:syntax] = @options[:from]
|
245
|
+
|
246
|
+
out =
|
247
|
+
Sass::Util.silence_sass_warnings do
|
248
|
+
if @options[:from] == :css
|
249
|
+
require 'sass/css'
|
250
|
+
Sass::CSS.new(read(input), @options[:for_tree]).render(@options[:to])
|
251
|
+
else
|
252
|
+
if input_path
|
253
|
+
Sass::Engine.for_file(input_path, @options[:for_engine])
|
254
|
+
else
|
255
|
+
Sass::Engine.new(read(input), @options[:for_engine])
|
256
|
+
end.to_tree.send("to_#{@options[:to]}", @options[:for_tree])
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
output = input_path if @options[:in_place]
|
261
|
+
write_output(out, output)
|
262
|
+
rescue Sass::SyntaxError => e
|
263
|
+
raise e if @options[:trace]
|
264
|
+
file = " of #{e.sass_filename}" if e.sass_filename
|
265
|
+
raise "Error on line #{e.sass_line}#{file}: #{e.message}\n Use --trace for backtrace"
|
266
|
+
rescue LoadError => err
|
267
|
+
handle_load_error(err)
|
268
|
+
end
|
269
|
+
|
270
|
+
def path_for(file)
|
271
|
+
return file.path if file.is_a?(File)
|
272
|
+
return file if file.is_a?(String)
|
273
|
+
end
|
274
|
+
|
275
|
+
def read(file)
|
276
|
+
if file.respond_to?(:read)
|
277
|
+
file.read
|
278
|
+
else
|
279
|
+
open(file, 'rb') {|f| f.read}
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|