Comparisons within `assign`
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
It appears that the assign operator doesn't like comparisons (i.e. [thing] contains [other thing]). For instance, I would expect this to work:
{%- assign is_some_product = variant.tags contains "example" -%}
But produces the error: Expected end_of_string but found comparison in [...]
I've used the following as a workaround:
{% if variant.tags contains "example" %}
{%- assign is_some_product = true -%}
{% else %}
{%- assign is_some_product = false -%}
{% endif %}
While the latter works, the former is much more concise and is what I would expect to work. Note that I found this while trying to use the or operator as well, but seeing as comparisons themselves aren't accepted, I don't think the parser even got that far.
edit 10/30/2020: The following snippet also works and is a bit more compact:
{%- assign is_some_product = false -%}
{% if variant.tags contains "example" %}
{%- assign is_some_product = true -%}
{% endif %}
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
The issue identifies the assign operator and comparison syntax as the entry points, but names no files or tests. Start by locating the parser for assign expressions and the existing comparison handling, then reproduce the supplied snippets and add coverage showing that a comparison can be assigned successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100