Class: MasterView::Parser
- Inherits:
-
Object
- Object
- MasterView::Parser
- Defined in:
- lib/masterview/parser.rb
Class Method Summary collapse
- .escape_erb(html) ⇒ Object
-
.parse(template, options = DefaultParserOptions.clone) ⇒ Object
parse a MasterView template and render output.
-
.parse_file(template_file_path, output_dir, options = DefaultParserOptions.clone) ⇒ Object
parse a MasterView template by first reading from file and render output.
- .tidy(html) ⇒ Object
Class Method Details
.escape_erb(html) ⇒ Object
578 579 580 581 582 |
# File 'lib/masterview/parser.rb', line 578 def self.escape_erb(html) html = html.gsub(/<%/, InlineErbStart) html.gsub!(/%>/, InlineErbEnd) html end |
.parse(template, options = DefaultParserOptions.clone) ⇒ Object
parse a MasterView template and render output. template param is actual template source passed in as string or array. options are the optional parameters which control the output (:output_dir, :namespace, :serializer)
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/masterview/parser.rb', line 545 def self.parse( template, = DefaultParserOptions.clone) begin if [:tidy] template = self.tidy(template) elsif [:escape_erb] template = self.escape_erb(template) end parser = REXML::Parsers::SAX2Parser.new( template ) parser.listen( MasterViewListener.new() ) parser.parse rescue Exception => e if RescueExceptions Log.error { "Failure to parse template. Exception="+e } Log.debug { e.backtrace.join("\n") } else raise end end end |
.parse_file(template_file_path, output_dir, options = DefaultParserOptions.clone) ⇒ Object
parse a MasterView template by first reading from file and render output. template_file_path param is file path to template options are the optional parameters which control the output (:output_dir, :namespace)
533 534 535 536 537 538 539 540 |
# File 'lib/masterview/parser.rb', line 533 def self.parse_file( template_file_path, output_dir, = DefaultParserOptions.clone) Log.debug { "Parsing file=#{File.(template_file_path)} output_dir=#{File.(output_dir)}" } [:template_path]=File.(template_file_path) [:output_dir] = output_dir template = File.new( template_file_path ) template = template.readlines.join if [:tidy] || [:escape_erb] self.parse( template, ) end |
.tidy(html) ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/masterview/parser.rb', line 565 def self.tidy(html) Tidy.path = TidyPath unless Tidy.path xml = Tidy.open do |tidy| tidy..output_xml = true tidy..indent = true tidy..wrap = 0 xml = tidy.clean(html) end xml = self.escape_erb(xml) Log.debug { 'tidy corrected xml='+xml } xml end |