Class: Haml::Exec::CSS2Sass

Inherits:
Generic show all
Defined in:
lib/haml/exec.rb

Overview

The css2sass executable.

Instance Method Summary collapse

Methods inherited from Generic

#get_line, #parse!, #to_s

Constructor Details

#initialize(args) ⇒ CSS2Sass

Returns a new instance of CSS2Sass.

Parameters:

  • args (Array<String>)

    The command-line arguments



434
435
436
437
438
439
440
# File 'lib/haml/exec.rb', line 434

def initialize(args)
  super

  @module_opts = {}

  require 'sass/css'
end

Instance Method Details

#process_resultObject

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



465
466
467
468
469
470
471
472
473
474
475
# File 'lib/haml/exec.rb', line 465

def process_result
  super

  input = @options[:input]
  output = @options[:output]

  output.write(::Sass::CSS.new(input, @module_opts).render)
rescue ::Sass::SyntaxError => e
  raise e if @options[:trace]
  raise "Syntax error on line #{get_line e}: #{e.message}\n  Use --trace for backtrace"
end

#set_opts(opts) ⇒ Object

Tells optparse how to parse the arguments.

Parameters:

  • opts (OptionParser)


445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/haml/exec.rb', line 445

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

Description: Transforms a CSS file into corresponding Sass code.

Options:
END

  opts.on('--old', 'Output the old-style ":prop val" property syntax') do
    @module_opts[:old] = true
  end

  opts.on_tail('-a', '--alternate', 'Ignored') {}

  super
end