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
classesattribute 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 asnamein theTransformation._available_symbols. If the object is adelb.TagNodeinstance andcopy_nodeisTrue, 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
namefrom theinxs.Transformation._available_symbolsto the log at info level.
-
inxs.lib.debug_symbols[source]¶ Logs the representation strings of the objects referenced by
namesininxs.Transformation._available_symbolsat info level.
-
inxs.lib.f(func, *args, **kwargs)[source]¶ Wraps the callable
funcwhich 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.TextNodetype.
-
inxs.lib.get_variable[source]¶ Gets the object referenced as
namefrom the context. It is then available as symbolprevious_result.
-
inxs.lib.has_attributes(node: delb.nodes.TagNode, _)[source]¶ Returns
Trueif the node has attributes.
-
inxs.lib.has_children(node: delb.nodes.TagNode, _)[source]¶ Returns
Trueif the node has descendants.
-
inxs.lib.has_matching_text[source]¶ Returns
Trueif the text contained by the node and its descendants has a matches the providedpattern.
-
inxs.lib.has_text(node: delb.nodes.TagNode, _)[source]¶ Returns
Trueif 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
nameatpositionof which onlyafteris implemented atm.It employs semantics for Font Awesome 5.
-
inxs.lib.join_to_string[source]¶ Joins the object referenced by
symbolaround the givenseparatorand 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
namesand returns a mapping with names and values. Whenignore_missingisTrueKeyErrorexceptions pass silently.
-
inxs.lib.put_variable[source]¶ Puts
value``as ``nameto 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
namesfrom 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_childrenis passed asTrue, or only the contained text whenpreserve_textis passed asTrue. The reference list is cleared afterwards ifclear_refisTrue.
-
inxs.lib.rename_attributes(translation_map: Mapping[str, str]) → Callable[source]¶ Renames the attributes of a node according to the provided
translation_mapthat 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
nameswith 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.Transformationis called.
-
inxs.lib.set_text[source]¶ Sets the nodes’s first child node that is of
delb.TextNodetype 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
namein the context usingkeyas key function.