Skip to content

Commit

Permalink
Merge pull request #770 from nanoc/fix-parent-of-child-of-root
Browse files Browse the repository at this point in the history
Fix finding parent of child of root
  • Loading branch information
denisdefreyne committed Dec 13, 2015
2 parents 6404b23 + 0af69bb commit 5769827
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/nanoc/base/views/item_without_reps_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def parent
end

parent_identifier = '/' + unwrap.identifier.components[0..-2].join('/') + '/'

# FIXME: Fix this elsewhere
parent_identifier.sub!(/\/\/$/, '/')
parent_identifier = '/' if parent_identifier == '//'

parent = @context.items[parent_identifier]

Expand Down
10 changes: 10 additions & 0 deletions spec/nanoc/base/views/item_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
end

it { is_expected.to be_frozen }

context 'with root parent' do
let(:parent_item) { Nanoc::Int::Item.new('parent', {}, '/') }
let(:identifier) { Nanoc::Identifier.new('/me/', type: :legacy) }

it 'returns a view for the parent' do
expect(subject.class).to eql(Nanoc::ItemWithRepsView)
expect(subject.unwrap).to eql(parent_item)
end
end
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/nanoc/regressions/gh_769_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe 'GH-769', site: true do
before do
File.write('content/index.md', 'Index!')
File.write('content/donkey.md', 'Donkey! [<%= @item.parent.identifier %>]')

File.open('nanoc.yaml', 'w') do |io|
io << 'string_pattern_type: legacy' << "\n"
io << 'data_sources:' << "\n"
io << ' -' << "\n"
io << ' type: filesystem' << "\n"
io << ' identifier_type: legacy' << "\n"
end

File.write('Rules', <<EOS)
compile '*' do
filter :erb
write item.identifier + 'index.html'
end
layout '/foo.*', :erb
EOS
end

it 'finds the parent if the parent is root' do
site = Nanoc::Int::SiteLoader.new.new_from_cwd
site.compile

expect(File.read('output/donkey/index.html')).to eql('Donkey! [/]')
end
end

0 comments on commit 5769827

Please sign in to comment.