The `haml` executable.
Processes the options set by the command-line arguments, and runs the Haml compiler appropriately.
# File lib/haml/exec.rb, line 257 257: def process_result 258: super 259: @options[:for_engine][:filename] = @options[:filename] 260: input = @options[:input] 261: output = @options[:output] 262: 263: template = input.read() 264: input.close() if input.is_a? File 265: 266: @options[:load_paths].each {|p| $LOAD_PATH << p} 267: @options[:requires].each {|f| require f} 268: 269: begin 270: engine = ::Haml::Engine.new(template, @options[:for_engine]) 271: if @options[:check_syntax] 272: puts "Syntax OK" 273: return 274: end 275: 276: if @options[:debug] 277: puts engine.precompiled 278: puts '=' * 100 279: end 280: 281: result = engine.to_html 282: rescue Exception => e 283: raise e if @options[:trace] 284: 285: case e 286: when ::Haml::SyntaxError; raise "Syntax error on line #{get_line e}: #{e.message}" 287: when ::Haml::Error; raise "Haml error on line #{get_line e}: #{e.message}" 288: else raise "Exception on line #{get_line e}: #{e.message}\n Use --trace for backtrace." 289: end 290: end 291: 292: output.write(result) 293: output.close() if output.is_a? File 294: end
Tells optparse how to parse the arguments.
@param opts [OptionParser]
# File lib/haml/exec.rb, line 191 191: def set_opts(opts) 192: super 193: 194: opts.banner = Usage: haml [options] [INPUT] [OUTPUT]Description: Converts Haml files to HTML.Options: 195: 196: opts.on('-c', '--check', "Just check syntax, don't evaluate.") do 197: require 'stringio' 198: @options[:check_syntax] = true 199: @options[:output] = StringIO.new 200: end 201: 202: opts.on('-t', '--style NAME', 203: 'Output style. Can be indented (default) or ugly.') do |name| 204: @options[:for_engine][:ugly] = true if name.to_sym == :ugly 205: end 206: 207: opts.on('-f', '--format NAME', 208: 'Output format. Can be xhtml (default), html4, or html5.') do |name| 209: @options[:for_engine][:format] = name.to_sym 210: end 211: 212: opts.on('-e', '--escape-html', 213: 'Escape HTML characters (like ampersands and angle brackets) by default.') do 214: @options[:for_engine][:escape_html] = true 215: end 216: 217: opts.on('--no-escape-attrs', 218: "Don't escape HTML characters (like ampersands and angle brackets) in attributes.") do 219: @options[:for_engine][:escape_attrs] = false 220: end 221: 222: opts.on('-q', '--double-quote-attributes', 223: 'Set attribute wrapper to double-quotes (default is single).') do 224: @options[:for_engine][:attr_wrapper] = '"' 225: end 226: 227: opts.on('-r', '--require FILE', "Same as 'ruby -r'.") do |file| 228: @options[:requires] << file 229: end 230: 231: opts.on('-I', '--load-path PATH', "Same as 'ruby -I'.") do |path| 232: @options[:load_paths] << path 233: end 234: 235: unless ::Haml::Util.ruby1_8? 236: opts.on('-E ex[:in]', 'Specify the default external and internal character encodings.') do |encoding| 237: external, internal = encoding.split(':') 238: Encoding.default_external = external if external && !external.empty? 239: Encoding.default_internal = internal if internal && !internal.empty? 240: end 241: end 242: 243: opts.on('--debug', "Print out the precompiled Ruby source.") do 244: @options[:debug] = true 245: end 246: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.