showcase 0.1.6 → 0.1.7
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 +12 -5
- data/lib/showcase/presenter.rb +6 -2
- data/lib/showcase/version.rb +1 -1
- data/spec/fixtures.rb +13 -0
- data/spec/showcase_spec.rb +6 -0
- 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: 93da90243af0c3fe8b795954fbdf5df12a28007b
|
4
|
+
data.tar.gz: 463b88936212e9e181cb15fe44613e947ab116cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7a38f5e9d326581b10ea36a15ffd78019a5b3fae9deb475ed6565723e187e3894383ee1ec3c8574784cd3c25e65aeed63f8793891ca8b66db588780371e615a
|
7
|
+
data.tar.gz: 69ed3a3ac0c0dbc8c7a12f4d1b0fd018a5ffe465ddb611de1ba576e2fbca792e692b09296a93e33e6a90eb63fb447d9821dda374a9122c6e3ba30a838218d059
|
data/lib/showcase/helpers.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
require 'active_support/inflector'
|
3
|
+
require 'active_support/core_ext/hash/keys'
|
3
4
|
|
4
5
|
module Showcase
|
5
6
|
module Helpers
|
@@ -13,13 +14,19 @@ module Showcase
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
def present(obj, klass = nil, context = presenter_context)
|
17
|
-
|
18
|
-
|
17
|
+
def present(obj, klass = nil, context = presenter_context, options = {})
|
18
|
+
options.assert_valid_keys(:nil_presenter)
|
19
|
+
|
20
|
+
if obj || options.fetch(:nil_presenter, false)
|
21
|
+
klass ||= "#{obj.class.name}Presenter".constantize
|
22
|
+
klass.new(obj, context)
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
|
-
def present_collection(obj, klass = nil, context = presenter_context)
|
22
|
-
obj.map { |o| present(o, klass, context) }
|
28
|
+
def present_collection(obj, klass = nil, context = presenter_context, options = {})
|
29
|
+
obj.map { |o| present(o, klass, context, options) }
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
data/lib/showcase/presenter.rb
CHANGED
@@ -43,13 +43,17 @@ module Showcase
|
|
43
43
|
|
44
44
|
def self.wrap_methods(args, method)
|
45
45
|
options = args.extract_options!
|
46
|
-
options.assert_valid_keys(:with)
|
46
|
+
options.assert_valid_keys(:with, :nil_presenter)
|
47
47
|
presenter_klass = options.fetch(:with, nil)
|
48
48
|
|
49
49
|
methods_module = Module.new do
|
50
50
|
args.each do |attr|
|
51
51
|
define_method attr do
|
52
|
-
send(method,
|
52
|
+
send(method,
|
53
|
+
object.send(attr),
|
54
|
+
presenter_klass,
|
55
|
+
view_context,
|
56
|
+
options.slice(:nil_presenter))
|
53
57
|
end
|
54
58
|
end
|
55
59
|
end
|
data/lib/showcase/version.rb
CHANGED
data/spec/fixtures.rb
CHANGED
@@ -14,6 +14,12 @@ class Project < Struct.new(:name)
|
|
14
14
|
collaborators.first
|
15
15
|
end
|
16
16
|
|
17
|
+
def owner_child
|
18
|
+
end
|
19
|
+
|
20
|
+
def foobar
|
21
|
+
end
|
22
|
+
|
17
23
|
def dummy
|
18
24
|
"foobar"
|
19
25
|
end
|
@@ -39,6 +45,7 @@ class ProjectPresenter < Showcase::Presenter
|
|
39
45
|
presents :owner, with: AdminPresenter
|
40
46
|
presents_collection :collaborators
|
41
47
|
presents :owner_child
|
48
|
+
presents :foobar, nil_presenter: true
|
42
49
|
|
43
50
|
def name
|
44
51
|
"Presented #{object.name}"
|
@@ -57,6 +64,12 @@ class ProjectPresenter < Showcase::Presenter
|
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
67
|
+
class NilClassPresenter < Showcase::Presenter
|
68
|
+
def hi
|
69
|
+
"hi!"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
60
73
|
class Context
|
61
74
|
include Showcase::Helpers
|
62
75
|
|
data/spec/showcase_spec.rb
CHANGED
@@ -55,6 +55,12 @@ describe Showcase::Presenter do
|
|
55
55
|
it 'passes the context' do
|
56
56
|
subject.owner.bold_name.should == '**Admin Stefano Verna**'
|
57
57
|
end
|
58
|
+
it 'returns null if nil_presenter is false or undefined' do
|
59
|
+
subject.owner_child.should be_nil
|
60
|
+
end
|
61
|
+
it 'returns a null presenter if nil_presenter is true' do
|
62
|
+
subject.foobar.hi.should eq "hi!"
|
63
|
+
end
|
58
64
|
end
|
59
65
|
|
60
66
|
describe '#presents_collection' do
|
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.7
|
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-
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|