Expose Liquid::Condition in public API
jscheid opened this issue · comments
Julian Scheid commented
It would be useful to be able to use Liquid conditions outside of templating. This can be hacked by using private APIs like so:
cond = Liquid::If
.send(
:new,
'if',
condition_str,
parse_context
)
.blocks
.first or raise
cond.evaluate(context)
...or by abusing templating like so:
tmpl = Liquid::Template.parse(
"{% if #{condition} %}true{% else %}false{% endif %}",
parse_context
)
tmpl.render(context) == "true"
The former is hacky and prone to breakage in future releases, the latter is inefficient and has quoting issues. Would it be conceivable to expose this feature in the public API?