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 +4 -4
- data/README.md +7 -3
- data/lib/pres/presents.rb +5 -1
- data/lib/pres/version.rb +1 -1
- data/test/presents_test.rb +5 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e2c8712efee843e682f2e3182e2f64023915c3
|
4
|
+
data.tar.gz: c49375a53ac4065124d60d21abf975d7399f577b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
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 `
|
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
data/test/presents_test.rb
CHANGED
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
|
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-
|
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.
|
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:
|