Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78aa8a7
commit 5ca94b8
Showing
10 changed files
with
65 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module Nanoc | ||
class LayoutView < ::Nanoc::DocumentView | ||
class LayoutView | ||
include Nanoc::DocumentViewMixin | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
lib/nanoc/base/views/document.rb → lib/nanoc/base/views/mixins/document.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Nanoc | ||
class DocumentView | ||
module DocumentViewMixin | ||
# @api private | ||
NONE = Object.new | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Nanoc | ||
module MutableDocumentViewMixin | ||
# Sets the value for the given attribute. | ||
# | ||
# @param [Symbol] key | ||
# | ||
# @see Hash#[]= | ||
def []=(key, value) | ||
unwrap.attributes[key] = value | ||
end | ||
|
||
# Updates the attributes based on the given hash. | ||
# | ||
# @param [Hash] hash | ||
# | ||
# @return [self] | ||
def update_attributes(hash) | ||
hash.each { |k, v| unwrap.attributes[k] = v } | ||
self | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,5 @@ | ||
module Nanoc | ||
class MutableItemView < Nanoc::ItemView | ||
# Sets the value for the given attribute. | ||
# | ||
# @param [Symbol] key | ||
# | ||
# @see Hash#[]= | ||
def []=(key, value) | ||
unwrap.attributes[key] = value | ||
end | ||
|
||
# Updates the attributes based on the given hash. | ||
# | ||
# @param [Hash] hash | ||
# | ||
# @return [self] | ||
def update_attributes(hash) | ||
hash.each { |k, v| unwrap.attributes[k] = v } | ||
self | ||
end | ||
include Nanoc::MutableDocumentViewMixin | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
module Nanoc | ||
class MutableLayoutView < Nanoc::LayoutView | ||
# Sets the value for the given attribute. | ||
# | ||
# @param [Symbol] key | ||
# | ||
# @see Hash#[]= | ||
def []=(key, value) | ||
unwrap.attributes[key] = value | ||
end | ||
include Nanoc::MutableDocumentViewMixin | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
shared_examples 'a mutable document view' do | ||
describe '#[]=' do | ||
let(:item) { entity_class.new('content', {}, '/asdf/') } | ||
let(:view) { described_class.new(item) } | ||
|
||
it 'sets attributes' do | ||
view[:title] = 'Donkey' | ||
expect(view[:title]).to eq('Donkey') | ||
end | ||
end | ||
|
||
describe '#update_attributes' do | ||
let(:item) { entity_class.new('content', {}, '/asdf/') } | ||
let(:view) { described_class.new(item) } | ||
|
||
let(:update) { { friend: 'Giraffe' } } | ||
|
||
subject { view.update_attributes(update) } | ||
|
||
it 'sets attributes' do | ||
expect { subject }.to change { view[:friend] }.from(nil).to('Giraffe') | ||
end | ||
|
||
it 'returns self' do | ||
expect(subject).to equal(view) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,4 @@ | ||
describe Nanoc::MutableItemView do | ||
describe '#[]=' do | ||
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') } | ||
let(:view) { described_class.new(item) } | ||
|
||
it 'sets attributes' do | ||
view[:title] = 'Donkey' | ||
expect(view[:title]).to eq('Donkey') | ||
end | ||
end | ||
|
||
describe '#update_attributes' do | ||
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') } | ||
let(:view) { described_class.new(item) } | ||
|
||
let(:update) { { friend: 'Giraffe' } } | ||
|
||
subject { view.update_attributes(update) } | ||
|
||
it 'sets attributes' do | ||
expect { subject }.to change { view[:friend] }.from(nil).to('Giraffe') | ||
end | ||
|
||
it 'returns self' do | ||
expect(subject).to equal(view) | ||
end | ||
end | ||
let(:entity_class) { Nanoc::Int::Item } | ||
it_behaves_like 'a mutable document view' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
describe Nanoc::MutableLayoutView do | ||
describe '#[]=' do | ||
let(:layout) { Nanoc::Int::Layout.new('content', {}, '/asdf/') } | ||
let(:view) { described_class.new(layout) } | ||
|
||
it 'sets attributes' do | ||
view[:title] = 'Donkey' | ||
expect(view[:title]).to eq('Donkey') | ||
end | ||
end | ||
let(:entity_class) { Nanoc::Int::Layout } | ||
it_behaves_like 'a mutable document view' | ||
end |