inxs.lib module¶
This module contains common functions that can be used for either Rule
s’ tests, as handler functions or simple transformation steps.
Community contributions are highly appreciated, but it’s hard to layout hard criteria for what belongs here and what not. In doubt open a pull request with your proposal as far as it proved functional to you, it doesn’t need to be polished at that point.
-
inxs.lib.
add_html_classes
[source]¶ Adds the string tokens passed as positional arguments to the
classes
attribute of a node specified bytarget
. An argument can also be a sequence of strings or aRef()
that yields on of the two. Per default that is aRef()
to the matching node of a rule.
-
inxs.lib.
append
[source]¶ Appends the object referenced by
symbol
(default: the result of the previous handler function) to the object available asname
in theTransformation._available_symbols
. If the object is adelb.TagNode
instance andcopy_node
isTrue
, a copy that includes all descendant nodes is appended to the target.
-
inxs.lib.
cleanup_namespaces
(root: delb.nodes.TagNode, previous_result: Any) → Any[source]¶ Cleanup the namespaces of the tree. This should always be used at the end of a transformation when nodes’ namespaces have been changed.
-
inxs.lib.
clear_attributes
(node: delb.nodes.TagNode, previous_result: Any) → Any[source]¶ Deletes all attributes of an node.
-
inxs.lib.
concatenate
[source]¶ Concatenate the given parts which may be lists or strings as well as callables returning such.
-
inxs.lib.
debug_dump_document
[source]¶ Dumps all contents of the node referenced by
name
from theinxs.Transformation._available_symbols
to the log at info level.
-
inxs.lib.
debug_symbols
[source]¶ Logs the representation strings of the objects referenced by
names
ininxs.Transformation._available_symbols
at info level.
-
inxs.lib.
f
(func, *args, **kwargs)[source]¶ Wraps the callable
func
which will be called asfunc(*args, **kwargs)
, the function and any argument can be given asinxs.Ref()
.
-
inxs.lib.
get_text
(node: delb.nodes.TagNode)[source]¶ Returns the content of the matched node’s descendants of
delb.TextNode
type.
-
inxs.lib.
get_variable
[source]¶ Gets the object referenced as
name
from the context. It is then available as symbolprevious_result
.
-
inxs.lib.
has_attributes
(node: delb.nodes.TagNode, _)[source]¶ Returns
True
if the node has attributes.
-
inxs.lib.
has_children
(node: delb.nodes.TagNode, _)[source]¶ Returns
True
if the node has descendants.
-
inxs.lib.
has_matching_text
[source]¶ Returns
True
if the text contained by the node and its descendants has a matches the providedpattern
.
-
inxs.lib.
has_text
(node: delb.nodes.TagNode, _)[source]¶ Returns
True
if the node has anydelb.TextNode
.
-
inxs.lib.
insert_fontawesome_icon
[source]¶ Inserts the html markup for an icon from the fontawesome set with the given
name
atposition
of which onlyafter
is implemented atm.It employs semantics for Font Awesome 5.
-
inxs.lib.
join_to_string
[source]¶ Joins the object referenced by
symbol
around the givenseparator
and returns it.
-
inxs.lib.
make_node
(**node_args)[source]¶ Creates a new tag node in the root node’s context, takes the arguments of
delb.TagNode.new_tag_node()
that must be provided as keyword arguments. The node is then available as symbolprevious_result
.
-
inxs.lib.
pop_attributes
[source]¶ Pops all attributes with name from
names
and returns a mapping with names and values. Whenignore_missing
isTrue
KeyError
exceptions pass silently.
-
inxs.lib.
put_variable
[source]¶ Puts
value``as ``name
to the context namespace, by default the value is determined by ainxs.Ref()
toprevious_result
.
-
inxs.lib.
remove_attributes
[source]¶ Removes all attributes with the keys provided as
names
from the node.
-
inxs.lib.
remove_namespace
(node: delb.nodes.TagNode, previous_result)[source]¶ Removes the namespace from the node. When used,
cleanup_namespaces()
should be applied at the end of the transformation.
-
inxs.lib.
remove_node
(node: delb.nodes.TagNode)[source]¶ A very simple handler that just removes a node and its descendants from a tree.
-
inxs.lib.
remove_nodes
[source]¶ Removes all nodes from their tree that are referenced in a list that is available as
references
. The nodes’ children are retained whenkeep_children
is passed asTrue
, or only the contained text whenpreserve_text
is passed asTrue
. The reference list is cleared afterwards ifclear_ref
isTrue
.
-
inxs.lib.
rename_attributes
(translation_map: Mapping[str, str]) → Callable[source]¶ Renames the attributes of a node according to the provided
translation_map
that consists of old name keys and new name values.
-
inxs.lib.
resolve_xpath_to_node
[source]¶ Resolves the objects from the context namespace (which are supposed to be XPath expressions) referenced by
names
with the one node that the expression matches orNone
. This is useful when a copied tree is processed and ‘XPath pointers’ are passed to the context when ainxs.Transformation
is called.
-
inxs.lib.
set_text
[source]¶ Sets the nodes’s first child node that is of
delb.TextNode
type to the one provided astext
, it can also be ainxs.Ref()
. If the first node isn’t a text node, one will be inserted.
-
inxs.lib.
sort
[source]¶ Sorts the object referenced by
name
in the context usingkey
as key function.