Class | Amrita::NodeArray |
In: |
lib/amrita/node_expand.rb
lib/amrita/format.rb lib/amrita/node.rb |
Parent: | Object |
# File lib/amrita/node.rb, line 607 def initialize(*elements) if elements.size() == 1 and elements[0].kind_of?(NodeArray) @array = elements[0].to_a.collect {|n| n.clone} else @array = elements.collect do |a| #raise "can't be a parent of me!" if a.id == self.id # no recusive check because it costs too much to_node(a) end end end
# File lib/amrita/node.rb, line 678 def <<(node) raise "can't be a parent of me!" if node.equal?(self) case node when Array, NodeArray node.each {|n| self << n } when Node @array << node else @array << TextElement.new(node.to_s) end self end
# File lib/amrita/node.rb, line 618 def ==(x) case x when NodeArray, Array return false unless x.size() == @array.size() @array.each_with_index do |n, i| return false unless n == x[i] end true else false end end
# File lib/amrita/node_expand.rb, line 352 def apply_to_children(hash, context) ret = [] hid = context.tmpl_id nodes = to_a() while nodes.size > 0 n = nodes.shift if n.is_a?(Element) && n.multi && n.multi.alt && (ary = hash[n.attrs[hid].value.intern]).is_a?(Array) # 配列を交互に展開する # self = <table> # n = <tr amrita_id="foo+"> # hash["foo"] = ["a", "b", ...] alt_id = n.attrs[hid].value alt_e = [n] while (nodes.first.is_a?(Element) && nodes.first.attrs[hid].value == alt_id) || (nodes.first.is_a?(TextElement) && nodes.first.to_s.strip == "") f = nodes.shift alt_e << f if f.is_a?(Element) end ary.each_with_index {|data, i| ret << alt_e[i % alt_e.size].clone.delete_attr!(hid).expand1(data, context) } else ret << yield(n) end end Node::to_node(ret) end
# File lib/amrita/node.rb, line 647 def elements_with_attr(key, value = nil) raise TypeError if !key.is_a?(Symbol) ret = [] @array.each {|node| if node.is_a?(Element) && (v = node.attrs[key]) if value && v == value ret << node end end } return ret end