showcase 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/showcase/helpers.rb +2 -6
- data/lib/showcase/presenter.rb +17 -10
- data/lib/showcase/version.rb +1 -1
- data/spec/showcase_spec.rb +11 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c765d3877ec138551a3f31f9689b060b8461a433
|
4
|
+
data.tar.gz: 59dcf8ad2c8b36965df56f5edb950beed2ddcfc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db97e02df789e59db7f735b2414ebcdb469dcca9de3323ab36598556bd77802ed56c15f3f93658aabf9b04f8c1208699405db96a5011a992f9296c334ef26219
|
7
|
+
data.tar.gz: 7b23bfa80dd5a1c5ac4968c8704f8260cb7d4c5a845ddef8e1fc8579f5ec4bb7dd19f362c956698573b60fc43a0b3a2c1ab76b8d8510c6f85455533dcd585f49
|
data/lib/showcase/helpers.rb
CHANGED
@@ -14,12 +14,8 @@ module Showcase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def present(obj, klass = nil, context = presenter_context)
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
klass ||= "#{obj.class.name}Presenter".constantize
|
21
|
-
klass.new(obj, context)
|
22
|
-
end
|
17
|
+
klass ||= "#{obj.class.name}Presenter".constantize
|
18
|
+
klass.new(obj, context)
|
23
19
|
end
|
24
20
|
|
25
21
|
def present_collection(obj, klass = nil, context = presenter_context)
|
data/lib/showcase/presenter.rb
CHANGED
@@ -2,23 +2,30 @@ require 'delegate'
|
|
2
2
|
require 'showcase/helpers'
|
3
3
|
|
4
4
|
module Showcase
|
5
|
-
class Presenter <
|
6
|
-
include Helpers
|
7
|
-
|
5
|
+
class Presenter < BasicObject
|
8
6
|
attr_reader :view_context
|
9
|
-
|
10
|
-
alias_method :object, :__getobj__
|
7
|
+
attr_reader :object
|
11
8
|
alias_method :h, :view_context
|
12
9
|
|
13
|
-
|
14
|
-
object.class
|
15
|
-
end
|
10
|
+
include Helpers
|
16
11
|
|
17
|
-
def initialize(
|
18
|
-
|
12
|
+
def initialize(object, context)
|
13
|
+
@object = object
|
19
14
|
@view_context = context
|
20
15
|
end
|
21
16
|
|
17
|
+
def respond_to?(name)
|
18
|
+
if [:view_context, :h, :object].include? name
|
19
|
+
true
|
20
|
+
else
|
21
|
+
object.respond_to?(name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(name, *args, &block)
|
26
|
+
object.__send__(name, *args, &block)
|
27
|
+
end
|
28
|
+
|
22
29
|
def self.presents(*attrs)
|
23
30
|
attrs.each do |attr|
|
24
31
|
define_method attr do
|
data/lib/showcase/version.rb
CHANGED
data/spec/showcase_spec.rb
CHANGED
@@ -43,7 +43,7 @@ describe Showcase::Presenter do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe '#presents_collection' do
|
46
|
-
it 'wraps the
|
46
|
+
it 'wraps the specified collection attributes inside a presenter' do
|
47
47
|
subject.collaborators.first.sex.should == 'male'
|
48
48
|
end
|
49
49
|
it 'passes the context' do
|
@@ -57,25 +57,17 @@ describe Showcase::Helpers do
|
|
57
57
|
let(:context) { Context.new }
|
58
58
|
|
59
59
|
describe '.present' do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
context.present(presenter).should == presenter
|
64
|
-
end
|
60
|
+
it 'instanciate a new presenter, inferring the class' do
|
61
|
+
PersonPresenter.stub(:new).with(object, context).and_return 'Presenter'
|
62
|
+
context.present(object, PersonPresenter).should == 'Presenter'
|
65
63
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
context.present(object, ProjectPresenter).should == 'Presenter'
|
74
|
-
end
|
75
|
-
it 'the context to use can be specified as third parameter' do
|
76
|
-
different_context = stub
|
77
|
-
context.present(object, ProjectPresenter, different_context).view_context.should == different_context
|
78
|
-
end
|
64
|
+
it 'the presenter class to use can be specified as the second parameter' do
|
65
|
+
ProjectPresenter.stub(:new).with(object, context).and_return 'Presenter'
|
66
|
+
context.present(object, ProjectPresenter).should == 'Presenter'
|
67
|
+
end
|
68
|
+
it 'the context to use can be specified as third parameter' do
|
69
|
+
different_context = stub
|
70
|
+
context.present(object, ProjectPresenter, different_context).view_context.should == different_context
|
79
71
|
end
|
80
72
|
end
|
81
73
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: showcase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|