From 025d5a7dda214a8ee875f517d13d1c9a3fb22ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Lukos=CC=8Cevic=CC=8Cius?= Date: Sun, 14 Aug 2011 11:34:08 +0300 Subject: [PATCH 1/2] added .parent method to Page drop --- lib/locomotive/liquid/drops/page.rb | 4 ++++ spec/factories.rb | 8 ++++++++ spec/lib/locomotive/liquid/drops/page_spec.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/locomotive/liquid/drops/page.rb b/lib/locomotive/liquid/drops/page.rb index 8de62944..263d032d 100644 --- a/lib/locomotive/liquid/drops/page.rb +++ b/lib/locomotive/liquid/drops/page.rb @@ -12,6 +12,10 @@ 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 children @children ||= liquify(*self._source.children) diff --git a/spec/factories.rb b/spec/factories.rb index cffcbca1..918a7317 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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| diff --git a/spec/lib/locomotive/liquid/drops/page_spec.rb b/spec/lib/locomotive/liquid/drops/page_spec.rb index b80328cd..7af1b32d 100644 --- a/spec/lib/locomotive/liquid/drops/page_spec.rb +++ b/spec/lib/locomotive/liquid/drops/page_spec.rb @@ -40,6 +40,18 @@ 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 '#rendering page title' do From 69e24e8fe0fccd0ffb7bca04867de4343f66269b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Lukos=CC=8Cevic=CC=8Cius?= Date: Sun, 14 Aug 2011 11:34:57 +0300 Subject: [PATCH 2/2] added .breadcrumbs method to Page drop. It gives all the ancestors of the page and the page itself --- lib/locomotive/liquid/drops/page.rb | 4 ++++ spec/lib/locomotive/liquid/drops/page_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/locomotive/liquid/drops/page.rb b/lib/locomotive/liquid/drops/page.rb index 263d032d..63a0c85f 100644 --- a/lib/locomotive/liquid/drops/page.rb +++ b/lib/locomotive/liquid/drops/page.rb @@ -16,6 +16,10 @@ module Locomotive 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) diff --git a/spec/lib/locomotive/liquid/drops/page_spec.rb b/spec/lib/locomotive/liquid/drops/page_spec.rb index 7af1b32d..303bc198 100644 --- a/spec/lib/locomotive/liquid/drops/page_spec.rb +++ b/spec/lib/locomotive/liquid/drops/page_spec.rb @@ -52,6 +52,17 @@ describe Locomotive::Liquid::Drops::Page do 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