the site drop has access to pages
This commit is contained in:
parent
34ee6e1a64
commit
ebc40d1682
@ -9,6 +9,10 @@ module Locomotive
|
|||||||
@index ||= @source.pages.root.first
|
@index ||= @source.pages.root.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pages
|
||||||
|
@pages ||= @source.pages.to_a.collect(&:to_liquid)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
32
spec/lib/locomotive/liquid/drops/site_spec.rb
Normal file
32
spec/lib/locomotive/liquid/drops/site_spec.rb
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Locomotive::Liquid::Drops::Site do
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@site = Factory.build(:site)
|
||||||
|
page_1 = Factory.build(:page, :site => @site)
|
||||||
|
page_2 = Factory.build(:page, :site => @site, :title => 'About us', :slug => 'about_us')
|
||||||
|
@site.stubs(:pages).returns([page_1, page_2])
|
||||||
|
end
|
||||||
|
|
||||||
|
context '#pages' do
|
||||||
|
|
||||||
|
it 'has access to all the pages' do
|
||||||
|
render_template('{{ site.pages.size }}').should == '2'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'loops thru the pages' do
|
||||||
|
render_template('{% for page in site.pages %}{{ page.title }} {% endfor %}').should == 'Home page About us '
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_template(template = '', assigns = {})
|
||||||
|
assigns = {
|
||||||
|
'site' => @site
|
||||||
|
}.merge(assigns)
|
||||||
|
|
||||||
|
Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { :site => @site }))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user