draper 0.7.3 → 0.7.4
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/.gitignore +1 -0
- data/.yardopts +1 -0
- data/Gemfile +1 -0
- data/Readme.markdown +32 -17
- data/doc/ApplicationDecorator.html +147 -0
- data/doc/Draper.html +123 -0
- data/doc/Draper/AllHelpers.html +256 -0
- data/doc/Draper/Base.html +1222 -0
- data/doc/Draper/DecoratorGenerator.html +216 -0
- data/doc/Draper/LazyHelpers.html +174 -0
- data/doc/Draper/ModelSupport.html +164 -0
- data/doc/Draper/System.html +179 -0
- data/doc/_index.html +172 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +53 -0
- data/doc/css/style.css +320 -0
- data/doc/file_list.html +46 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +172 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +150 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +174 -0
- data/doc/top-level-namespace.html +103 -0
- data/lib/draper/base.rb +100 -15
- data/lib/draper/model_support.rb +1 -0
- data/lib/draper/version.rb +1 -1
- data/lib/generators/rails/decorator_generator.rb +15 -0
- data/spec/base_spec.rb +16 -3
- data/spec/draper/model_support_spec.rb +5 -0
- data/spec/samples/active_record.rb +1 -4
- data/spec/samples/decorator_with_allows.rb +1 -1
- data/spec/samples/product_decorator.rb +4 -0
- metadata +45 -40
data/.gitignore
CHANGED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
yardoc 'lib/draper/**/*.rb' -m markdown
|
data/Gemfile
CHANGED
data/Readme.markdown
CHANGED
@@ -28,7 +28,7 @@ This gem makes it easy to apply the decorator pattern to domain models in a Rail
|
|
28
28
|
|
29
29
|
### 1. Object Oriented Helpers
|
30
30
|
|
31
|
-
Why hate helpers? In Ruby/Rails we approach everything from an Object-Oriented perspective, then with helpers we get procedural.The job of a helper is to take in data and output a presentation-ready string. We can do that with a decorator.
|
31
|
+
Why hate normal helpers? In Ruby/Rails we approach everything from an Object-Oriented perspective, then with helpers we get procedural.The job of a helper is to take in data and output a presentation-ready string. We can do that with a decorator.
|
32
32
|
|
33
33
|
A decorator wraps an object with presentation-related accessor methods. For instance, if you had an `Article` object, then the decorator could override `.published_at` to use formatted output like this:
|
34
34
|
|
@@ -102,11 +102,11 @@ end
|
|
102
102
|
```
|
103
103
|
|
104
104
|
```irb
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
> ad = ArticleDecorator.find(1)
|
106
|
+
=> #<ArticleDecorator:0x000001020d7728 @model=#<Article id: 1, title: "Hello, World">>
|
107
|
+
> ad.title
|
108
|
+
=> "Hello, World"
|
109
|
+
> ad.created_at
|
110
110
|
NoMethodError: undefined method `created_at' for #<ArticleDecorator:0x000001020d7728>
|
111
111
|
```
|
112
112
|
|
@@ -135,9 +135,22 @@ config.generators do |g|
|
|
135
135
|
g.helper false
|
136
136
|
end
|
137
137
|
```
|
138
|
-
|
139
138
|
If you want a helper, you can still call `rails generate helper` directly.
|
140
139
|
|
140
|
+
|
141
|
+
#### Add DecoratorGenerator to ActiveRecord Generator (Optional)
|
142
|
+
|
143
|
+
Add the following to your `config/application.rb`
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
config.generators do |g|
|
147
|
+
g.orm :decorator, :invoke_after_finished => "active_record:model"
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
From now on, every model you generate will first invoke the DecoratorGenerator. The Decorator will then invoke the active_record:model Generator.
|
152
|
+
|
153
|
+
|
141
154
|
### Generate the Decorator
|
142
155
|
|
143
156
|
To decorate a model named `Article`:
|
@@ -199,20 +212,22 @@ When writing your controller actions, you have three options:
|
|
199
212
|
|
200
213
|
* Call `.new` and pass in the object to be wrapped
|
201
214
|
|
202
|
-
|
203
|
-
|
204
|
-
|
215
|
+
```ruby
|
216
|
+
ArticleDecorator.new(Article.find(params[:id]))`
|
217
|
+
```
|
205
218
|
|
206
219
|
* Call `.decorate` and pass in an object or collection of objects to be wrapped:
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
ArticleDecorator.decorate(Article.first) # Returns one instance of ArticleDecorator
|
223
|
+
ArticleDecorator.decorate(Article.all) # Returns an array of ArticleDecorator instances
|
224
|
+
```
|
211
225
|
|
212
226
|
* Call `.find` to do automatically do a lookup on the `decorates` class:
|
213
|
-
|
214
|
-
|
215
|
-
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
ArticleDecorator.find(1)
|
230
|
+
```
|
216
231
|
|
217
232
|
### In Your Views
|
218
233
|
|
@@ -0,0 +1,147 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Class: ApplicationDecorator
|
8
|
+
|
9
|
+
— Documentation by YARD 0.7.2
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
relpath = '';
|
19
|
+
if (relpath != '') relpath += '/';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
25
|
+
|
26
|
+
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<script type="text/javascript" charset="utf-8">
|
30
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<div id="header">
|
34
|
+
<div id="menu">
|
35
|
+
|
36
|
+
<a href="_index.html">Index (A)</a> »
|
37
|
+
|
38
|
+
|
39
|
+
<span class="title">ApplicationDecorator</span>
|
40
|
+
|
41
|
+
|
42
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div id="search">
|
46
|
+
|
47
|
+
<a id="class_list_link" href="#">Class List</a>
|
48
|
+
|
49
|
+
<a id="method_list_link" href="#">Method List</a>
|
50
|
+
|
51
|
+
<a id="file_list_link" href="#">File List</a>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
<div class="clear"></div>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<iframe id="search_frame"></iframe>
|
58
|
+
|
59
|
+
<div id="content"><h1>Class: ApplicationDecorator
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
</h1>
|
64
|
+
|
65
|
+
<dl class="box">
|
66
|
+
|
67
|
+
<dt class="r1">Inherits:</dt>
|
68
|
+
<dd class="r1">
|
69
|
+
<span class="inheritName"><span class='object_link'><a href="Draper/Base.html" title="Draper::Base (class)">Draper::Base</a></span></span>
|
70
|
+
|
71
|
+
<ul class="fullTree">
|
72
|
+
<li>Object</li>
|
73
|
+
|
74
|
+
<li class="next"><span class='object_link'><a href="Draper/Base.html" title="Draper::Base (class)">Draper::Base</a></span></li>
|
75
|
+
|
76
|
+
<li class="next">ApplicationDecorator</li>
|
77
|
+
|
78
|
+
</ul>
|
79
|
+
<a href="#" class="inheritanceTree">show all</a>
|
80
|
+
|
81
|
+
</dd>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
<dt class="r2 last">Defined in:</dt>
|
92
|
+
<dd class="r2 last">lib/generators/draper/decorator/templates/application_decorator.rb</dd>
|
93
|
+
|
94
|
+
</dl>
|
95
|
+
<div class="clear"></div>
|
96
|
+
|
97
|
+
|
98
|
+
<h2>Constant Summary</h2>
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
<h3 class="inherited">Constants inherited from <span class='object_link'><a href="Draper/Base.html" title="Draper::Base (class)">Draper::Base</a></span></h3>
|
107
|
+
<p class="inherited"><span class='object_link'><a href="Draper/Base.html#DEFAULT_DENIED-constant" title="Draper::Base::DEFAULT_DENIED (constant)">DEFAULT_DENIED</a></span>, <span class='object_link'><a href="Draper/Base.html#FORCED_PROXY-constant" title="Draper::Base::FORCED_PROXY (constant)">FORCED_PROXY</a></span></p>
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
<h2>Instance Attribute Summary</h2>
|
115
|
+
|
116
|
+
<h3 class="inherited">Attributes inherited from <span class='object_link'><a href="Draper/Base.html" title="Draper::Base (class)">Draper::Base</a></span></h3>
|
117
|
+
<p class="inherited"><span class='object_link'><a href="Draper/Base.html#context-instance_method" title="Draper::Base#context (method)">context</a></span>, <span class='object_link'><a href="Draper/Base.html#model-instance_method" title="Draper::Base#model (method)">model</a></span></p>
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
<h2>Method Summary</h2>
|
127
|
+
|
128
|
+
<h3 class="inherited">Methods inherited from <span class='object_link'><a href="Draper/Base.html" title="Draper::Base (class)">Draper::Base</a></span></h3>
|
129
|
+
<p class="inherited"><span class='object_link'><a href="Draper/Base.html#allows-class_method" title="Draper::Base.allows (method)">allows</a></span>, <span class='object_link'><a href="Draper/Base.html#decorate-class_method" title="Draper::Base.decorate (method)">decorate</a></span>, <span class='object_link'><a href="Draper/Base.html#decorates-class_method" title="Draper::Base.decorates (method)">decorates</a></span>, <span class='object_link'><a href="Draper/Base.html#denies-class_method" title="Draper::Base.denies (method)">denies</a></span>, <span class='object_link'><a href="Draper/Base.html#find-class_method" title="Draper::Base.find (method)">find</a></span>, <span class='object_link'><a href="Draper/Base.html#helpers-instance_method" title="Draper::Base#helpers (method)">#helpers</a></span>, <span class='object_link'><a href="Draper/Base.html#initialize-instance_method" title="Draper::Base#initialize (method)">#initialize</a></span>, <span class='object_link'><a href="Draper/Base.html#lazy_helpers-class_method" title="Draper::Base.lazy_helpers (method)">lazy_helpers</a></span>, <span class='object_link'><a href="Draper/Base.html#model_name-class_method" title="Draper::Base.model_name (method)">model_name</a></span>, <span class='object_link'><a href="Draper/Base.html#to_model-instance_method" title="Draper::Base#to_model (method)">#to_model</a></span></p>
|
130
|
+
<div id="constructor_details" class="method_details_list">
|
131
|
+
<h2>Constructor Details</h2>
|
132
|
+
|
133
|
+
<p class="notice">This class inherits a constructor from <span class='object_link'><a href="Draper/Base.html#initialize-instance_method" title="Draper::Base#initialize (method)">Draper::Base</a></span></p>
|
134
|
+
|
135
|
+
</div>
|
136
|
+
|
137
|
+
|
138
|
+
</div>
|
139
|
+
|
140
|
+
<div id="footer">
|
141
|
+
Generated on Wed Aug 31 23:53:09 2011 by
|
142
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
143
|
+
0.7.2 (ruby-1.8.7).
|
144
|
+
</div>
|
145
|
+
|
146
|
+
</body>
|
147
|
+
</html>
|
data/doc/Draper.html
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Draper
|
8
|
+
|
9
|
+
— Documentation by YARD 0.7.2
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
relpath = '';
|
19
|
+
if (relpath != '') relpath += '/';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
25
|
+
|
26
|
+
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<script type="text/javascript" charset="utf-8">
|
30
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<div id="header">
|
34
|
+
<div id="menu">
|
35
|
+
|
36
|
+
<a href="_index.html">Index (D)</a> »
|
37
|
+
|
38
|
+
|
39
|
+
<span class="title">Draper</span>
|
40
|
+
|
41
|
+
|
42
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div id="search">
|
46
|
+
|
47
|
+
<a id="class_list_link" href="#">Class List</a>
|
48
|
+
|
49
|
+
<a id="method_list_link" href="#">Method List</a>
|
50
|
+
|
51
|
+
<a id="file_list_link" href="#">File List</a>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
<div class="clear"></div>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<iframe id="search_frame"></iframe>
|
58
|
+
|
59
|
+
<div id="content"><h1>Module: Draper
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
</h1>
|
64
|
+
|
65
|
+
<dl class="box">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
<dt class="r1 last">Defined in:</dt>
|
75
|
+
<dd class="r1 last">lib/draper/base.rb<span class="defines">,<br />
|
76
|
+
lib/draper/system.rb,<br /> lib/draper/version.rb,<br /> lib/draper/all_helpers.rb,<br /> lib/draper/lazy_helpers.rb</span>
|
77
|
+
</dd>
|
78
|
+
|
79
|
+
</dl>
|
80
|
+
<div class="clear"></div>
|
81
|
+
|
82
|
+
<h2>Defined Under Namespace</h2>
|
83
|
+
<p class="children">
|
84
|
+
|
85
|
+
|
86
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Draper/AllHelpers.html" title="Draper::AllHelpers (module)">AllHelpers</a></span>, <span class='object_link'><a href="Draper/LazyHelpers.html" title="Draper::LazyHelpers (module)">LazyHelpers</a></span>, <span class='object_link'><a href="Draper/ModelSupport.html" title="Draper::ModelSupport (module)">ModelSupport</a></span>
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Draper/Base.html" title="Draper::Base (class)">Base</a></span>, <span class='object_link'><a href="Draper/System.html" title="Draper::System (class)">System</a></span>
|
91
|
+
|
92
|
+
|
93
|
+
</p>
|
94
|
+
|
95
|
+
<h2>Constant Summary</h2>
|
96
|
+
|
97
|
+
<dl class="constants">
|
98
|
+
|
99
|
+
<dt id="VERSION-constant" class="">VERSION =
|
100
|
+
|
101
|
+
</dt>
|
102
|
+
<dd><pre class="code"><span class='string val'>"0.7.3"</span>
|
103
|
+
</pre></dd>
|
104
|
+
|
105
|
+
</dl>
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
</div>
|
115
|
+
|
116
|
+
<div id="footer">
|
117
|
+
Generated on Thu Sep 1 01:13:36 2011 by
|
118
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
119
|
+
0.7.2 (ruby-1.8.7).
|
120
|
+
</div>
|
121
|
+
|
122
|
+
</body>
|
123
|
+
</html>
|
@@ -0,0 +1,256 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Draper::AllHelpers
|
8
|
+
|
9
|
+
— Documentation by YARD 0.7.2
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
relpath = '..';
|
19
|
+
if (relpath != '') relpath += '/';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
25
|
+
|
26
|
+
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<script type="text/javascript" charset="utf-8">
|
30
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<div id="header">
|
34
|
+
<div id="menu">
|
35
|
+
|
36
|
+
<a href="../_index.html">Index (A)</a> »
|
37
|
+
<span class='title'><span class='object_link'><a href="../Draper.html" title="Draper (module)">Draper</a></span></span>
|
38
|
+
»
|
39
|
+
<span class="title">AllHelpers</span>
|
40
|
+
|
41
|
+
|
42
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div id="search">
|
46
|
+
|
47
|
+
<a id="class_list_link" href="#">Class List</a>
|
48
|
+
|
49
|
+
<a id="method_list_link" href="#">Method List</a>
|
50
|
+
|
51
|
+
<a id="file_list_link" href="#">File List</a>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
<div class="clear"></div>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<iframe id="search_frame"></iframe>
|
58
|
+
|
59
|
+
<div id="content"><h1>Module: Draper::AllHelpers
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
</h1>
|
64
|
+
|
65
|
+
<dl class="box">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
<dt class="r1 last">Defined in:</dt>
|
75
|
+
<dd class="r1 last">lib/draper/all_helpers.rb</dd>
|
76
|
+
|
77
|
+
</dl>
|
78
|
+
<div class="clear"></div>
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
<h2>
|
87
|
+
Instance Method Summary
|
88
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
89
|
+
</h2>
|
90
|
+
|
91
|
+
<ul class="summary">
|
92
|
+
|
93
|
+
<li class="public ">
|
94
|
+
<span class="summary_signature">
|
95
|
+
|
96
|
+
<a href="#all_helpers-instance_method" title="#all_helpers (instance method)">- (Object) <strong>all_helpers</strong> </a>
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
</span>
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<span class="summary_desc"><div class='inline'><p>Most of the black magic here thanks to Xavier Shay (@xshay)
|
110
|
+
Provide access to helper methods from outside controllers and views,
|
111
|
+
such as in Presenter objects.</p>
|
112
|
+
</div></span>
|
113
|
+
|
114
|
+
</li>
|
115
|
+
|
116
|
+
|
117
|
+
</ul>
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
<div id="instance_method_details" class="method_details_list">
|
123
|
+
<h2>Instance Method Details</h2>
|
124
|
+
|
125
|
+
|
126
|
+
<div class="method_details first">
|
127
|
+
<p class="signature first" id="all_helpers-instance_method">
|
128
|
+
|
129
|
+
- (<tt>Object</tt>) <strong>all_helpers</strong>
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
</p><div class="docstring">
|
134
|
+
<div class="discussion">
|
135
|
+
<p>Most of the black magic here thanks to Xavier Shay (@xshay)
|
136
|
+
Provide access to helper methods from outside controllers and views,
|
137
|
+
such as in Presenter objects. Rails provides ActionController::Base.helpers,
|
138
|
+
but this does not include any of our application helpers.</p>
|
139
|
+
|
140
|
+
|
141
|
+
</div>
|
142
|
+
</div>
|
143
|
+
<div class="tags">
|
144
|
+
|
145
|
+
</div><table class="source_code">
|
146
|
+
<tr>
|
147
|
+
<td>
|
148
|
+
<pre class="lines">
|
149
|
+
|
150
|
+
|
151
|
+
7
|
152
|
+
8
|
153
|
+
9
|
154
|
+
10
|
155
|
+
11
|
156
|
+
12
|
157
|
+
13
|
158
|
+
14
|
159
|
+
15
|
160
|
+
16
|
161
|
+
17
|
162
|
+
18
|
163
|
+
19
|
164
|
+
20
|
165
|
+
21
|
166
|
+
22
|
167
|
+
23
|
168
|
+
24
|
169
|
+
25
|
170
|
+
26
|
171
|
+
27
|
172
|
+
28
|
173
|
+
29
|
174
|
+
30
|
175
|
+
31
|
176
|
+
32
|
177
|
+
33
|
178
|
+
34
|
179
|
+
35
|
180
|
+
36
|
181
|
+
37
|
182
|
+
38
|
183
|
+
39
|
184
|
+
40
|
185
|
+
41
|
186
|
+
42
|
187
|
+
43
|
188
|
+
44
|
189
|
+
45
|
190
|
+
46
|
191
|
+
47
|
192
|
+
48</pre>
|
193
|
+
</td>
|
194
|
+
<td>
|
195
|
+
<pre class="code"><span class="info file"># File 'lib/draper/all_helpers.rb', line 7</span>
|
196
|
+
|
197
|
+
<span class='def def kw'>def</span> <span class='all_helpers identifier id'>all_helpers</span>
|
198
|
+
<span class='@all_helpers_proxy ivar id'>@all_helpers_proxy</span> <span class='opasgn op'>||=</span> <span class='begin begin kw'>begin</span>
|
199
|
+
<span class='comment val'># Start with just the rails helpers. This is the same method used</span>
|
200
|
+
<span class='comment val'># by ActionController::Base.helpers</span>
|
201
|
+
<span class='comment val'># proxy = ActionView::Base.new.extend(_helpers)</span>
|
202
|
+
<span class='proxy identifier id'>proxy</span> <span class='assign token'>=</span> <span class='ActionController constant id'>ActionController</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='helpers identifier id'>helpers</span>
|
203
|
+
|
204
|
+
<span class='comment val'># url_for depends on _routes method being defined</span>
|
205
|
+
<span class='proxy identifier id'>proxy</span><span class='dot token'>.</span><span class='instance_eval identifier id'>instance_eval</span> <span class='do do kw'>do</span>
|
206
|
+
<span class='def def kw'>def</span> <span class='_routes identifier id'>_routes</span>
|
207
|
+
<span class='Rails constant id'>Rails</span><span class='dot token'>.</span><span class='application identifier id'>application</span><span class='dot token'>.</span><span class='routes identifier id'>routes</span>
|
208
|
+
<span class='end end kw'>end</span>
|
209
|
+
<span class='end end kw'>end</span>
|
210
|
+
|
211
|
+
<span class='comment val'># Import all named path methods</span>
|
212
|
+
<span class='proxy identifier id'>proxy</span><span class='dot token'>.</span><span class='extend identifier id'>extend</span><span class='lparen token'>(</span><span class='Rails constant id'>Rails</span><span class='dot token'>.</span><span class='application identifier id'>application</span><span class='dot token'>.</span><span class='routes identifier id'>routes</span><span class='dot token'>.</span><span class='named_routes identifier id'>named_routes</span><span class='dot token'>.</span><span class='module identifier id'>module</span><span class='rparen token'>)</span>
|
213
|
+
|
214
|
+
<span class='comment val'># Load all our application helpers to extend</span>
|
215
|
+
<span class='modules_for_helpers identifier id'>modules_for_helpers</span><span class='lparen token'>(</span><span class='lbrack token'>[</span><span class='symbol val'>:all</span><span class='rbrack token'>]</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='each identifier id'>each</span> <span class='do do kw'>do</span> <span class='bitor op'>|</span><span class='mod identifier id'>mod</span><span class='bitor op'>|</span>
|
216
|
+
<span class='proxy identifier id'>proxy</span><span class='dot token'>.</span><span class='extend identifier id'>extend</span><span class='lparen token'>(</span><span class='mod identifier id'>mod</span><span class='rparen token'>)</span>
|
217
|
+
<span class='end end kw'>end</span>
|
218
|
+
|
219
|
+
<span class='proxy identifier id'>proxy</span><span class='dot token'>.</span><span class='instance_eval identifier id'>instance_eval</span> <span class='do do kw'>do</span>
|
220
|
+
<span class='def def kw'>def</span> <span class='controller identifier id'>controller</span>
|
221
|
+
<span class='comment val'>#Object.controller</span>
|
222
|
+
<span class='end end kw'>end</span>
|
223
|
+
<span class='end end kw'>end</span>
|
224
|
+
|
225
|
+
<span class='proxy identifier id'>proxy</span><span class='dot token'>.</span><span class='instance_eval identifier id'>instance_eval</span> <span class='do do kw'>do</span>
|
226
|
+
<span class='comment val'># A hack since this proxy doesn't pick up default_url_options from anywhere</span>
|
227
|
+
<span class='def def kw'>def</span> <span class='url_for identifier id'>url_for</span><span class='lparen token'>(</span><span class='mult op'>*</span><span class='args identifier id'>args</span><span class='rparen token'>)</span>
|
228
|
+
<span class='if if kw'>if</span> <span class='args identifier id'>args</span><span class='dot token'>.</span><span class='last identifier id'>last</span><span class='dot token'>.</span><span class='is_a? fid id'>is_a?</span><span class='lparen token'>(</span><span class='Hash constant id'>Hash</span><span class='rparen token'>)</span> <span class='andop op'>&&</span> <span class='notop op'>!</span><span class='args identifier id'>args</span><span class='dot token'>.</span><span class='last identifier id'>last</span><span class='lbrack token'>[</span><span class='symbol val'>:only_path</span><span class='rbrack token'>]</span>
|
229
|
+
<span class='args identifier id'>args</span> <span class='assign token'>=</span> <span class='args identifier id'>args</span><span class='dot token'>.</span><span class='dup identifier id'>dup</span>
|
230
|
+
<span class='args identifier id'>args</span> <span class='lshft op'><<</span> <span class='args identifier id'>args</span><span class='dot token'>.</span><span class='pop identifier id'>pop</span><span class='dot token'>.</span><span class='merge identifier id'>merge</span><span class='lparen token'>(</span><span class='string val'>'host'</span> <span class='assign token'>=</span><span class='gt op'>></span> <span class='ActionMailer constant id'>ActionMailer</span><span class='colon2 op'>::</span><span class='Base constant id'>Base</span><span class='dot token'>.</span><span class='default_url_options identifier id'>default_url_options</span><span class='lbrack token'>[</span><span class='symbol val'>:host</span><span class='rbrack token'>]</span><span class='rparen token'>)</span>
|
231
|
+
<span class='end end kw'>end</span>
|
232
|
+
<span class='super super kw'>super</span><span class='lparen token'>(</span><span class='mult op'>*</span><span class='args identifier id'>args</span><span class='rparen token'>)</span>
|
233
|
+
<span class='end end kw'>end</span>
|
234
|
+
<span class='end end kw'>end</span>
|
235
|
+
|
236
|
+
<span class='proxy identifier id'>proxy</span>
|
237
|
+
<span class='end end kw'>end</span>
|
238
|
+
<span class='end end kw'>end</span>
|
239
|
+
</pre>
|
240
|
+
</td>
|
241
|
+
</tr>
|
242
|
+
</table>
|
243
|
+
</div>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
</div>
|
248
|
+
|
249
|
+
<div id="footer">
|
250
|
+
Generated on Thu Sep 1 01:13:37 2011 by
|
251
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
252
|
+
0.7.2 (ruby-1.8.7).
|
253
|
+
</div>
|
254
|
+
|
255
|
+
</body>
|
256
|
+
</html>
|