| 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 583
583: def initialize(args)
584: super
585: require 'sass'
586: @options[:for_tree] = {}
587: @options[:for_engine] = {:cache => false, :read_cache => true}
588: end
Processes the options set by the command-line arguments, and runs the CSS compiler appropriately.
# File lib/haml/exec.rb, line 657
657: def process_result
658: require 'sass'
659:
660: if @options[:recursive]
661: process_directory
662: return
663: end
664:
665: super
666: input = @options[:input]
667: raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)" if File.directory?(input)
668: output = @options[:output]
669: output = input if @options[:in_place]
670: process_file(input, output)
671: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 593
593: def set_opts(opts)
594: 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"
595:
596: opts.on('-F', '--from FORMAT',
597: 'The format to convert from. Can be css, scss, sass, less, or sass2.',
598: 'sass2 is the same as sass, but updates more old syntax to new.',
599: 'By default, this is inferred from the input filename.',
600: 'If there is none, defaults to css.') do |name|
601: @options[:from] = name.downcase.to_sym
602: unless [:css, :scss, :sass, :less, :sass2].include?(@options[:from])
603: raise "Unknown format for sass-convert --from: #{name}"
604: end
605: try_less_note if @options[:from] == :less
606: end
607:
608: opts.on('-T', '--to FORMAT',
609: 'The format to convert to. Can be scss or sass.',
610: 'By default, this is inferred from the output filename.',
611: 'If there is none, defaults to sass.') do |name|
612: @options[:to] = name.downcase.to_sym
613: unless [:scss, :sass].include?(@options[:to])
614: raise "Unknown format for sass-convert --to: #{name}"
615: end
616: end
617:
618: opts.on('-R', '--recursive',
619: 'Convert all the files in a directory. Requires --from and --to.') do
620: @options[:recursive] = true
621: end
622:
623: opts.on('-i', '--in-place',
624: 'Convert a file to its own syntax.',
625: 'This can be used to update some deprecated syntax.') do
626: @options[:in_place] = true
627: end
628:
629: opts.on('--dasherize', 'Convert underscores to dashes') do
630: @options[:for_tree][:dasherize] = true
631: end
632:
633: opts.on('--old', 'Output the old-style ":prop val" property syntax.',
634: 'Only meaningful when generating Sass.') do
635: @options[:for_tree][:old] = true
636: end
637:
638: opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
639: @options[:for_engine][:read_cache] = false
640: end
641:
642: super
643: end