A node's attributes, as carve's AST carries them.
id- the#id, ornilclasses- the.classnames, in orderkey_values- otherkey=valuepairs (string keys)order- the written order of the slots, as"#id",".class"or a key name;[]when not recorded. Used byCarvex.to_carve/2.
Every function accepts nil as an empty set and returns a struct.
Summary
Functions
Appends a class.
Removes key.
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", otherwise the key/value entry. nil when absent.
Sets key. "class" replaces the classes with the whitespace-split value.
Types
Functions
Appends a class.
iex> Carvex.Attributes.add_class(%Carvex.Attributes{classes: ["a"]}, "b")
%Carvex.Attributes{classes: ["a", "b"]}
Removes key.
iex> Carvex.Attributes.delete(%Carvex.Attributes{id: "x", classes: ["a"], order: ["#id", ".class"]}, "class")
%Carvex.Attributes{id: "x", order: ["#id"]}
True for nil or an attribute set with nothing in it.
iex> Carvex.Attributes.empty?(nil)
true
iex> Carvex.Attributes.empty?(%Carvex.Attributes{id: "x"})
false
Returns the value for key: the id for "id", the classes joined with a
space for "class", otherwise the key/value entry. nil when absent.
iex> attrs = %Carvex.Attributes{id: "x", classes: ["a", "b"], key_values: %{"k" => "v"}}
iex> Carvex.Attributes.get(attrs, "class")
"a b"
iex> Carvex.Attributes.get(attrs, "id")
"x"
iex> Carvex.Attributes.get(attrs, "k")
"v"
iex> Carvex.Attributes.get(nil, "class")
nil
Sets key. "class" replaces the classes with the whitespace-split value.
iex> Carvex.Attributes.put(nil, "class", "a b")
%Carvex.Attributes{classes: ["a", "b"]}
iex> Carvex.Attributes.put(%Carvex.Attributes{id: "x", order: ["#id"]}, "k", "v")
%Carvex.Attributes{id: "x", key_values: %{"k" => "v"}, order: ["#id", "k"]}