Skip to content

Commit

Permalink
can remove child and attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAlphaFox committed Feb 15, 2019
1 parent 33a2a5e commit e219bc6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/ai_dom_node.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
-module(ai_dom_node).

-export([new/0,new/1,new/2]).
-export([insert_child/3,append_child/2,append_children/2,children/1]).
-export([insert_attribute/3,insert_attributes/2, attribute/2,attributes/1]).
-export([insert_child/3,append_child/2,remove_child/2,
append_children/2,remove_children/1,children/1]).
-export([insert_attribute/3,insert_attributes/2,remove_attribute/2,
attribute/2,remove_attributes/1, attributes/1]).
-export([set_value/2,set_id/2,set_tag/2,value/1,id/1,tag/1]).

-record(ai_dom_node,{
Expand Down Expand Up @@ -44,6 +46,12 @@ append_child(Child,Node)->
Node#ai_dom_node{
children = lists:append(Node#ai_dom_node.children,[Child])
}.
remove_child(Index,Node)->
{CHead,[_I|CTail]} = lists:split(Index,Node#ai_dom_node.children),
Node#ai_dom_node{
children = lists:append(CHead,CTail)
}.
remove_children(Node)-> Node#ai_dom_node{children = []}.
append_children(Children,Node)->
Node#ai_dom_node{
children = lists:append(Node#ai_dom_node.children,Children)
Expand All @@ -54,10 +62,18 @@ insert_attribute(Name,Value,Node)->
Node#ai_dom_node{
attributes = maps:put(Name,Value,Node#ai_dom_node.attributes)
}.
remove_attribute(Name,Node)->
Node#ai_dom_node{
attributes = maps:remove(Name,Node#ai_dom_node.attributes)
}.
insert_attributes(Attributes,Node)->
Node#ai_dom_node{
attributes = maps:merge(Attributes,Node#ai_dom_node.attributes)
}.
remove_attributes(Node)->
Node#ai_dom_node{
attributes = maps:new()
}.
attribute(Name,Node)->
Attributes = Node#ai_dom_node.attributes,
maps:get(Name,Attributes,undefined).
Expand Down

0 comments on commit e219bc6

Please sign in to comment.