Merge pull request #167 from pacifists/master
added parent and breadcrumbs methods to page drop
This commit is contained in:
commit
c3ba38216d
@ -13,6 +13,14 @@ module Locomotive
|
|||||||
self._source.templatized? ? self._source.content_type.slug.singularize : self._source.slug
|
self._source.templatized? ? self._source.content_type.slug.singularize : self._source.slug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parent
|
||||||
|
@parent ||= self._source.parent.to_liquid
|
||||||
|
end
|
||||||
|
|
||||||
|
def breadcrumbs
|
||||||
|
@breadcrumbs ||= liquify(*self._source.self_and_ancestors)
|
||||||
|
end
|
||||||
|
|
||||||
def children
|
def children
|
||||||
@children ||= liquify(*self._source.children)
|
@children ||= liquify(*self._source.children)
|
||||||
end
|
end
|
||||||
|
@ -98,6 +98,14 @@ Factory.define :page do |p|
|
|||||||
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
|
p.site { Site.where(:subdomain => "acme").first || Factory(:site) }
|
||||||
end
|
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 ##
|
## Snippets ##
|
||||||
Factory.define :snippet do |s|
|
Factory.define :snippet do |s|
|
||||||
|
@ -41,6 +41,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
|
context '#rendering page title' do
|
||||||
|
|
||||||
it 'renders the title of a normal page' do
|
it 'renders the title of a normal page' do
|
||||||
|
Loading…
Reference in New Issue
Block a user