diff --git a/lib/locomotive/liquid/drops/site.rb b/lib/locomotive/liquid/drops/site.rb index 29f093b3..07f040b8 100644 --- a/lib/locomotive/liquid/drops/site.rb +++ b/lib/locomotive/liquid/drops/site.rb @@ -9,6 +9,10 @@ module Locomotive @index ||= @source.pages.root.first end + def pages + @pages ||= @source.pages.to_a.collect(&:to_liquid) + end + end end end diff --git a/spec/lib/locomotive/liquid/drops/site_spec.rb b/spec/lib/locomotive/liquid/drops/site_spec.rb new file mode 100644 index 00000000..fb59b1be --- /dev/null +++ b/spec/lib/locomotive/liquid/drops/site_spec.rb @@ -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