Skip to content

Commit

Permalink
Merge pull request #702 from nanoc/document-attributes
Browse files Browse the repository at this point in the history
Add DocumentView#attributes
  • Loading branch information
denisdefreyne committed Sep 19, 2015
2 parents 6aeb14f + 388ab07 commit b972fba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/nanoc/base/views/mixins/document_view_mixin.rb
Expand Up @@ -37,6 +37,14 @@ def [](key)
unwrap.attributes[key]
end

# @return [Hash]
def attributes
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
Nanoc::Int::NotificationCenter.post(:visit_ended, unwrap)

unwrap.attributes
end

# @see Hash#fetch
def fetch(key, fallback = NONE, &_block)
Nanoc::Int::NotificationCenter.post(:visit_started, unwrap)
Expand Down
16 changes: 16 additions & 0 deletions spec/nanoc/base/views/document_view_spec.rb
Expand Up @@ -71,6 +71,22 @@
end
end

describe '#attributes' do
let(:item) { entity_class.new('stuff', { animal: 'donkey' }, '/foo/') }
let(:view) { described_class.new(item) }

before do
expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:visit_started, item).ordered
expect(Nanoc::Int::NotificationCenter).to receive(:post).with(:visit_ended, item).ordered
end

subject { view.attributes }

it 'returns attributes' do
expect(subject).to eql(animal: 'donkey')
end
end

describe '#fetch' do
let(:item) { entity_class.new('stuff', { animal: 'donkey' }, '/foo/') }
let(:view) { described_class.new(item) }
Expand Down

0 comments on commit b972fba

Please sign in to comment.