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] 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