| 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 201
201: def initialize(args)
202: super
203: @name = "Sass"
204: @options[:for_engine][:load_paths] = ['.'] + (ENV['SASSPATH'] || '').split(File::PATH_SEPARATOR)
205: end
Processes the options set by the command-line arguments, and runs the Sass compiler appropriately.
# File lib/haml/exec.rb, line 240
240: def process_result
241: if @options[:interactive]
242: require 'sass'
243: require 'sass/repl'
244: ::Sass::Repl.new(@options).run
245: return
246: end
247:
248: super
249: input = @options[:input]
250: output = @options[:output]
251:
252: tree =
253: if input.is_a?(File) && !@options[:check_syntax]
254: ::Sass::Files.tree_for(input.path, @options[:for_engine])
255: else
256: # We don't need to do any special handling of @options[:check_syntax] here,
257: # because the Sass syntax checking happens alongside evaluation
258: # and evaluation doesn't actually evaluate any code anyway.
259: ::Sass::Engine.new(input.read(), @options[:for_engine]).to_tree
260: end
261:
262: input.close() if input.is_a?(File)
263:
264: output.write(tree.render)
265: output.close() if output.is_a? File
266: rescue ::Sass::SyntaxError => e
267: raise e if @options[:trace]
268: raise "Syntax error on line #{get_line e}: #{e.message}"
269: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 212
212: def set_opts(opts)
213: super
214:
215: opts.on('-t', '--style NAME',
216: 'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
217: @options[:for_engine][:style] = name.to_sym
218: end
219: opts.on('-l', '--line-comments',
220: 'Line Comments. Emit comments in the generated CSS indicating the corresponding sass line.') do
221: @options[:for_engine][:line_comments] = true
222: end
223: opts.on('-i', '--interactive',
224: 'Run an interactive SassScript shell.') do
225: @options[:interactive] = true
226: end
227: opts.on('-I', '--load-path PATH', 'Add a sass import path.') do |path|
228: @options[:for_engine][:load_paths] << path
229: end
230: opts.on('--cache-location', 'The path to put cached Sass files. Defaults to .sass-cache.') do |loc|
231: @options[:for_engine][:cache_location] = path
232: end
233: opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
234: @options[:for_engine][:cache] = false
235: end
236: end