| Class | Haml::Exec::SassConvert |
| In: |
lib/haml/exec.rb
|
| Parent: | Generic |
The `sass-convert` executable.
@param args [Array<String>] The command-line arguments
# File lib/haml/exec.rb, line 594
594: def initialize(args)
595: super
596: require 'sass'
597: @options[:for_tree] = {}
598: @options[:for_engine] = {:cache => false, :read_cache => true}
599: end
Processes the options set by the command-line arguments, and runs the CSS compiler appropriately.
# File lib/haml/exec.rb, line 668
668: def process_result
669: require 'sass'
670:
671: if @options[:recursive]
672: process_directory
673: return
674: end
675:
676: super
677: input = @options[:input]
678: raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)" if File.directory?(input)
679: output = @options[:output]
680: output = input if @options[:in_place]
681: process_file(input, output)
682: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 604
604: def set_opts(opts)
605: opts.banner = "Usage: sass-convert [options] [INPUT] [OUTPUT]\n\nDescription:\n Converts between CSS, Sass, and SCSS files.\n E.g. converts from SCSS to Sass,\n or converts from CSS to SCSS (adding appropriate nesting).\n\nOptions:\n"
606:
607: opts.on('-F', '--from FORMAT',
608: 'The format to convert from. Can be css, scss, sass, less, or sass2.',
609: 'sass2 is the same as sass, but updates more old syntax to new.',
610: 'By default, this is inferred from the input filename.',
611: 'If there is none, defaults to css.') do |name|
612: @options[:from] = name.downcase.to_sym
613: unless [:css, :scss, :sass, :less, :sass2].include?(@options[:from])
614: raise "Unknown format for sass-convert --from: #{name}"
615: end
616: try_less_note if @options[:from] == :less
617: end
618:
619: opts.on('-T', '--to FORMAT',
620: 'The format to convert to. Can be scss or sass.',
621: 'By default, this is inferred from the output filename.',
622: 'If there is none, defaults to sass.') do |name|
623: @options[:to] = name.downcase.to_sym
624: unless [:scss, :sass].include?(@options[:to])
625: raise "Unknown format for sass-convert --to: #{name}"
626: end
627: end
628:
629: opts.on('-R', '--recursive',
630: 'Convert all the files in a directory. Requires --from and --to.') do
631: @options[:recursive] = true
632: end
633:
634: opts.on('-i', '--in-place',
635: 'Convert a file to its own syntax.',
636: 'This can be used to update some deprecated syntax.') do
637: @options[:in_place] = true
638: end
639:
640: opts.on('--dasherize', 'Convert underscores to dashes') do
641: @options[:for_tree][:dasherize] = true
642: end
643:
644: opts.on('--old', 'Output the old-style ":prop val" property syntax.',
645: 'Only meaningful when generating Sass.') do
646: @options[:for_tree][:old] = true
647: end
648:
649: opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
650: @options[:for_engine][:read_cache] = false
651: end
652:
653: super
654: end