prospecto 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +23 -19
- data/lib/prospecto/presenter_view.rb +2 -2
- data/lib/prospecto/version.rb +1 -1
- metadata +8 -19
data/README.md
CHANGED
@@ -23,25 +23,27 @@ There are 2 problems that prospecto was created to solve.
|
|
23
23
|
1. Views are hard and ineffective to test.
|
24
24
|
2. Code is often common between the output formats.
|
25
25
|
|
26
|
-
We feel that (our interpretation of) the presenter pattern is the answer to
|
27
|
-
do not need a library to implement the
|
28
|
-
|
26
|
+
We feel that (our interpretation of) the presenter pattern is the answer to
|
27
|
+
these problems. To be clear, you do not need a library to implement the
|
28
|
+
presenter pattern. The purpose of prospecto is to provide some syntactic sugar
|
29
|
+
and structure.
|
29
30
|
|
30
31
|
## Usage
|
31
32
|
|
32
33
|
### ApplicationPresenter
|
33
34
|
|
34
|
-
To start it is recommended (but not required) that you generate an
|
35
|
-
as a base class for all other presenters
|
36
|
-
generator:
|
35
|
+
To start it is recommended (but not required) that you generate an
|
36
|
+
`ApplicationPresenter`. This will act as a base class for all other presenters
|
37
|
+
much like an `ApplicationController`. Just use the built in generator:
|
37
38
|
|
38
39
|
$ rails generate prospecto:install
|
39
40
|
|
40
41
|
### Presenter
|
41
42
|
|
42
|
-
You are now ready to start creating presenters. In prospecto a presenter does
|
43
|
-
a model (though this often ends up as the case),
|
44
|
-
|
43
|
+
You are now ready to start creating presenters. In prospecto a presenter does
|
44
|
+
not necessarily correlate with a model (though this often ends up as the case),
|
45
|
+
instead a presenter represents a view or family of views depending on the
|
46
|
+
situation. This is up to you to decide.
|
45
47
|
|
46
48
|
To create a simple presenter use the included generator:
|
47
49
|
|
@@ -49,8 +51,9 @@ To create a simple presenter use the included generator:
|
|
49
51
|
|
50
52
|
### Prospecto::PresenterView
|
51
53
|
|
52
|
-
By default all presenters inherit from the `Prospecto::PresenterView` class.
|
53
|
-
solely to provide some sugar for creating
|
54
|
+
By default all presenters inherit from the `Prospecto::PresenterView` class.
|
55
|
+
This class is optional and exists solely to provide some sugar for creating
|
56
|
+
constructors for objects.
|
54
57
|
|
55
58
|
#### accepts
|
56
59
|
|
@@ -73,8 +76,8 @@ puts user.name
|
|
73
76
|
#### decorates
|
74
77
|
|
75
78
|
The `decorates` method allows the provided value to be accessed directly on the
|
76
|
-
presenter. This is simalar to how something like
|
77
|
-
works.
|
79
|
+
presenter. This is simalar to how something like
|
80
|
+
[draper](https://github.com/jcasimir/draper) works.
|
78
81
|
|
79
82
|
``` ruby
|
80
83
|
class UserPresenter < Prospecto::PresenterView
|
@@ -87,7 +90,8 @@ puts "#{view.first} #{view.last}"
|
|
87
90
|
|
88
91
|
#### proxies
|
89
92
|
|
90
|
-
The `proxies` method creates named methods on the presenter for the provided
|
93
|
+
The `proxies` method creates named methods on the presenter for the provided
|
94
|
+
value.
|
91
95
|
|
92
96
|
``` ruby
|
93
97
|
class UserPresenter < Prospecto::PresenterView
|
@@ -114,9 +118,9 @@ puts "#{view.user_public.first} #{view.user_public.last}"
|
|
114
118
|
|
115
119
|
### Rails Views and Controllers
|
116
120
|
|
117
|
-
How you use the presenters is very loose. Since you are just dealing with
|
118
|
-
ruby objects you can instantiate where it makes the most sense
|
119
|
-
basic usage looks something like this.
|
121
|
+
How you use the presenters is very loose. Since you are just dealing with
|
122
|
+
pretty vanilla ruby objects you can instantiate where it makes the most sense
|
123
|
+
for your project. Usually basic usage looks something like this.
|
120
124
|
|
121
125
|
``` ruby
|
122
126
|
class UserController < ApplicationController
|
@@ -139,5 +143,5 @@ You then use the `@view` object like normal in the view.
|
|
139
143
|
|
140
144
|
## Sponsor
|
141
145
|
|
142
|
-
Development for prospecto is sponsored mainly by my employer
|
143
|
-
since we use it heavily in house.
|
146
|
+
Development for prospecto is sponsored mainly by my employer
|
147
|
+
[Voonami](http://www.voonami.com) since we use it heavily in house.
|
@@ -24,9 +24,9 @@ module Prospecto
|
|
24
24
|
def method_missing(name, *args, &block)
|
25
25
|
if property_name = self.class.__properties.find{|m| name.to_s.start_with? "#{m}_"}
|
26
26
|
field_name = name.to_s.sub("#{property_name}_", "")
|
27
|
-
self.send(property_name).send(field_name)
|
27
|
+
self.send(property_name).send(field_name, *args, &block)
|
28
28
|
elsif delegate_obj = __delegates.find{|d| d.respond_to? name}
|
29
|
-
delegate_obj.send(name)
|
29
|
+
delegate_obj.send(name, *args, &block)
|
30
30
|
else
|
31
31
|
super
|
32
32
|
end
|
data/lib/prospecto/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prospecto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70201111619740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70201111619740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70201111618300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,18 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: pry
|
38
|
-
requirement: &70113014262840 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0'
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *70113014262840
|
35
|
+
version_requirements: *70201111618300
|
47
36
|
description: ''
|
48
37
|
email:
|
49
38
|
- bigjasonwebb@gmail.com
|
@@ -81,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
70
|
version: '0'
|
82
71
|
segments:
|
83
72
|
- 0
|
84
|
-
hash:
|
73
|
+
hash: 3769703894804639949
|
85
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
75
|
none: false
|
87
76
|
requirements:
|
@@ -90,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
79
|
version: '0'
|
91
80
|
segments:
|
92
81
|
- 0
|
93
|
-
hash:
|
82
|
+
hash: 3769703894804639949
|
94
83
|
requirements: []
|
95
84
|
rubyforge_project:
|
96
85
|
rubygems_version: 1.8.10
|