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

The `sass` executable.

### Methods

new process_result set_opts

### Public Class methods

new(args)

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

[Source]

         # File lib/haml/exec.rb, line 272
    272:       def initialize(args)
    273:         super
    274:         @name = "Sass"
    275:         @options[:for_engine][:load_paths] = ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
    276:       end

### Protected Instance methods

process_result()

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

[Source]

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

set_opts(opts)

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

         # File lib/haml/exec.rb, line 283
    283:       def set_opts(opts)
    284:         super
    285:
    286:         opts.on('--scss',
    287:                 'Use the CSS-superset SCSS syntax.') do
    288:           @options[:for_engine][:syntax] = :scss
    289:         end
    290:         opts.on('--watch', 'Watch files or directories for changes.',
    291:                            'The location of the generated CSS can be set using a colon:',
    292:                            '  sass --watch input.sass:output.css',
    293:                            '  sass --watch input-dir:output-dir') do
    294:           @options[:watch] = true
    295:         end
    296:         opts.on('--update', 'Compile files or directories to CSS.',
    297:                             'Locations are set like --watch.') do
    298:           @options[:update] = true
    299:         end
    300:         opts.on('-t', '--style NAME',
    301:                 'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
    302:           @options[:for_engine][:style] = name.to_sym
    303:         end
    304:         opts.on('-q', '--quiet', 'Silence warnings during compilation.') do
    305:           @options[:for_engine][:quiet] = true
    306:         end
    307:         opts.on('-g', '--debug-info',
    308:                 'Emit extra information in the generated CSS that can be used by the FireSass Firebug plugin.') do
    309:           @options[:for_engine][:debug_info] = true
    310:         end
    311:         opts.on('-l', '--line-numbers', '--line-comments',
    312:                 'Emit comments in the generated CSS indicating the corresponding sass line.') do
    313:           @options[:for_engine][:line_numbers] = true
    314:         end
    315:         opts.on('-i', '--interactive',
    316:                 'Run an interactive SassScript shell.') do
    317:           @options[:interactive] = true
    318:         end
    319:         opts.on('-I', '--load-path PATH', 'Add a sass import path.') do |path|
    320:           @options[:for_engine][:load_paths] << path
    321:         end
    322:         opts.on('--cache-location PATH', 'The path to put cached Sass files. Defaults to .sass-cache.') do |loc|
    323:           @options[:for_engine][:cache_location] = loc
    324:         end
    325:         opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
    326:           @options[:for_engine][:cache] = false
    327:         end
    328:
    329:         unless ::Haml::Util.ruby1_8?
    330:           opts.on('-E encoding', 'Specify the default encoding for Sass files.') do |encoding|
    331:             Encoding.default_external = encoding
    332:           end
    333:         end
    334:       end

[Validate]