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

Tells optparse how to parse the arguments.

@param opts [OptionParser]

[Source]

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

[Validate]