Merge pull request #167 from pacifists/master

added parent and breadcrumbs methods to page drop
This commit is contained in:
Didier Lafforgue 2011-08-15 15:38:20 -07:00
commit c3ba38216d
3 changed files with 39 additions and 0 deletions

View File

@ -12,6 +12,14 @@ module Locomotive
def slug
self._source.templatized? ? self._source.content_type.slug.singularize : self._source.slug
end
def parent
@parent ||= self._source.parent.to_liquid
end
def breadcrumbs
@breadcrumbs ||= liquify(*self._source.self_and_ancestors)
end
def children
@children ||= liquify(*self._source.children)

View File

@ -98,6 +98,14 @@ Factory.define :page do |p|
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
end
Factory.define :sub_page, :parent => :page do |p|
p.title 'Subpage'
p.slug 'subpage'
p.published true
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
p.parent { Page.where(:slug => "index").first || Factory(:page) }
end
## Snippets ##
Factory.define :snippet do |s|

View File

@ -40,6 +40,29 @@ describe Locomotive::Liquid::Drops::Page do
end
end
context '#parent' do
before(:each) do
@sub_page = Factory.build(:sub_page, :meta_keywords => 'Sub Libidinous, Angsty', :meta_description => "Sub Quite the combination.")
end
it 'renders title of parent page' do
content = render_template '{{ sub_page.parent.title }}', {'sub_page' => @sub_page}
content.should == "Home page"
end
end
context '#breadcrumbs' do
before(:each) do
@sub_page = Factory.build(:sub_page, :meta_keywords => 'Sub Libidinous, Angsty', :meta_description => "Sub Quite the combination.")
end
it 'renders breadcrumbs of current page' do
content = render_template '{% for crumb in sub_page.breadcrumbs %}{{ crumb.title}},{% endfor %}', {'sub_page' => @sub_page}
content.should == 'Home page,Subpage,'
end
end
context '#rendering page title' do