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.
Files changed (147) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +13 -0
  3. data/AGENTS.md +534 -0
  4. data/CODE_OF_CONDUCT.md +10 -0
  5. data/CONTRIBUTING.md +148 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +242 -0
  8. data/VERSION +1 -0
  9. data/VERSION_NAME +1 -0
  10. data/bin/sass +13 -0
  11. data/bin/sass-convert +12 -0
  12. data/bin/scss +13 -0
  13. data/extra/sass-spec-ref.sh +40 -0
  14. data/extra/update_watch.rb +13 -0
  15. data/init.rb +18 -0
  16. data/lib/sass/cache_stores/base.rb +88 -0
  17. data/lib/sass/cache_stores/chain.rb +34 -0
  18. data/lib/sass/cache_stores/filesystem.rb +60 -0
  19. data/lib/sass/cache_stores/memory.rb +46 -0
  20. data/lib/sass/cache_stores/null.rb +25 -0
  21. data/lib/sass/cache_stores.rb +15 -0
  22. data/lib/sass/callbacks.rb +67 -0
  23. data/lib/sass/css.rb +407 -0
  24. data/lib/sass/deprecation.rb +55 -0
  25. data/lib/sass/engine.rb +1236 -0
  26. data/lib/sass/environment.rb +236 -0
  27. data/lib/sass/error.rb +198 -0
  28. data/lib/sass/exec/base.rb +188 -0
  29. data/lib/sass/exec/sass_convert.rb +283 -0
  30. data/lib/sass/exec/sass_scss.rb +436 -0
  31. data/lib/sass/exec.rb +9 -0
  32. data/lib/sass/features.rb +48 -0
  33. data/lib/sass/importers/base.rb +182 -0
  34. data/lib/sass/importers/deprecated_path.rb +51 -0
  35. data/lib/sass/importers/filesystem.rb +221 -0
  36. data/lib/sass/importers.rb +23 -0
  37. data/lib/sass/logger/base.rb +47 -0
  38. data/lib/sass/logger/delayed.rb +50 -0
  39. data/lib/sass/logger/log_level.rb +45 -0
  40. data/lib/sass/logger.rb +17 -0
  41. data/lib/sass/media.rb +210 -0
  42. data/lib/sass/plugin/compiler.rb +552 -0
  43. data/lib/sass/plugin/configuration.rb +134 -0
  44. data/lib/sass/plugin/generic.rb +15 -0
  45. data/lib/sass/plugin/merb.rb +48 -0
  46. data/lib/sass/plugin/rack.rb +60 -0
  47. data/lib/sass/plugin/rails.rb +47 -0
  48. data/lib/sass/plugin/staleness_checker.rb +199 -0
  49. data/lib/sass/plugin.rb +134 -0
  50. data/lib/sass/railtie.rb +10 -0
  51. data/lib/sass/repl.rb +57 -0
  52. data/lib/sass/root.rb +7 -0
  53. data/lib/sass/script/css_lexer.rb +33 -0
  54. data/lib/sass/script/css_parser.rb +36 -0
  55. data/lib/sass/script/functions.rb +3103 -0
  56. data/lib/sass/script/lexer.rb +518 -0
  57. data/lib/sass/script/parser.rb +1164 -0
  58. data/lib/sass/script/tree/funcall.rb +314 -0
  59. data/lib/sass/script/tree/interpolation.rb +220 -0
  60. data/lib/sass/script/tree/list_literal.rb +119 -0
  61. data/lib/sass/script/tree/literal.rb +49 -0
  62. data/lib/sass/script/tree/map_literal.rb +64 -0
  63. data/lib/sass/script/tree/node.rb +119 -0
  64. data/lib/sass/script/tree/operation.rb +149 -0
  65. data/lib/sass/script/tree/selector.rb +26 -0
  66. data/lib/sass/script/tree/string_interpolation.rb +125 -0
  67. data/lib/sass/script/tree/unary_operation.rb +69 -0
  68. data/lib/sass/script/tree/variable.rb +57 -0
  69. data/lib/sass/script/tree.rb +16 -0
  70. data/lib/sass/script/value/arg_list.rb +36 -0
  71. data/lib/sass/script/value/base.rb +258 -0
  72. data/lib/sass/script/value/bool.rb +35 -0
  73. data/lib/sass/script/value/callable.rb +25 -0
  74. data/lib/sass/script/value/color.rb +704 -0
  75. data/lib/sass/script/value/function.rb +19 -0
  76. data/lib/sass/script/value/helpers.rb +298 -0
  77. data/lib/sass/script/value/list.rb +135 -0
  78. data/lib/sass/script/value/map.rb +70 -0
  79. data/lib/sass/script/value/null.rb +44 -0
  80. data/lib/sass/script/value/number.rb +564 -0
  81. data/lib/sass/script/value/string.rb +138 -0
  82. data/lib/sass/script/value.rb +13 -0
  83. data/lib/sass/script.rb +66 -0
  84. data/lib/sass/scss/css_parser.rb +61 -0
  85. data/lib/sass/scss/parser.rb +1343 -0
  86. data/lib/sass/scss/rx.rb +134 -0
  87. data/lib/sass/scss/static_parser.rb +351 -0
  88. data/lib/sass/scss.rb +14 -0
  89. data/lib/sass/selector/abstract_sequence.rb +112 -0
  90. data/lib/sass/selector/comma_sequence.rb +195 -0
  91. data/lib/sass/selector/pseudo.rb +291 -0
  92. data/lib/sass/selector/sequence.rb +661 -0
  93. data/lib/sass/selector/simple.rb +124 -0
  94. data/lib/sass/selector/simple_sequence.rb +348 -0
  95. data/lib/sass/selector.rb +327 -0
  96. data/lib/sass/shared.rb +76 -0
  97. data/lib/sass/source/map.rb +209 -0
  98. data/lib/sass/source/position.rb +39 -0
  99. data/lib/sass/source/range.rb +41 -0
  100. data/lib/sass/stack.rb +140 -0
  101. data/lib/sass/supports.rb +225 -0
  102. data/lib/sass/tree/at_root_node.rb +83 -0
  103. data/lib/sass/tree/charset_node.rb +22 -0
  104. data/lib/sass/tree/comment_node.rb +82 -0
  105. data/lib/sass/tree/content_node.rb +9 -0
  106. data/lib/sass/tree/css_import_node.rb +68 -0
  107. data/lib/sass/tree/debug_node.rb +18 -0
  108. data/lib/sass/tree/directive_node.rb +59 -0
  109. data/lib/sass/tree/each_node.rb +24 -0
  110. data/lib/sass/tree/error_node.rb +18 -0
  111. data/lib/sass/tree/extend_node.rb +43 -0
  112. data/lib/sass/tree/for_node.rb +36 -0
  113. data/lib/sass/tree/function_node.rb +44 -0
  114. data/lib/sass/tree/if_node.rb +52 -0
  115. data/lib/sass/tree/import_node.rb +75 -0
  116. data/lib/sass/tree/keyframe_rule_node.rb +15 -0
  117. data/lib/sass/tree/media_node.rb +48 -0
  118. data/lib/sass/tree/mixin_def_node.rb +38 -0
  119. data/lib/sass/tree/mixin_node.rb +52 -0
  120. data/lib/sass/tree/node.rb +240 -0
  121. data/lib/sass/tree/prop_node.rb +162 -0
  122. data/lib/sass/tree/return_node.rb +19 -0
  123. data/lib/sass/tree/root_node.rb +44 -0
  124. data/lib/sass/tree/rule_node.rb +153 -0
  125. data/lib/sass/tree/supports_node.rb +38 -0
  126. data/lib/sass/tree/trace_node.rb +33 -0
  127. data/lib/sass/tree/variable_node.rb +36 -0
  128. data/lib/sass/tree/visitors/base.rb +72 -0
  129. data/lib/sass/tree/visitors/check_nesting.rb +173 -0
  130. data/lib/sass/tree/visitors/convert.rb +350 -0
  131. data/lib/sass/tree/visitors/cssize.rb +362 -0
  132. data/lib/sass/tree/visitors/deep_copy.rb +107 -0
  133. data/lib/sass/tree/visitors/extend.rb +64 -0
  134. data/lib/sass/tree/visitors/perform.rb +572 -0
  135. data/lib/sass/tree/visitors/set_options.rb +139 -0
  136. data/lib/sass/tree/visitors/to_css.rb +440 -0
  137. data/lib/sass/tree/warn_node.rb +18 -0
  138. data/lib/sass/tree/while_node.rb +18 -0
  139. data/lib/sass/util/multibyte_string_scanner.rb +151 -0
  140. data/lib/sass/util/normalized_map.rb +122 -0
  141. data/lib/sass/util/subset_map.rb +109 -0
  142. data/lib/sass/util/test.rb +9 -0
  143. data/lib/sass/util.rb +1137 -0
  144. data/lib/sass/version.rb +120 -0
  145. data/lib/sass.rb +102 -0
  146. data/rails/init.rb +1 -0
  147. 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