Lavash.Template (Lavash v0.4.0-rc.3)

Copy Markdown View Source

Utilities for parsing HEEx templates into a small :element tree.

Provides tokenize/2 (parses to the new LV 1.2 Parser node tree) and parse/1 (converts that tree into a simpler {:element, tag, attrs, children, meta} form that the rest of lavash's compile-time analysis pipeline consumes).

Summary

Functions

Converts a LV 1.2 node tree (or %Parser{}) into the legacy :element tree shape

Parses HEEx source to the LV 1.2 node tree (%Parser{} or just the nodes list, depending on :return).

Functions

parse(nodes)

Converts a LV 1.2 node tree (or %Parser{}) into the legacy :element tree shape:

  • {:element, tag, attrs, children, meta} for HTML elements
  • {:text, content} for text nodes
  • {:expr, code, meta} for Elixir expressions

Components and slots are skipped (they aren't consumed downstream).

tokenize(source, opts \\ [])

Parses HEEx source to the LV 1.2 node tree (%Parser{} or just the nodes list, depending on :return).

Options:

  • :line - starting line number (default 1)
  • :file - source file path for error messages (default "nofile")
  • :indentation - indentation level (default 0)
  • :return - :nodes (default) returns the bare node list, :parser returns the full %Parser{} struct