Class: Haml::Exec::HTML2Haml
Overview
The html2haml
executable.
Constant Summary
Instance Method Summary (collapse)
-
- (HTML2Haml) initialize(args)
constructor
A new instance of HTML2Haml.
-
- process_result
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
-
- set_opts(opts)
Tells optparse how to parse the arguments.
Methods inherited from Generic
#color, #get_line, #parse, #parse!, #puts, #puts_action, #to_s
Constructor Details
- (HTML2Haml) initialize(args)
A new instance of HTML2Haml
302 303 304 305 |
# File '/build/buildd/ruby-haml-3.1.4/lib/haml/exec.rb', line 302
def initialize(args)
super
@module_opts = {}
end
|
Instance Method Details
- process_result
Processes the options set by the command-line arguments, and runs the HTML compiler appropriately.
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File '/build/buildd/ruby-haml-3.1.4/lib/haml/exec.rb', line 345
def process_result
super
require 'haml/html'
input = @options[:input]
output = @options[:output]
@module_opts[:erb] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
@module_opts[:erb] &&= @options[:no_erb] != false
output.write(::Haml::HTML.new(input, @module_opts).render)
rescue ::Haml::Error => e
raise "#{e.is_a?(::Haml::SyntaxError) ? "Syntax error" : "Error"} on line " +
"#{get_line e}: #{e.message}"
rescue LoadError => err
handle_load_error(err)
end
|
- set_opts(opts)
Tells optparse how to parse the arguments.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File '/build/buildd/ruby-haml-3.1.4/lib/haml/exec.rb', line 310
def set_opts(opts)
opts.banner = "Usage: html2haml [options] [INPUT] [OUTPUT]\n\nDescription: Transforms an HTML file into corresponding Haml code.\n\nOptions:\n"
opts.on('-e', '--erb', 'Parse ERb tags.') do
@module_opts[:erb] = true
end
opts.on('--no-erb', "Don't parse ERb tags.") do
@options[:no_erb] = true
end
opts.on('-r', '--rhtml', 'Deprecated; same as --erb.') do
@module_opts[:erb] = true
end
opts.on('--no-rhtml', "Deprecated; same as --no-erb.") do
@options[:no_erb] = true
end
opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
@module_opts[:xhtml] = true
end
super
end
|