easy_presenter 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 +40 -2
- data/lib/easy_presenter/version.rb +1 -1
- data/lib/easy_presenter.rb +13 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0a86beeb7a5bcf06f9eba3edf7a1def8cfd4269
|
4
|
+
data.tar.gz: 7c8a99589f8221df2e7d1f6f3723eb691d94f491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7ada92812250dd0e5824e473ab18dd001136d568fd9ab6bd2075a09c3445bc7a635bc88fcc94a19516a687fea2bea295c8209f34e401464513156454c23bc0e
|
7
|
+
data.tar.gz: 2fea4d3703aaade50bbfd077d79c9d9b64a48de757b728a9459e9bcdcdf0c874bddc9507c91dd47a22e99305c35174599899de31f118e188c03397f0779abe88
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# EasyPresenter
|
2
2
|
|
3
|
-
Access view methods from the context of your model.
|
3
|
+
Access view methods from the context of your `Ruby on Rails` model.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
### Easy
|
@@ -55,11 +55,49 @@ end
|
|
55
55
|
`ActiveRecord`, `Mongoid`, you may add support to an ORM at the bottom of `lib/easy_presenter.rb` and send in a pull request if you wish.
|
56
56
|
|
57
57
|
### Advanced
|
58
|
-
You may
|
58
|
+
You may `include` the following modules to add EasyPresenter to other classes.
|
59
59
|
|
60
|
+
* `easy_presenter_subclass` - for handling subclasses
|
60
61
|
* `EasyPresenter::Base` - add access to view methods
|
61
62
|
* `EasyPresenter` - `EasyPresenter::Base` and if `method_missing?`, give access to the `ClassNamePresenter` class
|
62
63
|
|
64
|
+
|
65
|
+
To add access to view methods to all instances or subclasses (such as an ORM).
|
66
|
+
```ruby
|
67
|
+
# config/initializers/add_presenter_to_orm.rb
|
68
|
+
# Find the base or shared class, for `ActiveRecord` it's `ActiveRecord::Base` and `Mongoid` it's `Mongoid::Document`
|
69
|
+
Orm::BaseClass.send :include, EasyPresenter
|
70
|
+
```
|
71
|
+
|
72
|
+
For all instances of a basic class.
|
73
|
+
```ruby
|
74
|
+
# app/models/non_database_model.rb
|
75
|
+
class NonDatabaseModel
|
76
|
+
include EasyPresenter
|
77
|
+
end
|
78
|
+
|
79
|
+
# app/presenters/non_database_model_presenter.rb
|
80
|
+
module NonDatabaseModelPresenter
|
81
|
+
...
|
82
|
+
|
83
|
+
module ClassMethods
|
84
|
+
...
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
For all instances of a basic class without need of a `ClassNamePresenter` class.
|
90
|
+
```ruby
|
91
|
+
# app/models/some_view_object.rb
|
92
|
+
class SomeViewObject
|
93
|
+
include EasyPresenter::Base
|
94
|
+
|
95
|
+
def random_link
|
96
|
+
link_to "random", "http://www.random.com"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
63
101
|
## Credits
|
64
102
|
Extracted out of [Placemark](https://www.placemarkhq.com/).
|
65
103
|
|
data/lib/easy_presenter.rb
CHANGED
@@ -6,11 +6,19 @@ module EasyPresenter
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
easy_presenter_subclass
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
protected
|
14
|
+
def easy_presenter_subclass
|
15
|
+
presenter_class = "#{self}Presenter".safe_constantize
|
16
|
+
if presenter_class
|
17
|
+
presenter_class.extend ActiveSupport::Concern
|
18
|
+
include presenter_class
|
19
|
+
include Base
|
20
|
+
end
|
21
|
+
presenter_class
|
14
22
|
end
|
15
23
|
end
|
16
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_presenter
|
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
|
- s12chung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|