A node's attributes, as carve's tree carries them.
id- the#id, ornilclasses- the.classnames, in orderkey_values- otherkey=valuepairs, in written order, as{key, value}tuples with string keys
Every function accepts nil as an empty set and returns a struct.
Summary
Functions
Appends a class.
Removes key.
Returns true for nil or an attribute set with nothing in it.
Returns the value for key: the id for "id", the classes joined with a
space for "class", and the key/value entry for anything else. Returns nil
when the key isn't set.
Sets key. "class" replaces the classes with the whitespace-split value; a
new key is appended, an existing one keeps its place.
Types
Functions
Appends a class.
iex> Markup.Carve.Attributes.add_class(%Markup.Carve.Attributes{classes: ["a"]}, "b")
%Markup.Carve.Attributes{classes: ["a", "b"]}
Removes key.
iex> Markup.Carve.Attributes.delete(%Markup.Carve.Attributes{id: "x", classes: ["a"]}, "class")
%Markup.Carve.Attributes{id: "x"}
Returns true for nil or an attribute set with nothing in it.
iex> Markup.Carve.Attributes.empty?(nil)
true
iex> Markup.Carve.Attributes.empty?(%Markup.Carve.Attributes{id: "x"})
false
Returns the value for key: the id for "id", the classes joined with a
space for "class", and the key/value entry for anything else. Returns nil
when the key isn't set.
iex> attrs = %Markup.Carve.Attributes{id: "x", classes: ["a", "b"], key_values: [{"k", "v"}]}
iex> Markup.Carve.Attributes.get(attrs, "class")
"a b"
iex> Markup.Carve.Attributes.get(attrs, "id")
"x"
iex> Markup.Carve.Attributes.get(attrs, "k")
"v"
iex> Markup.Carve.Attributes.get(nil, "class")
nil
Sets key. "class" replaces the classes with the whitespace-split value; a
new key is appended, an existing one keeps its place.
iex> Markup.Carve.Attributes.put(nil, "class", "a b")
%Markup.Carve.Attributes{classes: ["a", "b"]}
iex> Markup.Carve.Attributes.put(%Markup.Carve.Attributes{id: "x"}, "k", "v")
%Markup.Carve.Attributes{id: "x", key_values: [{"k", "v"}]}