Skip to content

Commit

Permalink
Adopt regex_replace tags to new Liquid BlockBody class
Browse files Browse the repository at this point in the history
  • Loading branch information
dsander committed Apr 25, 2017
1 parent d91c430 commit 63de008
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/concerns/liquid_interpolatable.rb
Expand Up @@ -386,21 +386,27 @@ def initialize(tag_name, markup, tokens)
else
raise Liquid::SyntaxError, 'Syntax Error in regex_replace tag - Valid syntax: regex_replace pattern in'
end
@nodelist = @in_block = []
@with_block = nil
@in_block = Liquid::BlockBody.new
end

def parse(tokens)
if more = parse_body(@in_block, tokens)
@with_block = Liquid::BlockBody.new
parse_body(@with_block, tokens)
end
end

def nodelist
if @with_block
@in_block + @with_block
[@in_block, @with_block]
else
@in_block
[@in_block]
end
end

def unknown_tag(tag, markup, tokens)
return super unless tag == 'with'.freeze
@nodelist = @with_block = []
@with_block = Liquid::BlockBody.new
end

def render(context)
Expand All @@ -410,7 +416,7 @@ def render(context)
raise Liquid::SyntaxError, "Syntax Error in regex_replace tag - #{e.message}"
end

subject = render_all(@in_block, context)
subject = @in_block.render(context)

subject.send(first? ? :sub : :gsub, regexp) {
next '' unless @with_block
Expand All @@ -420,7 +426,7 @@ def render(context)
context[name] = m[name]
end
context['match'.freeze] = m
render_all(@with_block, context)
@with_block.render(context)
end
}
end
Expand Down

0 comments on commit 63de008

Please sign in to comment.