| Class | Haml::Exec::Sass |
| In: |
lib/haml/exec.rb
|
| Parent: | HamlSass |
The `sass` executable.
@param args [Array<String>] The command-line arguments
# File lib/haml/exec.rb, line 260
260: def initialize(args)
261: super
262: @name = "Sass"
263: @options[:for_engine][:load_paths] = ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
264: end
Processes the options set by the command-line arguments, and runs the Sass compiler appropriately.
# File lib/haml/exec.rb, line 320
320: def process_result
321: if !@options[:update] && !@options[:watch] &&
322: @args.first && @args.first.include?(':')
323: if @args.size == 1
324: @args = @args.first.split(':', 2)
325: else
326: @options[:update] = true
327: end
328: end
329:
330: return interactive if @options[:interactive]
331: return watch_or_update if @options[:watch] || @options[:update]
332: super
333:
334: begin
335: input = @options[:input]
336: output = @options[:output]
337:
338: @options[:syntax] ||= :scss if input.is_a?(File) && input.path =~ /\.scss$/
339: tree =
340: if input.is_a?(File) && !@options[:check_syntax]
341: ::Sass::Files.tree_for(input.path, @options[:for_engine])
342: else
343: # We don't need to do any special handling of @options[:check_syntax] here,
344: # because the Sass syntax checking happens alongside evaluation
345: # and evaluation doesn't actually evaluate any code anyway.
346: ::Sass::Engine.new(input.read(), @options[:for_engine]).to_tree
347: end
348:
349: input.close() if input.is_a?(File)
350:
351: output.write(tree.render)
352: output.close() if output.is_a? File
353: rescue ::Sass::SyntaxError => e
354: raise e if @options[:trace]
355: raise e.sass_backtrace_str("standard input")
356: end
357: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 271
271: def set_opts(opts)
272: super
273:
274: opts.on('--scss',
275: 'Use the CSS-superset SCSS syntax.') do
276: @options[:for_engine][:syntax] = :scss
277: end
278: opts.on('--watch', 'Watch files or directories for changes.',
279: 'The location of the generated CSS can be set using a colon:',
280: ' sass --watch input.sass:output.css',
281: ' sass --watch input-dir:output-dir') do
282: @options[:watch] = true
283: end
284: opts.on('--update', 'Compile files or directories to CSS.',
285: 'Locations are set like --watch.') do
286: @options[:update] = true
287: end
288: opts.on('-t', '--style NAME',
289: 'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
290: @options[:for_engine][:style] = name.to_sym
291: end
292: opts.on('-q', '--quiet', 'Silence warnings during compilation.') do
293: @options[:for_engine][:quiet] = true
294: end
295: opts.on('-g', '--debug-info',
296: 'Emit extra information in the generated CSS that can be used by the FireSass Firebug plugin.') do
297: @options[:for_engine][:debug_info] = true
298: end
299: opts.on('-l', '--line-numbers', '--line-comments',
300: 'Emit comments in the generated CSS indicating the corresponding sass line.') do
301: @options[:for_engine][:line_numbers] = true
302: end
303: opts.on('-i', '--interactive',
304: 'Run an interactive SassScript shell.') do
305: @options[:interactive] = true
306: end
307: opts.on('-I', '--load-path PATH', 'Add a sass import path.') do |path|
308: @options[:for_engine][:load_paths] << path
309: end
310: opts.on('--cache-location PATH', 'The path to put cached Sass files. Defaults to .sass-cache.') do |loc|
311: @options[:for_engine][:cache_location] = loc
312: end
313: opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
314: @options[:for_engine][:read_cache] = false
315: end
316: end