Class: Haml::Exec::Haml
Overview
The ‘haml` executable.
Instance Method Summary collapse
-
#initialize(args) ⇒ Haml
constructor
A new instance of Haml.
-
#process_result ⇒ Object
Processes the options set by the command-line arguments, and runs the Haml compiler appropriately.
-
#set_opts(opts) ⇒ Object
Tells optparse how to parse the arguments.
Methods inherited from Generic
Constructor Details
#initialize(args) ⇒ Haml
Returns a new instance of Haml.
274 275 276 277 278 279 |
# File 'lib/haml/exec.rb', line 274 def initialize(args) super @name = "Haml" @options[:requires] = [] @options[:load_paths] = [] end |
Instance Method Details
#process_result ⇒ Object
Processes the options set by the command-line arguments, and runs the Haml compiler appropriately.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/haml/exec.rb', line 317 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} if @options[:debug] puts engine.precompiled puts '=' * 100 end 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.}" when ::Haml::Error; raise "Haml error on line #{get_line e}: #{e.}" else raise "Exception on line #{get_line e}: #{e.}\n Use --trace for backtrace." end end output.write(result) output.close() if output.is_a? File end |
#set_opts(opts) ⇒ Object
Tells optparse how to parse the arguments.
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/haml/exec.rb', line 284 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 opts.on('--debug', "Print out the precompiled Ruby source.") do @options[:debug] = true end end |