Skip to content

Commit

Permalink
Rename Node methods: append_child insert_before insert_after
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardloveall committed Oct 7, 2018
1 parent ea3a12a commit 29d1776
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions spec/node_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -211,45 +211,45 @@ describe Myhtml::Node do
parser.root!.data.null?.should eq true
end

describe "#append" do
describe "#append_child" do
it "adds a node at the end" do
tree = Myhtml::Tree.new
parent = tree.create_node(:div)
child = tree.create_node(:a)
grandchild = tree.create_node(:span)

parent.append(child)
child.append(grandchild)
parent.append_child(child)
child.append_child(grandchild)

parent.to_html.should eq("<div><a><span></span></a></div>")
parent.children.first.tag_sym.should eq(:a)
child.children.first.tag_sym.should eq(:span)
end
end

describe "#before" do
describe "#insert_before" do
it "adds a node just prior to this node" do
document = Myhtml::Parser.new("<html><body><main></main></body></html>")
main = document.css("main").first
tree = Myhtml::Tree.new
header = tree.create_node(:header)

main.before(header)
main.insert_before(header)

body_html = "<body><header></header><main></main></body>"
document.body!.to_html.should eq body_html
end
end

describe "#after" do
describe "#insert_after" do
it "adds a node just following this node" do
html_string = "<html><body><header></header></body></html>"
document = Myhtml::Parser.new(html_string)
header = document.css("header").first
tree = Myhtml::Tree.new
main = tree.create_node(:main)

header.after(main)
header.insert_after(main)

body_html = "<body><header></header><main></main></body>"
document.body!.to_html.should eq body_html
Expand Down
10 changes: 5 additions & 5 deletions src/myhtml/node.cr
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ struct Myhtml::Node
end
end

def append(child : Node)
def append_child(child : Node)
Lib.tree_node_add_child(raw_node, child.raw_node)
end

def before(node preceding : Node)
Lib.tree_node_insert_before(raw_node, preceding.raw_node)
def insert_before(node : Node)
Lib.tree_node_insert_before(raw_node, node.raw_node)
end

def after(node following : Node)
Lib.tree_node_insert_after(raw_node, following.raw_node)
def insert_after(node : Node)
Lib.tree_node_insert_after(raw_node, node.raw_node)
end

private class IOWrapper
Expand Down

0 comments on commit 29d1776

Please sign in to comment.