Surface.Formatter.Phase behaviour (SurfaceFormatter v0.2.2) View Source

A phase implementing a single "rule" for formatting code. These work as middleware between Surface.Compiler.Parser.parse/1 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

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.

Callbacks

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

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 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 section Callbacks

Specs

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