Class: Haml::Exec::Haml

Inherits:
HamlSass show all
Defined in:
lib/gems/haml-2.0.4/lib/haml/exec.rb

Overview

A class encapsulating executable functionality specific to Haml.

Instance Method Summary collapse

Methods inherited from Generic

#parse!, #to_s

Constructor Details

#initialize(args) ⇒ Haml

:nodoc:



206
207
208
209
210
211
# File 'lib/gems/haml-2.0.4/lib/haml/exec.rb', line 206

def initialize(args)
  super
  @name = "Haml"
  @options[:requires] = []
  @options[:load_paths] = []
end

Instance Method Details

#process_resultObject



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/gems/haml-2.0.4/lib/haml/exec.rb', line 240

def process_result
  super
  input = @options[:input]
  output = @options[:output]

  template = input.read()
  input.close() if input.is_a? File

  begin
    engine = ::Haml::Engine.new(template, @options[:for_engine])
    if @options[:check_syntax]
      puts "Syntax OK"
      return
    end

    @options[:load_paths].each {|p| $LOAD_PATH << p}
    @options[:requires].each {|f| require f}
    result = engine.to_html
  rescue Exception => e
    raise e if @options[:trace]

    case e
    when ::Haml::SyntaxError; raise "Syntax error on line #{get_line e}: #{e.message}"
    when ::Haml::Error;       raise "Haml error on line #{get_line e}: #{e.message}"
    else raise "Exception on line #{get_line e}: #{e.message}\n  Use --trace for backtrace."
    end
  end

  output.write(result)
  output.close() if output.is_a? File
end

#set_opts(opts) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/gems/haml-2.0.4/lib/haml/exec.rb', line 213

def set_opts(opts)
  super

  opts.on('-t', '--style NAME',
          'Output style. Can be indented (default) or ugly.') do |name|
    @options[:for_engine][:ugly] = true if name.to_sym == :ugly
  end

  opts.on('-f', '--format NAME',
          'Output format. Can be xhtml (default), html4, or html5.') do |name|
    @options[:for_engine][:format] = name.to_sym
  end

  opts.on('-e', '--escape-html',
          'Escape HTML characters (like ampersands and angle brackets) by default.') do
    @options[:for_engine][:escape_html] = true
  end

  opts.on('-r', '--require FILE', "Same as 'ruby -r'.") do |file|
    @options[:requires] << file
  end

  opts.on('-I', '--load-path PATH', "Same as 'ruby -I'.") do |path|
    @options[:load_paths] << path
  end
end