fix issue #157 (with_scope and boolean variables)

did committed Apr 21, 2014
commit 094a4dc2411d2992c18ad7cd7b1d56cac5a824c3
Showing 5 changed files with 18 additions and 2 deletions
locomotive/wagon/liquid/tags/with_scope.rb b/lib/locomotive/wagon/liquid/tags/with_scope.rb +1 -1
@@ @@ -31,7 +31,7 @@ module Locomotive
when /^\/[^\/]*\/$/ then Regexp.new(value[1..-2])
when /^["|'](.+)["|']$/ then $1.gsub(/^["|']/, '').gsub(/["|']$/, '')
else
- context[value] || value
+ context[value].nil? ? value : context[value]
end)
end
end
spec/fixtures/default/app/content_types/bands.yml +3 -1
@@ @@ -16,4 +16,6 @@ fields:
type: has_many
class_name: songs
inverse_of: band
- ui_enabled: true
\ No newline at end of file
+ ui_enabled: true
+ - featured:
+ type: boolean
\ No newline at end of file
spec/fixtures/default/app/views/pages/filtered.liquid.haml +6 -0
@@ @@ -7,4 +7,10 @@ title: Various uses of the with_scope tag
{% with_scope date.gte: begin, date.lte: end, city: /Kansas/, state.ne: 'Illinois', tags: 'awesome', tags.nin: 'bad', price.in: prices %}
events={{ contents.events.count }}.
+ {% endwith_scope %}
+
+ {% assign featured = false %}
+
+ {% with_scope featured: featured %}
+ bands={{ contents.bands.count }}.
{% endwith_scope %}
\ No newline at end of file
spec/fixtures/default/data/bands.yml +3 -0
@@ @@ -1,10 +1,13 @@
- Pearl Jam:
leader: Eddie
kind: grunge
+ featured: false
- Alice in Chains:
leader: Layne
kind: grunge
+ featured: false
- The who:
leader: Peter
kind: rock
+ featured: true
spec/integration/server/with_scope_spec.rb +5 -0
@@ @@ -17,4 +17,9 @@ describe 'Complex with_scope conditions' do
last_response.body.should =~ /events=1./
end
+ it 'returns the right number of bands' do
+ get '/filtered'
+ last_response.body.should =~ /bands=2./
+ end
+
end
\ No newline at end of file