Initial rough sketches for the DOM API.
This commit is contained in:
parent
6c661f3ee9
commit
6ae52c1b12
|
@ -4,5 +4,8 @@ require_relative 'oga/ast/node'
|
|||
|
||||
require_relative 'oga/xml/lexer'
|
||||
require_relative 'oga/xml/parser'
|
||||
require_relative 'oga/xml/node'
|
||||
require_relative 'oga/xml/element'
|
||||
require_relative 'oga/xml/builder'
|
||||
|
||||
require_relative 'oga/html/parser'
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
module Oga
|
||||
module XML
|
||||
##
|
||||
# Class for building a DOM tree of XML/HTML nodes.
|
||||
#
|
||||
# @!attribute [r] ast
|
||||
# @return [Oga::AST::Node]
|
||||
#
|
||||
class Builder < ::AST::Processor
|
||||
attr_reader :ast
|
||||
|
||||
##
|
||||
# @param [Oga::AST::Node] ast
|
||||
#
|
||||
def initialize(ast)
|
||||
@ast = ast
|
||||
end
|
||||
|
||||
def on_element(node)
|
||||
|
||||
end
|
||||
|
||||
def on_text(node)
|
||||
|
||||
end
|
||||
end # Builder
|
||||
end # XML
|
||||
end # Oga
|
|
@ -0,0 +1,19 @@
|
|||
module Oga
|
||||
module XML
|
||||
##
|
||||
# Class that contains information about an XML element such as the name,
|
||||
# attributes and child nodes.
|
||||
#
|
||||
class Element < Node
|
||||
##
|
||||
# @param [String] name The name of the element
|
||||
# @see Oga::XML::Node#initialize
|
||||
#
|
||||
def initialize(name, options = {})
|
||||
super(options)
|
||||
|
||||
@name = name
|
||||
end
|
||||
end # Element
|
||||
end # XML
|
||||
end # Oga
|
|
@ -0,0 +1,36 @@
|
|||
module Oga
|
||||
module XML
|
||||
##
|
||||
# @!attribute [r] parent
|
||||
# @return [Oga::XML::Node]
|
||||
#
|
||||
# @!attribute [r] children
|
||||
# @return [Array<Oga::XML::Node>]
|
||||
#
|
||||
# @!attribute [r] next
|
||||
# @return [Oga::XML::NOde]
|
||||
#
|
||||
# @!attribute [r] previous
|
||||
# @return [Oga::XML::Node]
|
||||
#
|
||||
class Node
|
||||
attr_reader :parent, :children, :next, :previous
|
||||
|
||||
##
|
||||
# @param [Hash] options
|
||||
#
|
||||
# @option options [Array] :children The child nodes of the current
|
||||
# element.
|
||||
#
|
||||
# @option options [Oga::XML::Node] :parent The parent node.
|
||||
# @option options [Oga::XML::Node] :next The following node.
|
||||
# @option options [Oga::XML::Node] :previous The previous node.
|
||||
#
|
||||
def initialize(options = {})
|
||||
options.each do |key, value|
|
||||
instance_variable_set("@#{key}", value) if respond_to?(key)
|
||||
end
|
||||
end
|
||||
end # Element
|
||||
end # XML
|
||||
end # Oga
|
Loading…
Reference in New Issue