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 208
208:       def initialize(args)
209:         super
210:         @name = "Sass"
211:         @options[:for_engine][:load_paths] = ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
212:       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 247
247:       def process_result
248:         if @options[:interactive]
249:           require 'sass'
250:           require 'sass/repl'
251:           ::Sass::Repl.new(@options).run
252:           return
253:         end
254: 
255:         super
256: 
257:         begin
258:           input = @options[:input]
259:           output = @options[:output]
260: 
261:           tree =
262:             if input.is_a?(File) && !@options[:check_syntax]
263:               ::Sass::Files.tree_for(input.path, @options[:for_engine])
264:             else
265:               # We don't need to do any special handling of @options[:check_syntax] here,
266:               # because the Sass syntax checking happens alongside evaluation
267:               # and evaluation doesn't actually evaluate any code anyway.
268:               ::Sass::Engine.new(input.read(), @options[:for_engine]).to_tree
269:             end
270: 
271:           input.close() if input.is_a?(File)
272: 
273:           output.write(tree.render)
274:           output.close() if output.is_a? File
275:         rescue ::Sass::SyntaxError => e
276:           raise e if @options[:trace]
277:           raise "Syntax error on line #{get_line e}: #{e.message}"
278:         end
279:       end

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

     # File lib/haml/exec.rb, line 219
219:       def set_opts(opts)
220:         super
221: 
222:         opts.on('-t', '--style NAME',
223:                 'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
224:           @options[:for_engine][:style] = name.to_sym
225:         end
226:         opts.on('-l', '--line-numbers', '--line-comments',
227:                 'Emit comments in the generated CSS indicating the corresponding sass line.') do
228:           @options[:for_engine][:line_numbers] = true
229:         end
230:         opts.on('-i', '--interactive',
231:                 'Run an interactive SassScript shell.') do
232:           @options[:interactive] = true
233:         end
234:         opts.on('-I', '--load-path PATH', 'Add a sass import path.') do |path|
235:           @options[:for_engine][:load_paths] << path
236:         end
237:         opts.on('--cache-location PATH', 'The path to put cached Sass files. Defaults to .sass-cache.') do |loc|
238:           @options[:for_engine][:cache_location] = loc
239:         end
240:         opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
241:           @options[:for_engine][:cache] = false
242:         end
243:       end

[Validate]