Shopify / Shopify/liquid

Using liquid class libraries inside Liquid::Tag

Open
#671 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Question
Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

I've written a liquid tag that makes use of Liquid::Parser and Liquid::Expression although not on the official documentation page. I just wanted to check back and ask if that is reasonably sustainable or the code is going to change soon.

Here's a code excerpt:

class ExampleTag < Liquid::Tag
  def initialize(tag_name, markup, tokens)
    super
    @markup = markup
  end

  def render(context)
    p = Liquid::Parser.new(@markup)
    name = Liquid::Expression.parse(exp = p.expression)
    key = context.evaluate(name)
    raise Liquid::SyntaxError.new("Invalid example tag expression: #{exp}") if key.nil?

    # do something with evaluated key

    # loop through arguments, optionally
    if p.consume?(:colon)
      loop do
        arg = Liquid::Expression.parse(exp = p.expression)
        argstr = context.evaluate(arg)
        raise Liquid::SyntaxError.new("Invalid parameter expression: #{exp}") if argstr.nil?
        # do something with parameter
        break if !p.consume?(:comma)
      end
    end

    # do something more, return
  end
end

At this point, I'm not an expert of liquid. What I want to achieve is parametrical expression parsing within a tag. So for example {% xt 'mandatory expression': 'arg1', 'arg2', variable3 %}.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the Liquid::Tag#render entry point and the Liquid::Parser, Liquid::Expression, and context.evaluate APIs used in the example, then compare them with the official documentation. Done means determining whether this parsing approach is a supported, stable API or what documentation change is needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.