pres 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 871d21e9da20da6b0ba8ba1f448c86fb91e24087
4
- data.tar.gz: ec4a5cca68060275991ea5bd0f13ead4f113c077
3
+ metadata.gz: bc021d5c9372478d941b2beea539420d82de377e
4
+ data.tar.gz: 54a3bd206edc161d6f414329a2c9fe885faee57d
5
5
  SHA512:
6
- metadata.gz: 9eb0e651996a5a2712f1b034e914ff69655d34c345583c49f5a273f016829a4543045bc44ce102bbed701a68edff0fac97e81e5fc66c7d3701a1c4a9a90e8e7a
7
- data.tar.gz: d02df0e3db9d705038b2790ea4cbbc1d0ffbb8f60b2859345650da67a8e336a68a20cb5d7d0492a0558348c4227e669baa4162957fd2c01885e65349ee9bfb5f
6
+ metadata.gz: '098c8e5eb4c4c62f5ce807ee6333e232295607d732f308dfb0eb2f19a25d1d9ad81f9edbe1443c56c82d0ec807d100394234389c28e2131fb56b10ccf2782e11'
7
+ data.tar.gz: 20a2b0fbe3666005827b0406fac9095afc19c28186184d4c862ffdf28b4b5537153ca1d94cba127e34f64bd52d3b37623cc1f96b5c232065284c9005a923c808
data/README.md CHANGED
@@ -89,7 +89,7 @@ Use the presenter object in `doges/show.haml.html`
89
89
  ```haml
90
90
  = doge.name_header
91
91
  .status
92
- You are #{ doge.signed_in_status }
92
+ You are #{doge.signed_in_status}
93
93
  .links
94
94
  .meme-link= doge.know_your_meme_link
95
95
  ```
@@ -165,6 +165,19 @@ present(user, presenter: UserEditPresenter, cool: true)
165
165
  => #<UserEditPresenter object: #<User> ...>
166
166
  ```
167
167
 
168
+ You may also define a custom presenter class on any class you want to present:
169
+
170
+ ```ruby
171
+ class User
172
+ def presenter_class
173
+ MyPresenter
174
+ end
175
+ end
176
+
177
+ present(User.new)
178
+ # => #<MyPresenter object: #<User> ...>
179
+ ```
180
+
168
181
  #### Creating presenters in views
169
182
 
170
183
  If you would like to create a presenter in your view code, make the `present` method
@@ -215,7 +228,7 @@ end
215
228
 
216
229
  #### Presenters can create other presenters
217
230
 
218
- If you are awesome, you could have one top-level presenter exposed per controller,
231
+ Ideally, you can have one top-level presenter exposed per controller,
219
232
  which can then wrap child objects in presenters of their own.
220
233
 
221
234
  ```ruby
@@ -234,7 +247,7 @@ end
234
247
 
235
248
  If you don't want to inherit from `Pres::Presenter`, you can include
236
249
  `Pres::ViewDelegation` and implement your own initializer (so the `present` helper
237
- will work).
250
+ will work).
238
251
 
239
252
  This technique is useful if you would like to delegate all methods in a model
240
253
  by default, instead of whitelisting methods on the wrapped model explicitly.
data/lib/pres/presents.rb CHANGED
@@ -4,8 +4,17 @@ module Pres
4
4
 
5
5
  # Wrap an object or collection of objects with a presenter class.
6
6
  #
7
- # object - a ruby class, or nil
8
- # presenter - a Presenter class (optional)
7
+ # object - A ruby object. May be nil.
8
+ # presenter - A Presenter class (optional)
9
+ # args - optional hash / kwargs passed to the presenter
10
+ #
11
+ # An instance of a presenter class is created. The class is
12
+ # one of the following:
13
+ # - the `presenter` argument
14
+ # - `Pres::Presenter` if object is nil
15
+ # - object.presenter_class (if that method is defined)
16
+ # - the default presenter class for the object
17
+ # (for example: User -> UserPresenter)
9
18
  #
10
19
  # Examples
11
20
  #
@@ -23,6 +32,15 @@ module Pres
23
32
  # present(user, presenter: NiceUserPresenter, cool: true)
24
33
  # => #<NiceUserPresenter object: #<User> ...>
25
34
  #
35
+ # class User
36
+ # def presenter_class
37
+ # MyPresenter
38
+ # end
39
+ # end
40
+ # user = User.new
41
+ # present(user)
42
+ # => #<MyPresenter object: #<User> ...>
43
+ #
26
44
  # present([user])
27
45
  # => [#<UserPresenter object: #<User> ...>]
28
46
  #
@@ -36,6 +54,7 @@ module Pres
36
54
  object.map { |item| present(item, presenter: presenter, **args) }
37
55
  else
38
56
  presenter ||= Presenter if object.nil?
57
+ presenter ||= object.respond_to?(:presenter_class) && object.presenter_class
39
58
  presenter ||= Object.const_get("#{object.class.name}Presenter")
40
59
  wrapper = presenter.new(object, view_context, **args)
41
60
  block_given? ? yield(wrapper) : wrapper
data/lib/pres/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pres
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pres
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tee Parham
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-24 00:00:00.000000000 Z
12
+ date: 2017-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '11.0'
76
+ version: '12.0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '11.0'
83
+ version: '12.0'
84
84
  description: A Simple Rails Presenter base class and controller helper
85
85
  email:
86
86
  - tee@neighborland.com
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.6.7
119
+ rubygems_version: 2.6.8
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: A Simple Rails Presenter