Skip to content

Commit

Permalink
Upgrade liquid (#1982)
Browse files Browse the repository at this point in the history
* Update Liquid to 4.0

* Handle Liquid renaming before_method to liquid_method_missing

* Adopt `regex_replace` tags to new Liquid BlockBody class
  • Loading branch information
dsander committed Apr 26, 2017
1 parent 2b41b6c commit e1f702a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ gem 'json', '~> 1.8.1'
gem 'jsonpathv2', '~> 0.0.8'
gem 'kaminari', github: "amatsuda/kaminari", branch: '0-17-stable', ref: 'abbf93d557208ee1d0b612c612cd079f86ed54f4'
gem 'kramdown', '~> 1.3.3'
gem 'liquid', '~> 3.0.3'
gem 'liquid', '~> 4.0'
gem 'loofah', '~> 2.0'
gem 'mini_magick'
gem 'multi_xml'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ GEM
letter_opener (~> 1.0)
railties (>= 3.2)
libv8 (3.16.14.15)
liquid (3.0.6)
liquid (4.0.0)
listen (3.0.5)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
Expand Down Expand Up @@ -644,7 +644,7 @@ DEPENDENCIES
kaminari!
kramdown (~> 1.3.3)
letter_opener_web (~> 1.3.0)
liquid (~> 3.0.3)
liquid (~> 4.0)
listen (~> 3.0.5)
loofah (~> 2.0)
mini_magick
Expand Down
2 changes: 1 addition & 1 deletion app/concerns/liquid_droppable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def to_s
@object[0]
end

def before_method(method)
def liquid_method_missing(method)
@object[method]
rescue IndexError
nil
Expand Down
19 changes: 13 additions & 6 deletions app/concerns/liquid_interpolatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,21 +386,28 @@ 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 = []
@in_block = Liquid::BlockBody.new
@with_block = nil
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 +417,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 +427,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
2 changes: 1 addition & 1 deletion app/models/agents/website_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def url

# Wraps Faraday::Utils::Headers
class HeaderDrop < LiquidDroppable::Drop
def before_method(name)
def liquid_method_missing(name)
@object[name.tr('_', '-')]
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def initialize(object)
super
end

def before_method(key)
def liquid_method_missing(key)
@payload[key]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def floatify(value)
class LocationDrop
KEYS = Location.members.map(&:to_s).concat(%w[latitude longitude latlng])

def before_method(key)
def liquid_method_missing(key)
if KEYS.include?(key)
@object.__send__(key)
end
Expand Down

0 comments on commit e1f702a

Please sign in to comment.