the liquify method sets the current context to each object of an array if possible

did committed Aug 10, 2016
commit cd9291dade1a77fd34c649db2526cab14d23306b
Showing 4 changed files with 25 additions and 14 deletions
locomotive/steam/liquid/drops/base.rb b/lib/locomotive/steam/liquid/drops/base.rb +17 -13
@@ @@ -14,30 +14,34 @@ module Locomotive
(@_source.respond_to?(:id) ? @_source.id : nil) || 'new'
end
+ def as_json(options = nil)
+ @_source.as_json(options)
+ end
+
+ protected
+
# converts an array of records to an array of liquid drops
- def self.liquify(*records, &block)
+ def liquify(*records, &block)
i = -1
records =
records.inject [] do |all, r|
- i+=1
+ i += 1
attrs = (block && block.arity == 1) ? [r] : [r, i]
- all << (block ? block.call(*attrs) : r.to_liquid)
+ all << (block ? block.call(*attrs) : r.to_liquid).tap do |_r|
+ # For unknown reasons, Liquid doesn't always set the context
+ #
+ # Example:
+ # {{ site.index.children | map: 'title' | join: " - " }}
+ # was not working before
+ #
+ _r.context = @context if _r.respond_to?(:context=)
+ end
all
end
records.compact!
records
end
- def as_json(options = nil)
- @_source.as_json(options)
- end
-
- protected
-
- def liquify(*records, &block)
- self.class.liquify(*records, &block)
- end
-
def _source
@_source
end
locomotive/steam/liquid/filters/misc.rb b/lib/locomotive/steam/liquid/filters/misc.rb +1 -1
@@ @@ -31,7 +31,7 @@ module Locomotive
::Liquid::StandardFilters::InputIterator.new(input).map do |e|
e = e.call if e.is_a?(Proc)
- if property == "to_liquid".freeze
+ if property == 'to_liquid'.freeze
e
elsif property == 'to_f'.freeze
e.to_f
spec/fixtures/default/app/views/pages/all.liquid.haml +3 -0
@@ @@ -10,4 +10,7 @@ published: true
<li>{{ page.title }}</li>
{% endfor %}
</ul>
+
+ <!-- TEST -->{{ site.index.children | map: 'title' | join: " - " }}<!-- TEST -->
+
{% endblock %}
spec/integration/server/nav_spec.rb +4 -0
@@ @@ -29,6 +29,10 @@ describe Locomotive::Steam::Server do
is_expected.to include('<li>A song template</li>')
end
+ it 'lists all the pages from the site liquid drop' do
+ is_expected.to include('<!-- TEST -->About Us - Music - Store - Contact Us - Events - Basic page - A sample contest - Various uses of the with_scope tag - Grunge leaders - Tags - Unlisted pages - Archives - All the pages - Layouts - Songs<!-- TEST -->')
+ end
+
describe 'with wrapper' do
subject { get '/tags/nav'; last_response.body }