Expose Liquid::Condition in public API
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Liquid::If and its private construction path, then compare it with the Liquid::Template.parse and render workaround shown in the issue. Determine the public API needed to evaluate a condition outside templating, and consider the existing quoting and efficiency concerns as completion criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100