Module Amrita::ElementCommon
|
|
Node
# File lib/amrita/node.rb, line 420
def tag
tag_symbol.to_s
end
# File lib/amrita/node.rb, line 425
def clone(&block)
Element.new(self, &block)
end
# File lib/amrita/node.rb, line 429
def dup(&block)
Element.new(self, &block)
end
apply_to_children(&block) {|body| ...}
|
# File lib/amrita/node.rb, line 433
def apply_to_children(&block)
clone { yield(body) }
end
# File lib/amrita/node.rb, line 439
def amrita_id
if hide_amrita_id
nil
else
self[:id] or self[:ID]
end
end
# File lib/amrita/node.rb, line 448
def tagclass
self[:class]
end
# File lib/amrita/node.rb, line 453
def put_attr(a, &block)
copy_on_write
attrs << a
init_body(&block) if block_given?
self
end
test if it has attribule for key
# File lib/amrita/node.rb, line 463
def include_attr?(key)
attrs.attr_by_key(key.intern) != nil
end
return attribule value for key
# File lib/amrita/node.rb, line 488
def [](key)
attrs.value_by_key(key.intern)
end
set attribule. delete it if value is nil
# File lib/amrita/node.rb, line 493
def []=(key, value)
copy_on_write
key = key.intern
a = attrs.attr_by_key(key)
if a
if value
a.value = value
else
delete_attr!(key)
end
else
put_attr(Attr.new(key,value)) if value
end
value
end
# File lib/amrita/node.rb, line 510
def delete_attr!(key)
key = key.intern
attrs.array.delete_if { |x| x.key_symbol == key }
end
# File lib/amrita/node.rb, line 515
def to_ruby
ret = "e(#{tag_symbol.to_ruby}"
if attrs.size > 0
ret << ","
ret << attrs.collect { |a| "#{a.key_symbol.to_ruby}=>#{a.value.inspect}" }.join(",")
end
ret << ") "
ret << "{ #{body.to_ruby} }" if body and not body.kind_of?(NullNode)
ret
end
each_element_with_id(recursive=false, &block) {|self| ...}
|
# File lib/amrita/node.rb, line 526
def each_element_with_id(recursive=false, &block)
if amrita_id
yield(self)
super if recursive
else
super
end
end
set the text to body of this Element.
# File lib/amrita/node.rb, line 536
def set_text(text)
init_body { text }
end
# File lib/amrita/node.rb, line 540
def simple_span?
tag_symbol == :span and attrs.size == 1 and attrs.keys == [:id] and
(no_child? or (body.kind_of?(TextElement)))
end