Sablon.Configuration (sablon v0.4.3)

Copy Markdown View Source

Global, mutable configuration for HTML conversion.

Mirrors the Sablon::Configuration singleton of the Ruby gem: it stores the set of permitted HTML tags and the CSS -> WordML property converters, both of which can be extended or replaced at runtime.

Sablon.configure(fn ->
  Sablon.Configuration.register_html_tag(:bgcyan, :inline, properties: [highlight: "cyan"])
end)

Summary

Functions

Returns a specification to start this module under a supervisor.

Runs the converter registered for ast_node/prop_name on value.

The tag table sablon starts with.

The CSS -> WordML converters sablon starts with.

All registered style converters, keyed by AST node name.

Looks up a tag definition, returning nil when it is not registered.

Returns the full configuration state.

All permitted HTML tags, keyed by tag name.

Adds a tag definition or replaces an existing one.

Registers a CSS property converter for an AST node.

Removes a tag definition, returning it.

Removes a CSS property converter.

Restores the built-in defaults, discarding every customisation.

The converters registered for a single AST node, e.g. :run.

Types

style_converter()

@type style_converter() :: (term() -> {binary() | atom(), term()} | nil | term())

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

convert(ast_node, prop_name, value)

@spec convert(atom(), binary() | atom(), term()) :: term()

Runs the converter registered for ast_node/prop_name on value.

Built-in converters use this for the shared helpers (:_border, :_sz), so overriding a helper also changes every converter that builds on it.

default_html_tags()

@spec default_html_tags() :: %{required(atom()) => Sablon.Configuration.HTMLTag.t()}

The tag table sablon starts with.

default_style_conversions()

@spec default_style_conversions() :: map()

The CSS -> WordML converters sablon starts with.

defined_style_conversions()

@spec defined_style_conversions() :: map()

All registered style converters, keyed by AST node name.

html_tag(name)

@spec html_tag(atom() | binary()) :: Sablon.Configuration.HTMLTag.t() | nil

Looks up a tag definition, returning nil when it is not registered.

instance()

@spec instance() :: map()

Returns the full configuration state.

permitted_html_tags()

@spec permitted_html_tags() :: %{required(atom()) => Sablon.Configuration.HTMLTag.t()}

All permitted HTML tags, keyed by tag name.

register_html_tag(name, type \\ :inline, options \\ [])

@spec register_html_tag(atom() | binary(), :inline | :block, keyword()) ::
  Sablon.Configuration.HTMLTag.t()

Adds a tag definition or replaces an existing one.

register_style_converter(ast_node, prop_name, converter)

@spec register_style_converter(atom(), binary() | atom(), style_converter()) :: :ok

Registers a CSS property converter for an AST node.

ast_node is the AST class name in lowercased snake case (Run -> :run), prop_name the CSS property and converter a one-argument function returning a {wordml_property, value} tuple.

remove_html_tag(name)

@spec remove_html_tag(atom() | binary()) :: Sablon.Configuration.HTMLTag.t() | nil

Removes a tag definition, returning it.

remove_style_converter(ast_node, prop_name)

@spec remove_style_converter(atom(), binary() | atom()) :: :ok

Removes a CSS property converter.

reset()

@spec reset() :: :ok

Restores the built-in defaults, discarding every customisation.

style_conversions(ast_node)

@spec style_conversions(atom()) :: map()

The converters registered for a single AST node, e.g. :run.