Skip to content

Commit

Permalink
Merge pull request #1811 from Shopify/marco-cycle-update
Browse files Browse the repository at this point in the history
Add named? method to Cycle class for checking if the cycle is named
  • Loading branch information
ianks authored Jul 16, 2024
2 parents 77bc56a + d6ca569 commit ed42120
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ end

gemspec

gem "base64"

group :benchmark, :test do
gem 'benchmark-ips'
gem 'memory_profiler'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
base64 (0.2.0)
benchmark-ips (2.13.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
Expand Down Expand Up @@ -57,6 +58,7 @@ PLATFORMS
ruby

DEPENDENCIES
base64
benchmark-ips
liquid!
liquid-c!
Expand Down
6 changes: 6 additions & 0 deletions lib/liquid/tags/cycle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ def initialize(tag_name, markup, options)
when NamedSyntax
@variables = variables_from_string(Regexp.last_match(2))
@name = parse_expression(Regexp.last_match(1))
@is_named = true
when SimpleSyntax
@variables = variables_from_string(markup)
@name = @variables.to_s
@is_named = !@name.match?(/\w+:0x\h{8}/)
else
raise SyntaxError, options[:locale].t("errors.syntax.cycle")
end
end

def named?
@is_named
end

def render_to_output_buffer(context, output)
context.registers[:cycle] ||= {}

Expand Down

0 comments on commit ed42120

Please sign in to comment.