Documentation
¶
Overview ¶
Package liquid is a pure-Go (CGO-free) reimplementation of Shopify's Ruby Liquid template engine. It parses a Liquid source template and renders it against a set of assigns, matching the rendered output of the `liquid` gem.
The entry point mirrors the gem's API:
tmpl, err := liquid.Parse(src) // Liquid::Template.parse(src) out, err := tmpl.Render(assigns) // tmpl.render(assigns) out, err := tmpl.RenderStrict(assigns) // tmpl.render!(assigns) — raises
Value model ¶
Assigns are an ordinary Go value tree; the engine accepts and produces the small, fixed set of Go types a host (such as go-embedded-ruby) maps to and from its own object graph:
Ruby Go ---- -- nil nil true / false bool Integer int, int64 Float float64 String string Array []any Hash map[string]any Drop Drop (LiquidValue / context-aware lookups)
Render walks the parsed tree and writes a string, so a host binds object.Value to and from these Go shapes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Drop ¶
Drop is the interface a host object may implement to expose context-aware member lookups to templates (the gem's Liquid::Drop). LiquidGet returns the value for a member name and whether it is defined.
type Error ¶
Error is a Liquid error. Type names the gem error class (SyntaxError, ArgumentError, ZeroDivisionError, …) and Message is the rendered text. In Lax mode a runtime Error renders inline as "Liquid error: <Message>".
type ErrorMode ¶
type ErrorMode int
ErrorMode selects how parse and render errors are surfaced.
const ( // Lax swallows recoverable errors, rendering an inline "Liquid error: …" // message in their place (the gem's default at render time). Lax ErrorMode = iota // Warn behaves like Lax but also collects the errors on the template. Warn // Strict turns recoverable parse/render errors into a returned error. Strict )
type Filter ¶
Filter is a host-supplied filter implementation. It receives the piped input value and the already-evaluated positional arguments, and returns the transformed value. Returning a non-nil error surfaces through the active ErrorMode exactly like a built-in filter failure.
Custom filters let a host (for example a Jekyll front-end) extend the filter vocabulary — relative_url, jsonify, slugify, … — without forking the engine. A registered name takes precedence over a built-in of the same name.
type Option ¶
type Option func(*parseConfig)
Option configures Parse.
func WithErrorMode ¶
WithErrorMode selects the parse/render error mode (default Lax).
func WithFilter ¶
WithFilter registers a single custom Filter under name. It may be passed to Parse more than once and combines with WithFilters.
func WithFilters ¶
WithFilters registers a set of custom filters in one call. Later registrations (including a subsequent WithFilter) override earlier ones for the same name.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a parsed Liquid template ready to render.
func Parse ¶
Parse compiles a Liquid source template. It mirrors Liquid::Template.parse(src). A syntax error is returned only in Strict mode; in Lax/Warn mode parse never fails and malformed constructs render as inline errors.
func (*Template) Errors ¶
Errors returns the errors collected during the most recent Render (Lax/Warn mode), mirroring template.errors in the gem.
