# File lib/amrita/node_expand.rb, line 267def expand(data, context=DefaultContext.clone)
case data
whentrueselfwhennil, false
Null
when DictionaryData
expand1(data, context)
else
raise "Amrita::Node#expand accepts only Hash or ExpandByMember as model data (#{data.type} was passed)"
endend
expand1(data, context=DefaultContext.clone)
# File lib/amrita/node_expand.rb, line 280def expand1(data, context=DefaultContext.clone)
data.amrita_expand_node(self, context)
end
amrita_expand_node(n, context)
# File lib/amrita/node_expand.rb, line 288def amrita_expand_node(n, context)
selfend
apply_to_children(&block)
# File lib/amrita/node_expand.rb, line 292def apply_to_children(&block)
selfend
init_body(&block) {|| ...}
set the block 's result to body
# File lib/amrita/node.rb, line 179def init_body(&block)
if block_given?
@body = to_node(yield)
else
@body = Null
endend
body()
a Node has NullNode as body before init_body was called.
# File lib/amrita/node.rb, line 188def body
ifdefined? @body
@body
else
Null
endend
no_child?()
test if it has any children
# File lib/amrita/node.rb, line 197def no_child?
body.kind_of?(NullNode)
end
children()
return an Array of child Node or an empty Array if
it does not have a body
# File lib/amrita/node.rb, line 202def children
if no_child?
[]
else
[ body ]
endend
# File lib/amrita/node.rb, line 211def to_node(n)
case n
whennil, false
Null
when Node
n
when Array
case n.size()
when 0
Null
when 1
to_node(n[0])
else
NodeArray.new(*n)
endelse
TextElement.new(n.to_s)
endend
hid()
# File lib/amrita/node.rb, line 232def hid
nilend
inspect()
# File lib/amrita/node.rb, line 236def inspect
to_ruby
end
# File lib/amrita/node.rb, line 278def has_id_element?
each_node do |n|
nextunless n.kind_of?(Element)
nextunless n.hid
returntrueendfalseend
to_s()
# File lib/amrita/format.rb, line 516def to_s
ret = ""
SingleLineFormatter.new(ret).format(self)
ret
end
pre_format(formatter, expand_attr=false)
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 527def 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
pre_format1(prf)
# File lib/amrita/format.rb, line 534def pre_format1(prf)
prf << selfend
compile(compiler)
# File lib/amrita/compiler.rb, line 68def compile(compiler)
compiler << to_s
end
generate_hint_from_template()
# File lib/amrita/compiler.rb, line 72def generate_hint_from_template
hash = {}
each_element_with_id do |e|
hash[e.hid.intern] = HtmlCompiler::AnyData
end
HtmlCompiler::DictionaryHint.new(hash)
end