Array of Attr s. It can
hold body part for using as a model data for Node#expand.
Amrita#a() method is a shortcut for Attr.new
:array |
[R] |
If you call a() { ... }, block yields to body
|
:body |
[R] |
If you call a() { ... }, block yields to body
|
:shared |
[RW] |
internal use only, never touch it!
true if this instance is shared by two or more elements
|
Enumerable
new(*attrs, &block) {|| ...}
|
# File lib/amrita/node.rb, line 94
def initialize(*attrs, &block)
@array = []
@shared = false
attrs.each do |a|
case a
when Array, AttrArray
a.each do |aa|
self << aa
end
when Hash
attrs[0].each do |k, v|
self << Attr.new(k, v)
end
else
self << a
end
end
if block_given?
@body = yield
else
@body = Null
end
end
amrita_expand_node(n, context)
|
# File lib/amrita/node_expand.rb, line 258
def amrita_expand_node(n, context)
raise Amrita::ModelMisMatch(type, n.type)
end
# File lib/amrita/node.rb, line 120
def ==(x)
return true if id == x.id
return false unless x.kind_of?(AttrArray)
each_with_index do |a, n|
return false unless a == x[n]
end
true
end
# File lib/amrita/node.rb, line 129
def inspect
to_ruby
end
# File lib/amrita/node.rb, line 134
def <<(a)
raise "must be Attr not #{a.class}" unless a.kind_of?(Attr)
@array << a
end
# File lib/amrita/node.rb, line 139
def clear
@array.clear
end
# File lib/amrita/node.rb, line 143
def [](index)
@array[index]
end
# File lib/amrita/node.rb, line 147
def []=(index, val)
@array[index] = val
val
end
# File lib/amrita/node.rb, line 153
def each(&block)
@array.each(&block)
end
# File lib/amrita/node.rb, line 157
def size
@array.size
end
# File lib/amrita/node.rb, line 161
def to_ruby
ret = "a(" + @array.collect {|a| ":#{a.key}, #{a.value}"}.join(", ") + ")"
case @body
when nil, Null
when Node
ret += body.to_ruby
else
ret += body.inspect
end
ret
end
# File lib/amrita/compiler.rb, line 58
def amrita_generate_hint
if body
Amrita::HtmlCompiler::AttrData[body.amrita_generate_hint]
else
Amrita::HtmlCompiler::AttrData.new
end
end