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