pres 0.0.2 → 0.1.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: 6362f45f6a774da5fd8d1fc0380daac5cb7a2504
4
- data.tar.gz: ca32363ebe601d5f94ea980565e2334cc63c4e1e
3
+ metadata.gz: 52e2c8712efee843e682f2e3182e2f64023915c3
4
+ data.tar.gz: c49375a53ac4065124d60d21abf975d7399f577b
5
5
  SHA512:
6
- metadata.gz: 09b506de976b7f4ece0eba3bf3b22587da6dba6fe0cda2a4bb1f74ccd584f5f90e5611b6e385b61586b61cfa9db753eb705731f080fe752f990bc95a35cdc60f
7
- data.tar.gz: d593aa5a5dbfaa48f5156016fe339a7b126009970c8232e79e6ce4a6a33d38661ae88e855bc3034de9813d81ca3037a9685059aec6c569c34d520455e006599e
6
+ metadata.gz: fac9d779069f6e4cc5b17f476fd9755f79d9d942451c0f48d8cadc50bbc83207fcaa79b90b7085bd40f05b50e42d281b78fc5e068ed38fa650f23bb415aa2a6e
7
+ data.tar.gz: a04a2234a5025980b4063c40ca7a1c9817c7b6ece10ea44f0f50548a6ab3d56e109419157c070f69ab55f9a671e17b077dbed4aef205d4c79e9cca7a03ece43f
data/README.md CHANGED
@@ -58,7 +58,7 @@ class DogePresenter < Presenter
58
58
 
59
59
  def name_header
60
60
  # object is the Doge
61
- content_tag(:h1, objec†.name)
61
+ content_tag(:h1, object.name)
62
62
  end
63
63
 
64
64
  def signed_in_status
@@ -80,7 +80,9 @@ class DogesController
80
80
  end
81
81
 
82
82
  private
83
-
83
+
84
+ helper_method :doge
85
+
84
86
  def doge
85
87
  @doge ||= present(Doge.find(params[:id]))
86
88
  end
@@ -116,6 +118,8 @@ class DogesController
116
118
 
117
119
  private
118
120
 
121
+ helper_method :doges
122
+
119
123
  def doges
120
124
  @doges ||= present(Doge.all)
121
125
  end
@@ -173,7 +177,7 @@ present(User.first(5))
173
177
  #### Creating presenters in views
174
178
 
175
179
  You should create presenters in your controllers. If you would like to create
176
- a presenter in your view code, make the `presents` method visible to your views:
180
+ a presenter in your view code, make the `present` method visible to your views:
177
181
 
178
182
  ```ruby
179
183
  class ApplicationController
data/lib/pres/presents.rb CHANGED
@@ -3,7 +3,7 @@ module Presents
3
3
 
4
4
  # Wrap an object or collection of objects with a presenter class.
5
5
  #
6
- # object - a ruby class
6
+ # object - a ruby class, or nil
7
7
  # presenter - a Presenter class (optional)
8
8
  #
9
9
  # Examples
@@ -19,11 +19,15 @@ module Presents
19
19
  # present([user])
20
20
  # => [#<UserPresenter object: #<User> ...>]
21
21
  #
22
+ # present(nil)
23
+ # => [#<Presenter object: nil ...>]
24
+ #
22
25
  # Returns a new Presenter object or array of new Presenter objects
23
26
  def present(object, presenter: nil, **args)
24
27
  if object.respond_to?(:to_ary)
25
28
  object.map { |item| present(item, presenter: presenter, **args) }
26
29
  else
30
+ presenter ||= Presenter if object.nil?
27
31
  presenter ||= Object.const_get("#{ object.class.name }Presenter")
28
32
  presenter.new(object, view_context, **args)
29
33
  end
data/lib/pres/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pres
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -51,4 +51,9 @@ describe Presents do
51
51
  assert_equal 2, presenters.size
52
52
  assert presenters[0].is_a?(VeryDogePresenter)
53
53
  end
54
+
55
+ it "creates the default presenter for nil object" do
56
+ presenter = controller.wrap(nil)
57
+ assert presenter.is_a?(Presenter)
58
+ end
54
59
  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: 0.0.2
4
+ version: 0.1.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: 2015-01-30 00:00:00.000000000 Z
12
+ date: 2015-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.4.5
123
+ rubygems_version: 2.4.6
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: A Simple Rails Presenter
@@ -130,4 +130,3 @@ test_files:
130
130
  - test/presenter_test.rb
131
131
  - test/presents_test.rb
132
132
  - test/test_helper.rb
133
- has_rdoc: