Class Haml::Exec::Sass
In: lib/haml/exec.rb
Parent: HamlSass

The `sass` executable.

Methods

Public Class methods

@param args [Array<String>] The command-line arguments

[Source]

     # 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

Protected Instance methods

Processes the options set by the command-line arguments, and runs the Sass compiler appropriately.

[Source]

     # File lib/haml/exec.rb, line 340
340:       def process_result
341:         if !@options[:update] && !@options[:watch] &&
342:             @args.first && colon_path?(@args.first)
343:           if @args.size == 1
344:             @args = split_colon_path(@args.first)
345:           else
346:             @options[:update] = true
347:           end
348:         end
349: 
350:         return interactive if @options[:interactive]
351:         return watch_or_update if @options[:watch] || @options[:update]
352:         super
353: 
354:         begin
355:           input = @options[:input]
356:           output = @options[:output]
357: 
358:           @options[:syntax] ||= :scss if input.is_a?(File) && input.path =~ /\.scss$/
359:           tree =
360:             if input.is_a?(File) && !@options[:check_syntax]
361:               ::Sass::Files.tree_for(input.path, @options[:for_engine])
362:             else
363:               # We don't need to do any special handling of @options[:check_syntax] here,
364:               # because the Sass syntax checking happens alongside evaluation
365:               # and evaluation doesn't actually evaluate any code anyway.
366:               ::Sass::Engine.new(input.read(), @options[:for_engine]).to_tree
367:             end
368: 
369:           input.close() if input.is_a?(File)
370: 
371:           output.write(tree.render)
372:           output.close() if output.is_a? File
373:         rescue ::Sass::SyntaxError => e
374:           raise e if @options[:trace]
375:           raise e.sass_backtrace_str("standard input")
376:         end
377:       end

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

     # 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('-r', '--require LIB', 'Require a Ruby library before running Sass.') do |lib|
322:           require lib
323:         end
324:         opts.on('--cache-location PATH', 'The path to put cached Sass files. Defaults to .sass-cache.') do |loc|
325:           @options[:for_engine][:cache_location] = loc
326:         end
327:         opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
328:           @options[:for_engine][:cache] = false
329:         end
330: 
331:         unless ::Haml::Util.ruby1_8?
332:           opts.on('-E encoding', 'Specify the default encoding for Sass files.') do |encoding|
333:             Encoding.default_external = encoding
334:           end
335:         end
336:       end

[Validate]