Class: ErbFile
Instance Attribute Summary collapse
-
#node_set ⇒ Object
Returns the value of attribute node_set.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Class Method Summary collapse
Instance Method Summary collapse
- #combine_nodes(leaves) ⇒ Object
- #compiled? ⇒ Boolean
- #extract_text(text_extractor) ⇒ Object
- #flatten_elements ⇒ Object
-
#initialize(node_set) ⇒ ErbFile
constructor
A new instance of ErbFile.
- #serialize ⇒ Object
- #to_s ⇒ Object
Methods included from NodeProcessing
Constructor Details
#initialize(node_set) ⇒ ErbFile
Returns a new instance of ErbFile.
7 8 9 10 11 |
# File 'lib/core/erb_file.rb', line 7 def initialize( node_set ) @node_set = node_set @nodes = flatten_elements if compiled? @debug = false end |
Instance Attribute Details
#node_set ⇒ Object
Returns the value of attribute node_set.
5 6 7 |
# File 'lib/core/erb_file.rb', line 5 def node_set @node_set end |
#nodes ⇒ Object
Returns the value of attribute nodes.
4 5 6 |
# File 'lib/core/erb_file.rb', line 4 def nodes @nodes end |
Class Method Details
.debug(file_path) ⇒ Object
23 24 25 26 |
# File 'lib/core/erb_file.rb', line 23 def ErbFile.debug( file_path ) ErbFile.parse( File.read( file_path ) ) @parser.failure_reason end |
Instance Method Details
#combine_nodes(leaves) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/core/erb_file.rb', line 28 def combine_nodes( leaves ) combined_nodes = [] leaves.each do |node| last_combined_node = combined_nodes.pop if( last_combined_node.nil? ) combined_nodes << node elsif( combindable_node?( node ) && combindable_node?( last_combined_node ) ) new_node = HerbNodeRetainingNonTextNode.new( last_combined_node ) new_node << node combined_nodes << new_node elsif( !node.is_a?(TextNode) && !last_combined_node.is_a?(TextNode) && !(last_combined_node.is_a?(BaseNode) && last_combined_node.can_be_combined? ) && !(node.is_a?(NonTextNode) && node.can_be_combined? ) ) combined_nodes << combine_two_nodes( last_combined_node, node, HerbNodeRetainingNonTextNode ) elsif( last_combined_node.is_a?(TextNode) && node.is_a?(TextNode) ) combined_nodes << combine_two_nodes( last_combined_node, node, HerbNodeRetainingTextNode ) elsif( combindable_node?( last_combined_node ) && node.is_a?(TextNode) ) combined_nodes << combine_two_nodes( last_combined_node, node, HerbNodeRetainingTextNode ) elsif( combindable_node?( node ) && last_combined_node.is_a?(TextNode)) combined_nodes << combine_two_nodes( last_combined_node, node, HerbNodeRetainingTextNode ) elsif( node.is_a?(NonTextNode) && node.can_be_combined? && last_combined_node.is_a?(TextNode ) ) combined_nodes << combine_two_nodes( last_combined_node, node, HerbNodeRetainingTextNode ) else combined_nodes << last_combined_node combined_nodes << node end end ( unwind_list( combined_nodes ) ) end |
#compiled? ⇒ Boolean
19 20 21 |
# File 'lib/core/erb_file.rb', line 19 def compiled? !@node_set.nil? end |
#extract_text(text_extractor) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/core/erb_file.rb', line 57 def extract_text( text_extractor ) # 1. Going to have to loop over all of the elements and find all of # the text. # 2. Then make the call back to the text_extractor # 3. Finally replace the nodes in the top levels (not sure how # this is going to work with any of the nested stuff) text_extractor.starting_text_extraction new_node_set = [] @nodes ||= [] @nodes = combine_nodes( @nodes ) @nodes.each do |node| if( node.respond_to?(:text?) && node.text? ) text_extractor.start_html_text node.extract_text( text_extractor, new_node_set ) new_node_set += text_extractor.end_html_text else new_node_set << node end @nodes = new_node_set self end text_extractor.completed_text_extraction end |
#flatten_elements ⇒ Object
13 14 15 16 17 |
# File 'lib/core/erb_file.rb', line 13 def flatten_elements terminals = [] flatten( @node_set, terminals ) terminals end |
#serialize ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/core/erb_file.rb', line 89 def serialize to_return = "" nodes.each do |node| to_return << node.text_value end to_return end |
#to_s ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/core/erb_file.rb', line 99 def to_s to_return = "" nodes.each do |node| to_return += node.text_value end to_return end |