class Marten::Template::Condition

Overview

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

Defined in:

marten/template/condition.cr
marten/template/condition/token/base.cr
marten/template/condition/token/end.cr
marten/template/condition/token/operator.cr
marten/template/condition/token/operator/and.cr
marten/template/condition/token/operator/equal.cr
marten/template/condition/token/operator/greater_than.cr
marten/template/condition/token/operator/greater_than_or_equal.cr
marten/template/condition/token/operator/in.cr
marten/template/condition/token/operator/infix.cr
marten/template/condition/token/operator/less_than.cr
marten/template/condition/token/operator/less_than_or_equal.cr
marten/template/condition/token/operator/not.cr
marten/template/condition/token/operator/not_equal.cr
marten/template/condition/token/operator/or.cr
marten/template/condition/token/operator/prefix.cr
marten/template/condition/token/value.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(parts : Array(String)) #

[View source]

Instance Method Detail

def 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).


[View source]
def parse : Token::Base #

Returns the condition token corresponding to the condition expression.

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


[View source]