| 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 645
645: def initialize(args)
646: super
647: require 'sass'
648: @options[:for_tree] = {}
649: @options[:for_engine] = {:cache => false, :read_cache => true}
650: end
Processes the options set by the command-line arguments, and runs the CSS compiler appropriately.
# File lib/haml/exec.rb, line 725
725: def process_result
726: require 'sass'
727:
728: if @options[:recursive]
729: process_directory
730: return
731: end
732:
733: super
734: input = @options[:input]
735: raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)" if File.directory?(input)
736: output = @options[:output]
737: output = input if @options[:in_place]
738: process_file(input, output)
739: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 655
655: def set_opts(opts)
656: 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"
657:
658: opts.on('-F', '--from FORMAT',
659: 'The format to convert from. Can be css, scss, sass, less, or sass2.',
660: 'sass2 is the same as sass, but updates more old syntax to new.',
661: 'By default, this is inferred from the input filename.',
662: 'If there is none, defaults to css.') do |name|
663: @options[:from] = name.downcase.to_sym
664: unless [:css, :scss, :sass, :less, :sass2].include?(@options[:from])
665: raise "Unknown format for sass-convert --from: #{name}"
666: end
667: try_less_note if @options[:from] == :less
668: end
669:
670: opts.on('-T', '--to FORMAT',
671: 'The format to convert to. Can be scss or sass.',
672: 'By default, this is inferred from the output filename.',
673: 'If there is none, defaults to sass.') do |name|
674: @options[:to] = name.downcase.to_sym
675: unless [:scss, :sass].include?(@options[:to])
676: raise "Unknown format for sass-convert --to: #{name}"
677: end
678: end
679:
680: opts.on('-R', '--recursive',
681: 'Convert all the files in a directory. Requires --from and --to.') do
682: @options[:recursive] = true
683: end
684:
685: opts.on('-i', '--in-place',
686: 'Convert a file to its own syntax.',
687: 'This can be used to update some deprecated syntax.') do
688: @options[:in_place] = true
689: end
690:
691: opts.on('--dasherize', 'Convert underscores to dashes') do
692: @options[:for_tree][:dasherize] = true
693: end
694:
695: opts.on('--old', 'Output the old-style ":prop val" property syntax.',
696: 'Only meaningful when generating Sass.') do
697: @options[:for_tree][:old] = true
698: end
699:
700: opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
701: @options[:for_engine][:read_cache] = false
702: end
703:
704: unless ::Haml::Util.ruby1_8?
705: opts.on('-E encoding', 'Specify the default encoding for Sass and CSS files.') do |encoding|
706: Encoding.default_external = encoding
707: end
708: end
709:
710: super
711: end