Class: Sass::Exec::SassConvert

Inherits:
Generic
  • Object
show all
Defined in:
/var/www/sass-pages/.sass/lib/sass/exec.rb

Overview

The sass-convert executable.

Constant Summary

Instance Method Summary

Methods inherited from Generic

#color, #get_line, #parse, #parse!, #puts, #puts_action, #to_s

Constructor Details

- (SassConvert) initialize(args)

A new instance of SassConvert

Parameters:

  • (Array<String>) args — The command-line arguments


474
475
476
477
478
479
# File '/var/www/sass-pages/.sass/lib/sass/exec.rb', line 474

def initialize(args)
  super
  require 'sass'
  @options[:for_tree] = {}
  @options[:for_engine] = {:cache => false, :read_cache => true}
end

Instance Method Details

- process_result

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



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File '/var/www/sass-pages/.sass/lib/sass/exec.rb', line 553

def process_result
  require 'sass'

  if @options[:recursive]
    process_directory
    return
  end

  super
  input = @options[:input]
  raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)" if File.directory?(input)
  output = @options[:output]
  output = input if @options[:in_place]
  process_file(input, output)
end

- set_opts(opts)

Tells optparse how to parse the arguments.

Parameters:

  • (OptionParser) opts


484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File '/var/www/sass-pages/.sass/lib/sass/exec.rb', line 484

def set_opts(opts)
  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"

  opts.on('-F', '--from FORMAT',
    'The format to convert from. Can be css, scss, sass, less.',
    'By default, this is inferred from the input filename.',
    'If there is none, defaults to css.') do |name|
    @options[:from] = name.downcase.to_sym
    unless [:css, :scss, :sass, :less].include?(@options[:from])
      raise "Unknown format for sass-convert --from: #{name}"
    end
    try_less_note if @options[:from] == :less
  end

  opts.on('-T', '--to FORMAT',
    'The format to convert to. Can be scss or sass.',
    'By default, this is inferred from the output filename.',
    'If there is none, defaults to sass.') do |name|
    @options[:to] = name.downcase.to_sym
    unless [:scss, :sass].include?(@options[:to])
      raise "Unknown format for sass-convert --to: #{name}"
    end
  end

  opts.on('-R', '--recursive',
    'Convert all the files in a directory. Requires --from and --to.') do
    @options[:recursive] = true
  end

  opts.on('-i', '--in-place',
    'Convert a file to its own syntax.',
    'This can be used to update some deprecated syntax.') do
    @options[:in_place] = true
  end

  opts.on('--dasherize', 'Convert underscores to dashes') do
    @options[:for_tree][:dasherize] = true
  end

  opts.on('--old', 'Output the old-style ":prop val" property syntax.',
                   'Only meaningful when generating Sass.') do
    @options[:for_tree][:old] = true
  end

  opts.on('-C', '--no-cache', "Don't cache to sassc files.") do
    @options[:for_engine][:read_cache] = false
  end

  unless ::Sass::Util.ruby1_8?
    opts.on('-E encoding', 'Specify the default encoding for Sass and CSS files.') do |encoding|
      Encoding.default_external = encoding
    end
  end

  super
end