Module | Amrita::Node |
In: |
lib/amrita/compiler.rb
lib/amrita/format.rb lib/amrita/node.rb lib/amrita/node_expand.rb |
Base module for HTML elements
iterate on child Elements
# File lib/amrita/node.rb, line 262 def each_element(&block) each_node do |node| yield(node) if node.kind_of?(Element) end end
iterate on self and children
# File lib/amrita/node.rb, line 253 def each_node(&block) c = children # save children before yield yield(self) c.each do |n| n.each_node(&block) end end
expand self as a template with a model data.
# File lib/amrita/node_expand.rb, line 267 def expand(data, context=DefaultContext.clone) case data when true self when nil, false Null when DictionaryData expand1(data, context) else raise "Amrita::Node#expand accepts only Hash or ExpandByMember as model data (#{data.type} was passed)" end end
# File lib/amrita/node_expand.rb, line 280 def expand1(data, context=DefaultContext.clone) data.amrita_expand_node(self, context) end
# File lib/amrita/compiler.rb, line 72 def generate_hint_from_template hash = {} each_element_with_id do |e| hash[e.hid.intern] = HtmlCompiler::AnyData end HtmlCompiler::DictionaryHint.new(hash) end
set the block ’s result to body
# File lib/amrita/node.rb, line 179 def init_body(&block) if block_given? @body = to_node(yield) else @body = Null end end
test if it has any children
# File lib/amrita/node.rb, line 197 def no_child? body.kind_of?(NullNode) end
converts an Element without id to TextElement to make tree low for performance.
A pre-formatted Node tree will be expanded faster than original. But, it produces the same output .
# File lib/amrita/format.rb, line 527 def pre_format(formatter, expand_attr=false) raise "pre_format dose not suport pretty-print" if formatter.kind_of?(PrettyPrintFormatter) prf = PreFormatter.new(formatter, expand_attr) prf.pre_format(self) prf end