the site drop has access to pages

This commit is contained in:
did 2011-02-27 17:14:14 +01:00
parent 34ee6e1a64
commit ebc40d1682
2 changed files with 36 additions and 0 deletions

View File

@ -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

View 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