showcase 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/showcase/errors.rb +5 -0
- data/lib/showcase/helpers/present.rb +7 -0
- data/lib/showcase/version.rb +1 -1
- data/spec/helpers_spec.rb +18 -7
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcf0fde90d484b35c54b9cfb8ef72123de71a78d
|
4
|
+
data.tar.gz: fdcc72c89960d828ab4d496974cb45c01045dc19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72365b989e2d2aeef8f757cbe85607097da0a602510652d03266b6d352f4c5036164dfe81376649407f47620af7296bde6bf7f8def7edc02a31b04fbfbda644b
|
7
|
+
data.tar.gz: c8774f411e41452fc643f952ed6c43413968d2246421cabce9b38d4854f23d80609d43f198328d5be234e8fb7b1f0bf96c4d1496480474044cffb3716a17cf6f
|
@@ -2,6 +2,8 @@ require 'active_support/concern'
|
|
2
2
|
require 'active_support/inflector'
|
3
3
|
require 'active_support/core_ext/hash/keys'
|
4
4
|
|
5
|
+
require 'showcase/errors'
|
6
|
+
|
5
7
|
module Showcase
|
6
8
|
module Helpers
|
7
9
|
module Present
|
@@ -20,6 +22,9 @@ module Showcase
|
|
20
22
|
|
21
23
|
if obj || options.fetch(:nil_presenter, false)
|
22
24
|
klass ||= presenter_class(obj)
|
25
|
+
if klass.nil?
|
26
|
+
raise Showcase::PresenterClassNotFound, "Unable to guess a presenter class for #{obj.inspect}!"
|
27
|
+
end
|
23
28
|
klass.new(obj, context)
|
24
29
|
else
|
25
30
|
nil
|
@@ -37,7 +42,9 @@ module Showcase
|
|
37
42
|
klass = "#{k.name}Presenter".safe_constantize
|
38
43
|
return klass if klass
|
39
44
|
end
|
45
|
+
nil
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
50
|
+
|
data/lib/showcase/version.rb
CHANGED
data/spec/helpers_spec.rb
CHANGED
@@ -2,23 +2,33 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Showcase::Helpers do
|
4
4
|
let(:object) { Person.new('Steve Ballmer') }
|
5
|
-
let(:
|
5
|
+
let(:subclass_object) { EnterpriseCustomer.new('Tito Traves') }
|
6
|
+
let(:object_with_no_presenter) { Shop.new }
|
6
7
|
let(:context) { Context.new }
|
7
8
|
|
8
9
|
describe '.present' do
|
9
|
-
it 'instantiates a new presenter, inferring the class' do
|
10
|
+
it 'instantiates a new presenter, inferring the presenter class' do
|
10
11
|
PersonPresenter.stub(:new).with(object, context).and_return 'Presenter'
|
11
12
|
context.present(object).should == 'Presenter'
|
12
13
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
context 'with a superclass presenter' do
|
15
|
+
it "instantiates a new presenter, searching presenter class in object ancestors chain" do
|
16
|
+
PersonPresenter.stub(:new).with(subclass_object, context).and_return 'Presenter'
|
17
|
+
context.present(subclass_object).should == 'Presenter'
|
18
|
+
end
|
16
19
|
end
|
17
|
-
|
20
|
+
context 'with no existing presenter class' do
|
21
|
+
it "raises a PresenterClassNotFound error" do
|
22
|
+
expect {
|
23
|
+
context.present(object_with_no_presenter)
|
24
|
+
}.to raise_error(Showcase::PresenterClassNotFound)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
it 'uses the specified presenter class, when passed' do
|
18
28
|
ProjectPresenter.stub(:new).with(object, context).and_return 'Presenter'
|
19
29
|
context.present(object, ProjectPresenter).should == 'Presenter'
|
20
30
|
end
|
21
|
-
it 'the
|
31
|
+
it 'uses the specified context, when passed' do
|
22
32
|
different_context = double
|
23
33
|
context.present(object, ProjectPresenter, different_context).view_context.should == different_context
|
24
34
|
end
|
@@ -36,3 +46,4 @@ describe Showcase::Helpers do
|
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
49
|
+
|
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.2.
|
4
|
+
version: 0.2.1
|
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-12-
|
11
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/generators/showcase/presenter/presenter_generator.rb
|
102
102
|
- lib/generators/showcase/presenter/templates/presenter.rb
|
103
103
|
- lib/showcase.rb
|
104
|
+
- lib/showcase/errors.rb
|
104
105
|
- lib/showcase/helpers/config_object.rb
|
105
106
|
- lib/showcase/helpers/html_options.rb
|
106
107
|
- lib/showcase/helpers/module_method_builder.rb
|
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
147
|
version: '0'
|
147
148
|
requirements: []
|
148
149
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.0.
|
150
|
+
rubygems_version: 2.0.14
|
150
151
|
signing_key:
|
151
152
|
specification_version: 4
|
152
153
|
summary: A barebone and framework agnostic presenter implementation
|