Parent

Class/Module Index [+]

Quicksearch

HTML5::TreeBuilders::Base::TreeBuilder

Base treebuilder implementation

Attributes

activeFormattingElements[RW]
document[RW]
formPointer[RW]
head_pointer[RW]
open_elements[RW]

Public Class Methods

new() click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 104
def initialize
  reset
end

Public Instance Methods

clearActiveFormattingElements() click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 184
def clearActiveFormattingElements
  {} until @activeFormattingElements.empty? || @activeFormattingElements.pop == Marker
end
createElement(name, attributes) click to toggle source

Create an element but don't insert it anywhere

# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 214
def createElement(name, attributes)
  element = @elementClass.new(name)
  element.attributes = attributes
  return element
end
elementInActiveFormattingElements(name) click to toggle source

Check if an element exists between the end of the active formatting elements and the last marker. If it does, return it, else return false

# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 191
def elementInActiveFormattingElements(name)
  @activeFormattingElements.reverse.each do |element|
    # Check for Marker first because if it's a Marker it doesn't have a
    # name attribute.
    break if element == Marker
    return element if element.name == name
  end
  return false
end
elementInScope(target, tableVariant=false) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 121
def elementInScope(target, tableVariant=false)
  # Exit early when possible.
  return true if @open_elements[-1].name == target

  # AT How about while true and simply set node to [-1] and set it to
  # [-2] at the end...
  @open_elements.reverse.each do |element|
    if element.name == target
      return true
    elsif element.name == 'table'
      return false
    elsif not tableVariant and SCOPING_ELEMENTS.include?(element.name)
      return false
    elsif element.name == 'html'
      return false
    end
  end
  assert false # We should never reach this point
end
generateImpliedEndTags(exclude=nil) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 302
def generateImpliedEndTags(exclude=nil)
  name = @open_elements[-1].name

  # XXX td, th and tr are not actually needed
  if (]dd dt li p td th tr].include?(name) and name != exclude)
    @open_elements.pop
    # XXX This is not entirely what the specification says. We should
    # investigate it more closely.
    generateImpliedEndTags(exclude)
  end
end
getTableMisnestedNodePosition() click to toggle source

Get the foster parent element, and sibling to insert before (or nil) when inserting a misnested table node

# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 274
def getTableMisnestedNodePosition
  #The foster parent element is the one which comes before the most
  #recently opened table element
  #XXX - this is really inelegant
  lastTable = nil
  fosterParent = nil
  insertBefore = nil
  @open_elements.reverse.each do |element|
    if element.name == "table"
      lastTable = element
      break
    end
  end
  if lastTable
    #XXX - we should really check that this parent is actually a
    #node here
    if lastTable.parent
      fosterParent = lastTable.parent
      insertBefore = lastTable
    else
      fosterParent = @open_elements[@open_elements.index(lastTable) - 1]
    end
  else
    fosterParent = @open_elements[0]
  end
  return fosterParent, insertBefore
end
get_document() click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 314
def get_document
  @document
end
get_fragment() click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 318
def get_fragment
  #assert @inner_html
  fragment = @fragmentClass.new
  @open_elements[0].reparentChildren(fragment)
  return fragment
end
insertDoctype(name, public_id, system_id) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 201
def insertDoctype(name, public_id, system_id)
  doctype = @doctypeClass.new(name)
  doctype.public_id = public_id
  doctype.system_id = system_id
  @document.appendChild(doctype)
end
insertText(data, parent=nil) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 259
def insertText(data, parent=nil)
  parent = @open_elements[-1] if parent.nil?

  if (not(@insert_from_table) or (@insert_from_table and not TABLE_INSERT_MODE_ELEMENTS.include?(@open_elements[-1].name)))
    parent.insertText(data)
  else
    #We should be in the InTable mode. This means we want to do
    #special magic element rearranging
    parent, insertBefore = getTableMisnestedNodePosition
    parent.insertText(data, insertBefore)
  end
end
insert_comment(data, parent=nil) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 208
def insert_comment(data, parent=nil)
  parent = @open_elements[-1] if parent.nil?
  parent.appendChild(@commentClass.new(data))
end
insert_element(name, attributes) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 227
def insert_element(name, attributes)
  send(@insert_element, name, attributes)
end
insert_elementNormal(name, attributes) click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 231
def insert_elementNormal(name, attributes)
  element = @elementClass.new(name)
  element.attributes = attributes
  @open_elements.last.appendChild(element)
  @open_elements.push(element)
  return element
end
insert_elementTable(name, attributes) click to toggle source

Create an element and insert it into the tree

# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 240
def insert_elementTable(name, attributes)
  element = @elementClass.new(name)
  element.attributes = attributes
  if TABLE_INSERT_MODE_ELEMENTS.include?(@open_elements.last.name)
    #We should be in the InTable mode. This means we want to do
    #special magic element rearranging
    parent, insertBefore = getTableMisnestedNodePosition
    if insertBefore.nil?
      parent.appendChild(element)
    else
      parent.insertBefore(element, insertBefore)
    end
    @open_elements.push(element)
  else
    return insert_elementNormal(name, attributes)
  end
  return element
end
insert_from_table=(value) click to toggle source

Switch the function used to insert an element from the normal one to the misnested table one and back again

# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 222
def insert_from_table=(value)
  @insert_from_table = value
  @insert_element = value ? :insert_elementTable : :insert_elementNormal
end
reconstructActiveFormattingElements() click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 141
def reconstructActiveFormattingElements
  # Within this algorithm the order of steps described in the
  # specification is not quite the same as the order of steps in the
  # code. It should still do the same though.

  # Step 1: stop the algorithm when there's nothing to do.
  return if @activeFormattingElements.empty?

  # Step 2 and step 3: we start with the last element. So i is -1.
  i = -1
  entry = @activeFormattingElements[i]
  return if entry == Marker or @open_elements.include?(entry)

  # Step 6
  until entry == Marker or @open_elements.include?(entry)
    # Step 5: let entry be one earlier in the list.
    i -= 1
    begin
      entry = @activeFormattingElements[i]
    rescue
      # Step 4: at this point we need to jump to step 8. By not doing
      # i += 1 which is also done in step 7 we achieve that.
      break
    end
  end
  while true
    # Step 7
    i += 1

    # Step 8
    clone = @activeFormattingElements[i].cloneNode

    # Step 9
    element = insert_element(clone.name, clone.attributes)

    # Step 10
    @activeFormattingElements[i] = element

    # Step 11
    break if element == @activeFormattingElements[-1]
  end
end
reset() click to toggle source
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 108
def reset
  @open_elements = []
  @activeFormattingElements = []

  #XXX - rename these to headElement, formElement
  @head_pointer = nil
  @formPointer = nil

  self.insert_from_table = false

  @document = @documentClass.new
end
testSerializer(node) click to toggle source

Serialize the subtree of node in the format required by unit tests node - the node from which to start serializing

# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/base.rb, line 327
def testSerializer(node)
  raise NotImplementedError
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.