mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Ability to pass block to decorator method
This commit is contained in:
parent
62d80310f4
commit
16f69ee07c
4 changed files with 11 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
module Draper::ModelSupport
|
module Draper::ModelSupport
|
||||||
def decorator
|
def decorator
|
||||||
@decorator ||= "#{self.class.name}Decorator".constantize.decorate(self)
|
@decorator ||= "#{self.class.name}Decorator".constantize.decorate(self)
|
||||||
|
block_given? ? yield(@decorator) : @decorator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,5 +6,10 @@ describe Draper::ModelSupport do
|
||||||
describe '#decorator' do
|
describe '#decorator' do
|
||||||
its(:decorator) { should be_kind_of(ProductDecorator) }
|
its(:decorator) { should be_kind_of(ProductDecorator) }
|
||||||
its(:decorator) { should be(subject.decorator) }
|
its(:decorator) { should be(subject.decorator) }
|
||||||
|
|
||||||
|
it 'should have abillity to pass block' do
|
||||||
|
a = Product.new.decorator { |d| d.awesome_title }
|
||||||
|
a.should eql "Awesome Title"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
class ProductDecorator < Draper::Base
|
class ProductDecorator < Draper::Base
|
||||||
decorates :product
|
decorates :product
|
||||||
|
|
||||||
|
def awesome_title
|
||||||
|
"Awesome Title"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue