Readmix.Context (readmix v0.8.1)

Copy Markdown

Helpers to access the context in generator actions.

Summary

Functions

Raises a Readmix.Error from within a generator action.

Returns a function that reads the given var from the given context.

Returns a section from the current rendering context at the same nesting level.

Types

t()

@type t() :: %Readmix.Context{
  block: term(),
  previous_content: term(),
  readmix: term(),
  siblings: term()
}

Functions

error!(context, reason)

@spec error!(t(), term()) :: no_return()

Raises a Readmix.Error from within a generator action.

The error is tagged with the location of the block currently being rendered, so the reported message points back to the offending tag in the source file.

getter(context, key)

Returns a function that reads the given var from the given context.

The returned function with throw {:undef_var, key} if the variable is not defined.

lookup_rendered_section(context, section_name)

Returns a section from the current rendering context at the same nesting level.

This function can only retrieve sections that are defined above the calling generated block. If multiple sections share the same name, it will return the closest section, .i.e the last one in file order.