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 609 609: def initialize(args) 610: super 611: require 'sass' 612: @options[:for_tree] = {} 613: @options[:for_engine] = {:cache => false, :read_cache => true} 614: end
Processes the options set by the command-line arguments, and runs the CSS compiler appropriately.
# File lib/haml/exec.rb, line 689 689: def process_result 690: require 'sass' 691: 692: if @options[:recursive] 693: process_directory 694: return 695: end 696: 697: super 698: input = @options[:input] 699: raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)" if File.directory?(input) 700: output = @options[:output] 701: output = input if @options[:in_place] 702: process_file(input, output) 703: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 619 619: def set_opts(opts) 620: 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" 621: 622: opts.on('-F', '--from FORMAT', 623: 'The format to convert from. Can be css, scss, sass, less, or sass2.', 624: 'sass2 is the same as sass, but updates more old syntax to new.', 625: 'By default, this is inferred from the input filename.', 626: 'If there is none, defaults to css.') do |name| 627: @options[:from] = name.downcase.to_sym 628: unless [:css, :scss, :sass, :less, :sass2].include?(@options[:from]) 629: raise "Unknown format for sass-convert --from: #{name}" 630: end 631: try_less_note if @options[:from] == :less 632: end 633: 634: opts.on('-T', '--to FORMAT', 635: 'The format to convert to. Can be scss or sass.', 636: 'By default, this is inferred from the output filename.', 637: 'If there is none, defaults to sass.') do |name| 638: @options[:to] = name.downcase.to_sym 639: unless [:scss, :sass].include?(@options[:to]) 640: raise "Unknown format for sass-convert --to: #{name}" 641: end 642: end 643: 644: opts.on('-R', '--recursive', 645: 'Convert all the files in a directory. Requires --from and --to.') do 646: @options[:recursive] = true 647: end 648: 649: opts.on('-i', '--in-place', 650: 'Convert a file to its own syntax.', 651: 'This can be used to update some deprecated syntax.') do 652: @options[:in_place] = true 653: end 654: 655: opts.on('--dasherize', 'Convert underscores to dashes') do 656: @options[:for_tree][:dasherize] = true 657: end 658: 659: opts.on('--old', 'Output the old-style ":prop val" property syntax.', 660: 'Only meaningful when generating Sass.') do 661: @options[:for_tree][:old] = true 662: end 663: 664: opts.on('-C', '--no-cache', "Don't cache to sassc files.") do 665: @options[:for_engine][:read_cache] = false 666: end 667: 668: unless ::Haml::Util.ruby1_8? 669: opts.on('-E encoding', 'Specify the default encoding for Sass and CSS files.') do |encoding| 670: Encoding.default_external = encoding 671: end 672: end 673: 674: super 675: end