presenter_rails 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +73 -23
- data/lib/presenter_rails/presenter.rb +7 -2
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07380e067bc7857407c563571ab083e00232e426
|
4
|
+
data.tar.gz: 4b783155f31ff25861d81b4cee5041ae8e40ef0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbb4331e7032230fffdd8d84e7ab8e7f62b14017439b3f3b67633f6636e987799c5bc5da8e4b8e1f913208a6fe20c83cd5da935daf91cb528eb4683c8c09f077
|
7
|
+
data.tar.gz: 3ac96ee5bf7174caa128c60ccb1c9d017026eda10beb4ac98f313b5ab073e7852af2d1f29c3ccbf94b7dfd651e2d180d7fc46ec429d451af658f819d579c39d1
|
data/README.md
CHANGED
@@ -1,38 +1,88 @@
|
|
1
|
-
|
1
|
+
Presenter
|
2
2
|
=====================
|
3
3
|
|
4
|
-
|
4
|
+
Presenter helps you expose view models to your views in a convenient way, while
|
5
|
+
still allowing you to define methods with the same name inside your controllers.
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
```ruby
|
8
|
+
# app/controllers/person_controller.rb
|
9
|
+
class PersonController < ApplicationController
|
8
10
|
|
11
|
+
present :person do
|
12
|
+
PersonPresenter.decorate(...)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
```
|
9
16
|
|
10
|
-
|
11
|
-
|
17
|
+
```haml
|
18
|
+
/ app/views/people/show.html.haml
|
19
|
+
.person
|
20
|
+
.person-name= person.name
|
21
|
+
.person-info= person.biography
|
22
|
+
```
|
23
|
+
If you don't provide a block for present, it will assume that you want to expose a `"#{name}_presenter"` method.
|
24
|
+
```ruby
|
25
|
+
# app/controllers/person_controller.rb
|
26
|
+
class PersonController < ApplicationController
|
27
|
+
present :person, :people
|
12
28
|
|
29
|
+
private
|
13
30
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
def person_presenter
|
32
|
+
PersonPresenter.decorate(...)
|
33
|
+
end
|
34
|
+
|
35
|
+
def people_presenter
|
36
|
+
People.all
|
37
|
+
end
|
38
|
+
end
|
18
39
|
```
|
19
40
|
|
20
|
-
|
21
|
-
|
22
|
-
|
41
|
+
## Background
|
42
|
+
Presenter attempts to simplify the exposure of variables to the views. It doesn't really care
|
43
|
+
about what you are exposing, although it's specially useful to implement [two-step views](http://martinfowler.com/eaaCatalog/twoStepView.html) while using
|
44
|
+
[draper](https://github.com/drapergem/draper) in combination with [resourcerer](https://github.com/ElMassimo/resourcerer).
|
23
45
|
|
24
|
-
|
25
|
-
``` ruby
|
26
|
-
:optional => "True if shouldn't fail if document does not exist",
|
46
|
+
### How it works
|
27
47
|
|
28
|
-
|
48
|
+
When you provide a block, it defines a `"#{name}_presenter"` private method in your controller the same way you would do manually.
|
29
49
|
|
30
|
-
|
50
|
+
After that, it creates helper methods for your views, each method calls its `"#{name}_presenter"` counterpart in the controller.
|
31
51
|
|
32
|
-
|
52
|
+
#### Memoization
|
53
|
+
Each presenter method is memoized, so the method is called only once and your views get the same instance every time.
|
54
|
+
|
55
|
+
#### Corolary
|
56
|
+
Since the helper methods defined are only available for the view, you can define methods with the same name in your controller :smiley:.
|
57
|
+
|
58
|
+
License
|
59
|
+
--------
|
60
|
+
|
61
|
+
Copyright (c) 2014 Máximo Mussini
|
62
|
+
|
63
|
+
MIT License
|
64
|
+
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
66
|
+
a copy of this software and associated documentation files (the
|
67
|
+
"Software"), to deal in the Software without restriction, including
|
68
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
69
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
70
|
+
permit persons to whom the Software is furnished to do so, subject to
|
71
|
+
the following conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be
|
74
|
+
included in all copies or substantial portions of the Software.
|
75
|
+
|
76
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
77
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
78
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
79
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
80
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
81
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
82
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
33
83
|
|
34
|
-
:param_key => "Name of the parameter that has the document's attributes"
|
35
|
-
```
|
36
84
|
|
37
|
-
|
38
|
-
|
85
|
+
Credits
|
86
|
+
--------
|
87
|
+
Presenter was crafted to use in combination with [resourcerer](https://github.com/ElMassimo/resourcerer) and
|
88
|
+
[draper](https://github.com/drapergem/draper).
|
@@ -1,7 +1,12 @@
|
|
1
|
+
require 'pakiderm'
|
2
|
+
|
1
3
|
module PresenterRails
|
2
4
|
module Presenter
|
3
5
|
extend ActiveSupport::Concern
|
4
|
-
|
6
|
+
|
7
|
+
included do
|
8
|
+
extend Pakiderm
|
9
|
+
end
|
5
10
|
|
6
11
|
module ClassMethods
|
7
12
|
|
@@ -11,7 +16,7 @@ module PresenterRails
|
|
11
16
|
define_presenter_method!(presenter_methods, &block) if block_given?
|
12
17
|
|
13
18
|
expose_presenter *methods
|
14
|
-
memoize *presenter_methods
|
19
|
+
memoize *presenter_methods, assignable: true
|
15
20
|
end
|
16
21
|
|
17
22
|
# Exposes a presenter method to the view for each provided name
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presenter_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pakiderm
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Presenter helps you expose view models to your views with a declarative
|
@@ -56,17 +56,17 @@ licenses:
|
|
56
56
|
metadata: {}
|
57
57
|
post_install_message:
|
58
58
|
rdoc_options:
|
59
|
-
- --charset=UTF-8
|
59
|
+
- "--charset=UTF-8"
|
60
60
|
require_paths:
|
61
61
|
- lib
|
62
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '2.0'
|
67
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
@@ -76,3 +76,4 @@ signing_key:
|
|
76
76
|
specification_version: 4
|
77
77
|
summary: ViewModels had a baby with helper_method
|
78
78
|
test_files: []
|
79
|
+
has_rdoc:
|