Class: Sass::Exec::SassConvert

Inherits:
Generic
  • Object
show all
Defined in:
lib/sass/exec.rb

Overview

The sass-convert executable.

Constant Summary

Constants inherited from Generic

Generic::COLORS

Instance Method Summary collapse

Methods inherited from Generic

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

Constructor Details

#initialize(args) ⇒ SassConvert

Returns a new instance of SassConvert.

Parameters:

  • args (Array<String>)

    The command-line arguments



560
561
562
563
564
565
# File 'lib/sass/exec.rb', line 560

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.



654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
# File 'lib/sass/exec.rb', line 654

def process_result
  require 'sass'

  if @options[:recursive]
    process_directory
    return
  end

  super
  input = @options[:input]
  if File.directory?(input)
    raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)"
  end
  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:

  • opts (OptionParser)


572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/sass/exec.rb', line 572

def set_opts(opts)
  opts.banner = <<END
Usage: sass-convert [options] [INPUT] [OUTPUT]

Description:
  Converts between CSS, Sass, and SCSS files.
  E.g. converts from SCSS to Sass,
  or converts from CSS to SCSS (adding appropriate nesting).

Options:
END

  opts.on('-F', '--from FORMAT',
    'The format to convert from. Can be css, scss, sass.',
    'By default, this is inferred from the input filename.',
    'If there is none, defaults to css.') do |name|
    @options[:from] = name.downcase.to_sym
    raise "sass-convert no longer supports LessCSS." if @options[:from] == :less
    unless [:css, :scss, :sass].include?(@options[:from])
      raise "Unknown format for sass-convert --from: #{name}"
    end
  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('--indent NUM',
    'How many spaces to use for each level of indentation. Defaults to 2.',
    '"t" means use hard tabs.') do |indent|

    if indent == 't'
      @options[:for_tree][:indent] = "\t"
    else
      @options[:for_tree][:indent] = " " * indent.to_i
    end
  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