Merge pull request #167 from pacifists/master
added parent and breadcrumbs methods to page drop
This commit is contained in:
commit
c3ba38216d
@ -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)
|
||||
|
@ -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|
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user