class

Marten::Template::Condition

Inherits Reference / Object

A template condition.

Condition expressions such as "var1 || var2" are parsed and evaluated using this abstraction.

context = Marten::Template::Context{"var1" => nil, "var2" => "42"}
Marten::Template::Condition.new(["var1", "||", "var2"]).parse.eval(context).truthy? # => true

Constructors

new(parts : Array(String))
Source

Instance methods

expression(rbp) : Token::Base

Consumes condition tokens until a token with a left binding power equal or lower than rbp is found.

This method acts as the main entrypoint for the condition parser's top-down operator precedence parsing algorithm (TDOP).

Source
parse

Returns the condition token corresponding to the condition expression.

The returned condition token can then be evaluated for a given template context.

Source

Nested types