the breadcrumbs method of a page drop can now be called from a templatized page
did
committed Dec 03, 2016
commit 6fe713247d4de2e7c2394d763bf1737c2c9f3467
Showing 2
changed files with
11 additions
and 3 deletions
locomotive/steam/liquid/drops/page.rb b/lib/locomotive/steam/liquid/drops/page.rb
+8
-1
| @@ | @@ -30,7 +30,14 @@ module Locomotive |
| end | |
| def breadcrumbs | |
| - | @breadcrumbs ||= liquify(*repository.ancestors_of(@_source)) |
| + | return @breadcrumbs if @breadcrumbs |
| + | |
| + | # remove the last one and replace it by the current instance |
| + | # which may have a valid reference to a content entry (if templatized) |
| + | pages = liquify(*repository.ancestors_of(@_source)) |
| + | pages.pop |
| + | |
| + | @breadcrumbs = pages + [self] |
| end | |
| def children | |
spec/unit/liquid/drops/page_spec.rb
+3
-2
| @@ | @@ -46,13 +46,14 @@ describe Locomotive::Steam::Liquid::Drops::Page do |
| describe '#breadcrumbs' do | |
| - | let(:ancestors) { [instance_double('ParentPage', to_liquid: { 'title' => 'Parent' })] } |
| + | let(:ancestors) { [instance_double('ParentPage', to_liquid: { 'title' => 'Parent' }), page] } |
| before do | |
| + | expect(page).to receive(:to_liquid).and_return(drop) |
| allow(services.repositories.page).to receive(:ancestors_of).with(page).and_return(ancestors) | |
| end | |
| - | it { expect(subject.breadcrumbs).to eq([{ 'title' => 'Parent' }]) } |
| + | it { expect(subject.breadcrumbs.map { |p| p['title'] }).to eq(['Parent', 'Index']) } |
| end | |