Class: MasterView::Parser
- Inherits:
-
Object
- Object
- MasterView::Parser
- Defined in:
- lib/masterview/parser.rb
Overview
The Parser processes a template document containing MasterView directives markup.
Processing options can be specified to control pre-processing of the template (e.g., :tidy
to run HTML Tidy) as well as the operation of the parse operation.
Class Method Summary collapse
-
.parse(template, options = {}) ⇒ Object
Parse a MasterView template and render output.
-
.parse_mio(template_mio, output_mio_tree, options = {}) ⇒ Object
Parse a template document contained in an IO source.
Instance Method Summary collapse
-
#ensure_standard_options_configured(options) ⇒ Object
ensure that default policies are configured.
-
#process(template, options) ⇒ Object
process the template.
Class Method Details
.parse(template, options = {}) ⇒ 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 template parsing (:tidy) and rendering output (:output_mio_tree, :namespace, :serializer)
683 684 685 686 |
# File 'lib/masterview/parser.rb', line 683 def self.parse( template, ={} ) mv_parser = self.new mv_parser.process(template, ) end |
.parse_mio(template_mio, output_mio_tree, options = {}) ⇒ Object
Parse a template document contained in an IO source.
669 670 671 672 673 674 675 |
# File 'lib/masterview/parser.rb', line 669 def self.parse_mio( template_mio, output_mio_tree, ={} ) = .clone() # don't munge the client's copy of this [:template_pathname] = template_mio.pathname [:output_mio_tree] = output_mio_tree template = template_mio.read self.parse( template, ) end |
Instance Method Details
#ensure_standard_options_configured(options) ⇒ Object
ensure that default policies are configured
715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/masterview/parser.rb', line 715 def () #:nodoc: # install the standard processing mechanisms unless overridden by client [:directive_load_path] = DirectiveLoadPath.current unless .include?(:directive_load_path) [:listeners] ||= [ TemplateProcessing::SAXParserListener ] [:rescue_exceptions] = RescueExceptions unless .include?(:rescue_exceptions) DefaultParserOptions.each_pair {|key, value| [key] = value unless .include?(key) } end |
#process(template, options) ⇒ Object
process the template
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/masterview/parser.rb', line 689 def process(template, ) = .clone() # don't munge the client's copy of this () begin sax_parser = MasterView::REXMLSax2ParserClass.new( template ) [:listeners].each do |listener| if listener.is_a? Class sax_parser.listen( listener.new() ) else sax_parser.listen(listener) end end sax_parser.parse rescue Exception => ex if [:rescue_exceptions] Log.error { "Failure to parse template. Exception="+ex } Log.debug { ex.backtrace.join("\n") } else raise end end end |