Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions dom.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative 'node'
require_relative 'node_types'

class Dom

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably consider wrapping all the code in a WindowBrowser module.

attr_reader :root_node

def initialize(node)
@root_node = node
end

def self.text_node(string)
Node.new(
type: NodeTypes::Text.new(string)
)
end

def self.element_node(tag_name:, attributes: {}, children: [])
Node.new(
type: NodeTypes::Element.new(
tag_name: tag_name,
attributes: attributes
),
children: children
)
end
end
8 changes: 8 additions & 0 deletions node.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Node
attr_accessor :type, :children

def initialize(type:, children: [])
@type = type
@children = children
end
end
18 changes: 18 additions & 0 deletions node_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module NodeTypes
class Text

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should node types inherit from Node?

attr_reader :string

def initialize(string)
@string = string
end
end

class Element
attr_reader :tag_name, :attributes

def initialize(tag_name:, attributes: {})
@tag_name = tag_name
@attributes = attributes
end
end
end