Class TagTreeScanner::Tag
In: TagTreeScanner.rb
Parent: Object

Tags are the equivalent of a DOM Element. The majority of tags are created automatically by a TagFactory, but it may be necessary to create them directly in order to augment or replace information in the tag tree.

A Tag may have one or more attributes, which are pairs of key/value strings; attributes are output in the HTML or XML representation of the Tag.

Each tag also has an info hash, which may be used to keep track of extra bits of information about a tag. Example usages might be keeping track of the depth of a list item, or the associated section for a header. Information from the info hash is not output in the HTML or XML representations.

Methods

Attributes

attributes  [RW]  A hash of key/value attributes to emit in the XML/HTML representation
child_tags  [RW]  An array of child Tag or TextNode instances
factory  [RW]  The TagFactory that created this tag (may be nil)
info  [RW]  A hash that may be used to store extra information about a Tag
next_sibling  [R]  The Tag or TextNode which immediately follows this tag (may be nil if this is the last tag of its parent)
parent_tag  [R]  The Tag to which this tag is attached (may be nil)
previous_sibling  [R]  The Tag or TextNode which immediately precedes this tag (may be nil if this is the first tag of its parent)
tag_name  [RW]  A symbold with the name of this tag

Public Class methods

tag_name:A symbol with the name of this tag
attributes:A hash of key/value pairs to store with this tag

Public Instance methods

additional_text:The text to add to this node.

Appends additional_text to this tag. If the last item in the child_tags collection is a TextNode, the text is added to that item; otherwise, a new TextNode is created with additional_text and added as the last child of this tag.

Returns the allowed_genre property of the owning TagFactory, or nil if this tag wasn’t created by a factory.

Returns the allows_text property of the owning TagFactory, or true if this tag wasn’t created by a factory.

new_child:The Tag or TextNode to add as the last child.

Adds new_child to the end of this tag’s +child_tags_ collection. Returns a reference to new_child.

If new_child is a child of another Tag, it is first removed from that tag.

Returns the autoclose property of the owning TagFactory, or nil if this tag wasn’t created by a factory.

Returns the close_match property of the owning TagFactory, or nil if this tag wasn’t created by a factory.

Returns the close_requires_bol property of the owning TagFactory, or nil if this tag wasn’t created by a factory.

Returns a copy of this tag and its entire hierarchy. All descendant tags/text nodes are also cloned.

The info hash is not preserved.

Returns the text contents of this tag and its descendants.

new_child:The Tag or TextNode to add as a child of this tag.
reference_child:The child to place new_child after.

Adds new_child as a child of this tag, immediately after the location of reference_child. Returns a reference to new_child.

If reference_child is nil, the child is added as the first child of this tag. A RuntimeError is raised if reference_child is not a child of this tag.

If new_child is a child of another Tag, remove_child is automatically invoked to remove it from that tag.

new_child:The Tag or TextNode to add as a child of this tag.
reference_child:The child to place new_child before.

Adds new_child as a child of this tag, immediately before the location of reference_child. Returns a reference to new_child.

If reference_child is nil, the child is added as the last child of this tag. A RuntimeError is raised if reference_child is not a child of this tag.

If new_child is a child of another Tag, remove_child is automatically invoked to remove it from that tag.

existing_child:The Tag or TextNode to remove.

Removes existing_child from being a child of this tag. Returns existing_child.

A RuntimeError is raised if existing_child is not a child of this tag.

If new_child is a child of another Tag, remove_child is automatically invoked to remove it from that tag.

old_child:The existing child Tag or TextNode to replace.
new_child:The Tag or TextNode to replace old_child.

Replaces old_child with new_child in this collection. Returns old_child.

A RuntimeError is raised if existing_child is not a child of this tag.

If new_child is a child of another Tag, remove_child is automatically invoked to remove it from that tag.

new_child:The Tag or TextNode to replace this tag.

Replaces this tag with new_child. Returns new_child.

A RuntimeError is raised if this tag is not a child of another tag.

If new_child is a child of another Tag, remove_child is automatically invoked to remove it from that tag.

Returns an array of all descendants of this tag whose tag_name matches the supplied tag_name.

Returns an HTML representation of this tag and all its descendants.

This method is the same as to_xml except that tags without any child_tags use an explicit close tag, e.g. <div></div> instead of XML’s <div />

Returns an XML representation of this tag and all its descendants.

If empty_tags_collapsed is true (the default) then this method is the same as to_html except that tags without any child_tags use a single closed tag, e.g. <div /> instead of HTML’s <div></div>

If empty_tags_collapsed is false, this is the same as to_html.

[Validate]