pres 1.1.0 → 1.2.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: 6c26aeb59d5a25f1249d32e9b31c52dd40c55262
4
- data.tar.gz: fe9fb9d51ac9010b57d95cff1c7f00e55d04752d
3
+ metadata.gz: 871d21e9da20da6b0ba8ba1f448c86fb91e24087
4
+ data.tar.gz: ec4a5cca68060275991ea5bd0f13ead4f113c077
5
5
  SHA512:
6
- metadata.gz: e315003283e6fed583e5f8b7399a3640a99b9177a9da67c0eb9adf1e94cdee6d06821979cecb824fef5fc26288177eea5dfd4aa71e8885636ec92afb9769e6b0
7
- data.tar.gz: d47003fd1650d6800cf0b1380b5cd48aeb48279a52f1cfe28bf7bf0e264db2b6b396a1268751b1b9ee58ae2d87053eb3e9cdcd30f92af11b13d780be209f685e
6
+ metadata.gz: 9eb0e651996a5a2712f1b034e914ff69655d34c345583c49f5a273f016829a4543045bc44ce102bbed701a68edff0fac97e81e5fc66c7d3701a1c4a9a90e8e7a
7
+ data.tar.gz: d02df0e3db9d705038b2790ea4cbbc1d0ffbb8f60b2859345650da67a8e336a68a20cb5d7d0492a0558348c4227e669baa4162957fd2c01885e65349ee9bfb5f
data/README.md CHANGED
@@ -15,7 +15,7 @@ Rails' `ViewContext` contains convenience methods for views, such as `link_to`,
15
15
  Rails views nice to work with.
16
16
 
17
17
  Other presenter libraries mix in all the methods from the Rails `ViewContext` to
18
- make it easy to call those methods in the Presenter class. `pres` instead injects
18
+ make it easy to call those methods in the Presenter class. `pres` instead injects
19
19
  the `ViewContext` as a dependency into the Presenter class, and uses `method_missing`
20
20
  to delegate to `ViewContext` methods. `pres` produces small classes that contain and
21
21
  delegate to an existing object that handles server-side rendering.
@@ -36,12 +36,6 @@ class ApplicationController
36
36
  end
37
37
  ```
38
38
 
39
- Add `app/presenters` to your application's autoload paths in `application.rb`:
40
-
41
- ```ruby
42
- config.autoload_paths += %W( #{ config.root }/app/presenters )
43
- ```
44
-
45
39
  ### Usage
46
40
 
47
41
  The quickest way to get started is to use the `Pres::Presenter` base class.
@@ -83,8 +77,7 @@ class DogesController
83
77
 
84
78
  private
85
79
 
86
- helper_method :doge
87
-
80
+ helper_method \
88
81
  def doge
89
82
  @doge ||= present(Doge.find(params[:id]))
90
83
  end
@@ -120,8 +113,7 @@ class DogesController
120
113
 
121
114
  private
122
115
 
123
- helper_method :doges
124
-
116
+ helper_method \
125
117
  def doges
126
118
  @doges ||= present(Doge.all)
127
119
  end
@@ -175,8 +167,8 @@ present(user, presenter: UserEditPresenter, cool: true)
175
167
 
176
168
  #### Creating presenters in views
177
169
 
178
- You should create presenters in your controllers or within other presenters. If you would like to create
179
- a presenter in your view code, make the `present` method visible to your views:
170
+ If you would like to create a presenter in your view code, make the `present` method
171
+ visible to your views.
180
172
 
181
173
  ```ruby
182
174
  class ApplicationController
@@ -185,6 +177,13 @@ class ApplicationController
185
177
  end
186
178
  ```
187
179
 
180
+ This makes it easy to create presenters inline in a view:
181
+
182
+ ```haml
183
+ - present(@doge) do |doge|
184
+ = doge.name_header
185
+ ```
186
+
188
187
  ### Presenters are objects
189
188
 
190
189
  You can mix in common methods.
@@ -267,3 +266,5 @@ Change your code references to `Pres::Presents` and `Pres::Presenter`.
267
266
 
268
267
  * http://nithinbekal.com/posts/rails-presenters/
269
268
  * https://github.com/drapergem/draper
269
+ * http://thepugautomatic.com/2014/03/draper/
270
+ * https://robots.thoughtbot.com/sandi-metz-rules-for-developers
data/lib/pres/presents.rb CHANGED
@@ -14,6 +14,12 @@ module Pres
14
14
  # => #<UserPresenter object: #<User> ...>
15
15
  #
16
16
  # user = User.new
17
+ # present(user) do |up|
18
+ # up.something
19
+ # end
20
+ # up => #<UserPresenter object: #<User> ...>
21
+ #
22
+ # user = User.new
17
23
  # present(user, presenter: NiceUserPresenter, cool: true)
18
24
  # => #<NiceUserPresenter object: #<User> ...>
19
25
  #
@@ -24,13 +30,15 @@ module Pres
24
30
  # => [#<Presenter object: nil ...>]
25
31
  #
26
32
  # Returns a new Presenter object or array of new Presenter objects
33
+ # Yields a new Presenter object if a block is given
27
34
  def present(object, presenter: nil, **args)
28
35
  if object.respond_to?(:to_ary)
29
36
  object.map { |item| present(item, presenter: presenter, **args) }
30
37
  else
31
38
  presenter ||= Presenter if object.nil?
32
39
  presenter ||= Object.const_get("#{object.class.name}Presenter")
33
- presenter.new(object, view_context, **args)
40
+ wrapper = presenter.new(object, view_context, **args)
41
+ block_given? ? yield(wrapper) : wrapper
34
42
  end
35
43
  end
36
44
  end
data/lib/pres/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pres
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.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.1.0
4
+ version: 1.2.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-09-01 00:00:00.000000000 Z
12
+ date: 2016-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -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.6
119
+ rubygems_version: 2.6.7
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: A Simple Rails Presenter