In Files

Class Index [+]

Quicksearch

Haml::Exec::Sass

The `sass` executable.

Public Class Methods

new(args) click to toggle source

@param args [Array] The command-line arguments

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

Protected Instance Methods

process_result() click to toggle source

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

     # File lib/haml/exec.rb, line 338
338:       def process_result
339:         if !@options[:update] && !@options[:watch] &&
340:             @args.first && colon_path?(@args.first)
341:           if @args.size == 1
342:             @args = split_colon_path(@args.first)
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) click to toggle source

Tells optparse how to parse the arguments.

@param opts [OptionParser]

     # File lib/haml/exec.rb, line 280
280:       def set_opts(opts)
281:         super
282: 
283:         opts.on('--scss',
284:                 'Use the CSS-superset SCSS syntax.') do
285:           @options[:for_engine][:syntax] = :scss
286:         end
287:         opts.on('--watch', 'Watch files or directories for changes.',
288:                            'The location of the generated CSS can be set using a colon:',
289:                            '  sass --watch input.sass:output.css',
290:                            '  sass --watch input-dir:output-dir') do
291:           @options[:watch] = true
292:         end
293:         opts.on('--update', 'Compile files or directories to CSS.',
294:                             'Locations are set like --watch.') do
295:           @options[:update] = true
296:         end
297:         opts.on('-t', '--style NAME',
298:                 'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
299:           @options[:for_engine][:style] = name.to_sym
300:         end
301:         opts.on('-q', '--quiet', 'Silence warnings during compilation.') do
302:           @options[:for_engine][:quiet] = true
303:         end
304:         opts.on('-g', '--debug-info',
305:                 'Emit extra information in the generated CSS that can be used by the FireSass Firebug plugin.') do
306:           @options[:for_engine][:debug_info] = true
307:         end
308:         opts.on('-l', '--line-numbers', '--line-comments',
309:                 'Emit comments in the generated CSS indicating the corresponding sass line.') do
310:           @options[:for_engine][:line_numbers] = true
311:         end
312:         opts.on('-i', '--interactive',
313:                 'Run an interactive SassScript shell.') do
314:           @options[:interactive] = true
315:         end
316:         opts.on('-I', '--load-path PATH', 'Add a sass import path.') do |path|
317:           @options[:for_engine][:load_paths] << path
318:         end
319:         opts.on('-r', '--require LIB', 'Require a Ruby library before running Sass.') do |lib|
320:           require lib
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

Private Instance Methods

colon_path?(path) click to toggle source
     # File lib/haml/exec.rb, line 440
440:       def colon_path?(path)
441:         !split_colon_path(path)[1].nil?
442:       end
interactive() click to toggle source
     # File lib/haml/exec.rb, line 379
379:       def interactive
380:         require 'sass'
381:         require 'sass/repl'
382:         ::Sass::Repl.new(@options).run
383:       end
probably_dest_dir?(path) click to toggle source

Whether path is likely to be meant as the destination in a source:dest pair.

     # File lib/haml/exec.rb, line 458
458:       def probably_dest_dir?(path)
459:         return false if colon_path?(path)
460:         return Dir.glob(File.join(path, "*.s[ca]ss")).empty?
461:       end
split_colon_path(path) click to toggle source
     # File lib/haml/exec.rb, line 444
444:       def split_colon_path(path)
445:         one, two = path.split(':', 2)
446:         if one && two && ::Haml::Util.windows? &&
447:             one =~ /\A[A-Za-z]\Z/ && two =~ /\A[\/\\]/
448:           # If we're on Windows and we were passed a drive letter path,
449:           # don't split on that colon.
450:           one2, two = two.split(':', 2)
451:           one = one + ':' + one2
452:         end
453:         return one, two
454:       end
watch_or_update() click to toggle source
     # File lib/haml/exec.rb, line 385
385:       def watch_or_update
386:         require 'sass'
387:         require 'sass/plugin'
388:         ::Sass::Plugin.options.merge! @options[:for_engine]
389:         ::Sass::Plugin.options[:unix_newlines] = @options[:unix_newlines]
390: 
391:         if !colon_path?(@args[0]) && probably_dest_dir?(@args[1])
392:           flag = @options[:update] ? "--update" : "--watch"
393:           err =
394:             if !File.exist?(@args[1])
395:               "doesn't exist"
396:             elsif @args[1] =~ /\.css$/
397:               "is a CSS file"
398:             end
399:           msg = File #{@args[1]} #{err}.  Did you mean: sass #{flag} #{@args[0]}:#{@args[1]} if err
400:         end
401: 
402:         dirs, files = @args.map {|name| split_colon_path(name)}.
403:           partition {|i, _| File.directory? i}
404:         files.map! {|from, to| [from, to || from.gsub(/\..*?$/, '.css')]}
405:         dirs.map! {|from, to| [from, to || from]}
406:         ::Sass::Plugin.options[:template_location] = dirs
407: 
408:         ::Sass::Plugin.on_updating_stylesheet do |_, css|
409:           if File.exists? css
410:             puts_action :overwrite, :yellow, css
411:           else
412:             puts_action :create, :green, css
413:           end
414:         end
415: 
416:         ::Sass::Plugin.on_creating_directory {|dirname| puts_action :directory, :green, dirname}
417:         ::Sass::Plugin.on_deleting_css {|filename| puts_action :delete, :yellow, filename}
418:         ::Sass::Plugin.on_compilation_error do |error, _, _|
419:           raise error unless error.is_a?(::Sass::SyntaxError)
420:           puts_action :error, :red, "#{error.sass_filename} (Line #{error.sass_line}: #{error.message})"
421:         end
422: 
423:         if @options[:update]
424:           ::Sass::Plugin.update_stylesheets(files)
425:           return
426:         end
427: 
428:         puts ">>> Sass is watching for changes. Press Ctrl-C to stop."
429: 
430:         ::Sass::Plugin.on_template_modified {|template| puts ">>> Change detected to: #{template}"}
431:         ::Sass::Plugin.on_template_created {|template| puts ">>> New template detected: #{template}"}
432:         ::Sass::Plugin.on_template_deleted {|template| puts ">>> Deleted template detected: #{template}"}
433: 
434:         ::Sass::Plugin.watch(files)
435:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.