Surface.Formatter.Phase behaviour (surface v0.7.0) View Source

A phase implementing a single "rule" for formatting code. These work as middleware between Surface.Compiler.Parser.parse and Surface.Formatter.Render.node/2 to modify node lists before they are rendered.

Some phases rely on other phases; @moduledocs should make this explicit.

For reference, the formatter operates by running these phases in the following order:

Link to this section Summary

Types

A node that takes a list of nodes and returns them back after applying a transformation

A list of nodes

Callbacks

The function implementing the phase. Returns the given nodes with the transformation applied.

Functions

Given a list of nodes, find all "element" nodes (HTML elements or Surface components) and transform children of those nodes using the given function.

Given a list of nodes, find all "element" nodes (HTML elements or Surface components) and transform children of those nodes using the given function.

Link to this section Types

Specs

node_transformer() :: (nodes() -> nodes())

A node that takes a list of nodes and returns them back after applying a transformation

Specs

A list of nodes

Link to this section Callbacks

Specs

The function implementing the phase. Returns the given nodes with the transformation applied.

Link to this section Functions

Link to this function

transform_element_children(nodes, transform)

View Source

Specs

transform_element_children(nodes(), node_transformer()) :: nodes()

Given a list of nodes, find all "element" nodes (HTML elements or Surface components) and transform children of those nodes using the given function.

Useful for recursing deeply through the entire tree of nodes.

Link to this function

transform_elements_and_descendants(nodes, transform)

View Source

Given a list of nodes, find all "element" nodes (HTML elements or Surface components) and transform children of those nodes using the given function.

Recurses deeply through the tree, unlike transform_element_children, which only affects a single layer.