peiji-san 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +25 -5
- data/TODO +0 -1
- data/VERSION.yml +4 -3
- data/{rails/init.rb → init.rb} +0 -0
- data/lib/peiji_san/view_helper.rb +8 -8
- data/lib/peiji_san.rb +28 -32
- data/rdoc/classes/PeijiSan/PaginationMethods.html +344 -0
- data/rdoc/classes/PeijiSan/ViewHelper.html +303 -0
- data/rdoc/classes/PeijiSan.html +306 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/LICENSE.html +129 -0
- data/rdoc/files/README_rdoc.html +157 -0
- data/rdoc/files/lib/peiji_san/view_helper_rb.html +101 -0
- data/rdoc/files/lib/peiji_san_rb.html +133 -0
- data/rdoc/fr_class_index.html +29 -0
- data/rdoc/fr_file_index.html +30 -0
- data/rdoc/fr_method_index.html +39 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/test/peiji_san_test.rb +23 -24
- data/test/test_helper.rb +8 -35
- data/test/view_helper_test.rb +18 -14
- metadata +34 -8
@@ -0,0 +1,303 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: PeijiSan::ViewHelper</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">PeijiSan::ViewHelper</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/peiji_san/view_helper_rb.html">
|
59
|
+
lib/peiji_san/view_helper.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
<div id="description">
|
76
|
+
<p>
|
77
|
+
Optionally defines the <a
|
78
|
+
href="ViewHelper.html#M000004">peiji_san_options</a> method in your helper
|
79
|
+
to override the default options.
|
80
|
+
</p>
|
81
|
+
<p>
|
82
|
+
Include the <a href="ViewHelper.html">PeijiSan::ViewHelper</a> into one of
|
83
|
+
your view helpers to acquire <a href="../PeijiSan.html">PeijiSan</a>
|
84
|
+
superpowers in your view.
|
85
|
+
</p>
|
86
|
+
<p>
|
87
|
+
Example:
|
88
|
+
</p>
|
89
|
+
<pre>
|
90
|
+
class ApplicationHelper
|
91
|
+
include PeijiSan::ViewHelper
|
92
|
+
end
|
93
|
+
|
94
|
+
@collection = Member.active.page(2)
|
95
|
+
|
96
|
+
<% pages_to_link_to(@collection).each do |page %>
|
97
|
+
<%= page.is_a?(String) ? page : link_to_page(page, @collection) %>
|
98
|
+
<% end %>
|
99
|
+
</pre>
|
100
|
+
|
101
|
+
</div>
|
102
|
+
|
103
|
+
|
104
|
+
</div>
|
105
|
+
|
106
|
+
<div id="method-list">
|
107
|
+
<h3 class="section-bar">Methods</h3>
|
108
|
+
|
109
|
+
<div class="name-list">
|
110
|
+
<a href="#M000005">link_to_page</a>
|
111
|
+
<a href="#M000006">pages_to_link_to</a>
|
112
|
+
<a href="#M000004">peiji_san_options</a>
|
113
|
+
</div>
|
114
|
+
</div>
|
115
|
+
|
116
|
+
</div>
|
117
|
+
|
118
|
+
|
119
|
+
<!-- if includes -->
|
120
|
+
|
121
|
+
<div id="section">
|
122
|
+
|
123
|
+
|
124
|
+
<div id="constants-list">
|
125
|
+
<h3 class="section-bar">Constants</h3>
|
126
|
+
|
127
|
+
<div class="name-list">
|
128
|
+
<table summary="Constants">
|
129
|
+
<tr class="top-aligned-row context-row">
|
130
|
+
<td class="context-item-name">DEFAULT_PEIJI_SAN_OPTIONS</td>
|
131
|
+
<td>=</td>
|
132
|
+
<td class="context-item-value">{ # For link_to_page :page_parameter => :page, :anchor => nil, :current_class => :current, # For pages_to_link_to :max_visible => 11, :separator => '…'</td>
|
133
|
+
<td width="3em"> </td>
|
134
|
+
<td class="context-item-desc">
|
135
|
+
The default options for <a href="ViewHelper.html#M000005">link_to_page</a>
|
136
|
+
and <a href="ViewHelper.html#M000006">pages_to_link_to</a>.
|
137
|
+
|
138
|
+
</td>
|
139
|
+
</tr>
|
140
|
+
</table>
|
141
|
+
</div>
|
142
|
+
</div>
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
<!-- if method_list -->
|
150
|
+
<div id="methods">
|
151
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
152
|
+
|
153
|
+
<div id="method-M000005" class="method-detail">
|
154
|
+
<a name="M000005"></a>
|
155
|
+
|
156
|
+
<div class="method-heading">
|
157
|
+
<a href="#M000005" class="method-signature">
|
158
|
+
<span class="method-name">link_to_page</span><span class="method-args">(page, paginated_set, options = {}, html_options = {})</span>
|
159
|
+
</a>
|
160
|
+
</div>
|
161
|
+
|
162
|
+
<div class="method-description">
|
163
|
+
<p>
|
164
|
+
Creates a link using <tt>link_to</tt> for a page in a pagination
|
165
|
+
collection. If the specified page is the current page then its class will
|
166
|
+
be `current’.
|
167
|
+
</p>
|
168
|
+
<p>
|
169
|
+
Options:
|
170
|
+
</p>
|
171
|
+
<pre>
|
172
|
+
[:page_parameter]
|
173
|
+
The name of the GET parameter used to indicate the page to display.
|
174
|
+
Defaults to <tt>:page</tt>.
|
175
|
+
[:current_class]
|
176
|
+
The CSS class name used when a page is the current page in a pagination
|
177
|
+
collection. Defaults to <tt>:current</tt>.
|
178
|
+
</pre>
|
179
|
+
<p><a class="source-toggle" href="#"
|
180
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
181
|
+
<div class="method-source-code" id="M000005-source">
|
182
|
+
<pre>
|
183
|
+
<span class="ruby-comment cmt"># File lib/peiji_san/view_helper.rb, line 49</span>
|
184
|
+
49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">link_to_page</span>(<span class="ruby-identifier">page</span>, <span class="ruby-identifier">paginated_set</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
|
185
|
+
50: <span class="ruby-identifier">page_parameter</span> = <span class="ruby-identifier">peiji_san_option</span>(<span class="ruby-identifier">:page_parameter</span>, <span class="ruby-identifier">options</span>)
|
186
|
+
51: <span class="ruby-identifier">url_options</span> = (<span class="ruby-identifier">page</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">params</span>.<span class="ruby-identifier">except</span>(<span class="ruby-identifier">page_parameter</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">controller</span>.<span class="ruby-identifier">params</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">page_parameter</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">page</span>))
|
187
|
+
52: <span class="ruby-identifier">url_options</span>[<span class="ruby-identifier">:anchor</span>] = <span class="ruby-identifier">peiji_san_option</span>(<span class="ruby-identifier">:anchor</span>, <span class="ruby-identifier">options</span>)
|
188
|
+
53: <span class="ruby-identifier">html_options</span>[<span class="ruby-identifier">:class</span>] = <span class="ruby-identifier">peiji_san_option</span>(<span class="ruby-identifier">:current_class</span>, <span class="ruby-identifier">options</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">paginated_set</span>.<span class="ruby-identifier">current_page?</span>(<span class="ruby-identifier">page</span>)
|
189
|
+
54: <span class="ruby-identifier">link_to</span> <span class="ruby-identifier">page</span>, <span class="ruby-identifier">url_for</span>(<span class="ruby-identifier">url_options</span>), <span class="ruby-identifier">html_options</span>
|
190
|
+
55: <span class="ruby-keyword kw">end</span>
|
191
|
+
</pre>
|
192
|
+
</div>
|
193
|
+
</div>
|
194
|
+
</div>
|
195
|
+
|
196
|
+
<div id="method-M000006" class="method-detail">
|
197
|
+
<a name="M000006"></a>
|
198
|
+
|
199
|
+
<div class="method-heading">
|
200
|
+
<a href="#M000006" class="method-signature">
|
201
|
+
<span class="method-name">pages_to_link_to</span><span class="method-args">(paginated_set, options = {})</span>
|
202
|
+
</a>
|
203
|
+
</div>
|
204
|
+
|
205
|
+
<div class="method-description">
|
206
|
+
<p>
|
207
|
+
Returns an array of pages to link to. This array includes the separator, so
|
208
|
+
make sure to keep this in mind when iterating over the array and creating
|
209
|
+
links.
|
210
|
+
</p>
|
211
|
+
<p>
|
212
|
+
For consistency’s sake, it is adviced to use an odd number for
|
213
|
+
<tt>:max_visible</tt>.
|
214
|
+
</p>
|
215
|
+
<p>
|
216
|
+
Options:
|
217
|
+
</p>
|
218
|
+
<pre>
|
219
|
+
[:max_visible]
|
220
|
+
The maximum amount of elements in the array, this includes the
|
221
|
+
separator(s). Defaults to 11.
|
222
|
+
[:separator]
|
223
|
+
The separator string used to indicate a range between the first or last
|
224
|
+
page and the ones surrounding the current page.
|
225
|
+
</pre>
|
226
|
+
<p>
|
227
|
+
Example:
|
228
|
+
</p>
|
229
|
+
<pre>
|
230
|
+
collection = Model.all.page(40)
|
231
|
+
collection.page_count # => 80
|
232
|
+
|
233
|
+
pages_to_link_to(collection) # => [1, '…', 37, 38, 39, 40, 41, 42, 43, '…', 80]
|
234
|
+
</pre>
|
235
|
+
<p><a class="source-toggle" href="#"
|
236
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
237
|
+
<div class="method-source-code" id="M000006-source">
|
238
|
+
<pre>
|
239
|
+
<span class="ruby-comment cmt"># File lib/peiji_san/view_helper.rb, line 78</span>
|
240
|
+
78: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pages_to_link_to</span>(<span class="ruby-identifier">paginated_set</span>, <span class="ruby-identifier">options</span> = {})
|
241
|
+
79: <span class="ruby-identifier">current</span>, <span class="ruby-identifier">last</span> = <span class="ruby-identifier">paginated_set</span>.<span class="ruby-identifier">current_page</span>, <span class="ruby-identifier">paginated_set</span>.<span class="ruby-identifier">page_count</span>
|
242
|
+
80: <span class="ruby-identifier">max</span> = <span class="ruby-identifier">peiji_san_option</span>(<span class="ruby-identifier">:max_visible</span>, <span class="ruby-identifier">options</span>)
|
243
|
+
81: <span class="ruby-identifier">separator</span> = <span class="ruby-identifier">peiji_san_option</span>(<span class="ruby-identifier">:separator</span>, <span class="ruby-identifier">options</span>)
|
244
|
+
82:
|
245
|
+
83: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">last</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">max</span>
|
246
|
+
84: (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-identifier">last</span>).<span class="ruby-identifier">to_a</span>
|
247
|
+
85: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">current</span> <span class="ruby-operator"><=</span> ((<span class="ruby-identifier">max</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>)
|
248
|
+
86: (<span class="ruby-value">1</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">max</span> <span class="ruby-operator">-</span> <span class="ruby-value">2</span>)).<span class="ruby-identifier">to_a</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">separator</span>, <span class="ruby-identifier">last</span>]
|
249
|
+
87: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">current</span> <span class="ruby-operator">>=</span> (<span class="ruby-identifier">last</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">max</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span>))
|
250
|
+
88: [<span class="ruby-value">1</span>, <span class="ruby-identifier">separator</span>, <span class="ruby-operator">*</span>((<span class="ruby-identifier">last</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">max</span> <span class="ruby-operator">-</span> <span class="ruby-value">3</span>))<span class="ruby-operator">..</span><span class="ruby-identifier">last</span>)]
|
251
|
+
89: <span class="ruby-keyword kw">else</span>
|
252
|
+
90: <span class="ruby-identifier">offset</span> = (<span class="ruby-identifier">max</span> <span class="ruby-operator">-</span> <span class="ruby-value">4</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2</span>
|
253
|
+
91: [<span class="ruby-value">1</span>, <span class="ruby-identifier">separator</span>] <span class="ruby-operator">+</span> ((<span class="ruby-identifier">current</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">offset</span>)<span class="ruby-operator">..</span>(<span class="ruby-identifier">current</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">offset</span>)).<span class="ruby-identifier">to_a</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">separator</span>, <span class="ruby-identifier">last</span>]
|
254
|
+
92: <span class="ruby-keyword kw">end</span>
|
255
|
+
93: <span class="ruby-keyword kw">end</span>
|
256
|
+
</pre>
|
257
|
+
</div>
|
258
|
+
</div>
|
259
|
+
</div>
|
260
|
+
|
261
|
+
<div id="method-M000004" class="method-detail">
|
262
|
+
<a name="M000004"></a>
|
263
|
+
|
264
|
+
<div class="method-heading">
|
265
|
+
<a href="#M000004" class="method-signature">
|
266
|
+
<span class="method-name">peiji_san_options</span><span class="method-args">()</span>
|
267
|
+
</a>
|
268
|
+
</div>
|
269
|
+
|
270
|
+
<div class="method-description">
|
271
|
+
<p>
|
272
|
+
Override this method in your helper to override default values:
|
273
|
+
</p>
|
274
|
+
<pre>
|
275
|
+
def peiji_san_options
|
276
|
+
{ :max_visible => 7 }
|
277
|
+
end
|
278
|
+
</pre>
|
279
|
+
<p><a class="source-toggle" href="#"
|
280
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
281
|
+
<div class="method-source-code" id="M000004-source">
|
282
|
+
<pre>
|
283
|
+
<span class="ruby-comment cmt"># File lib/peiji_san/view_helper.rb, line 36</span>
|
284
|
+
36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">peiji_san_options</span>
|
285
|
+
37: <span class="ruby-keyword kw">end</span>
|
286
|
+
</pre>
|
287
|
+
</div>
|
288
|
+
</div>
|
289
|
+
</div>
|
290
|
+
|
291
|
+
|
292
|
+
</div>
|
293
|
+
|
294
|
+
|
295
|
+
</div>
|
296
|
+
|
297
|
+
|
298
|
+
<div id="validator-badges">
|
299
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
300
|
+
</div>
|
301
|
+
|
302
|
+
</body>
|
303
|
+
</html>
|
@@ -0,0 +1,306 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: PeijiSan</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">PeijiSan</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/peiji_san/view_helper_rb.html">
|
59
|
+
lib/peiji_san/view_helper.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../files/lib/peiji_san_rb.html">
|
63
|
+
lib/peiji_san.rb
|
64
|
+
</a>
|
65
|
+
<br />
|
66
|
+
</td>
|
67
|
+
</tr>
|
68
|
+
|
69
|
+
</table>
|
70
|
+
</div>
|
71
|
+
<!-- banner header -->
|
72
|
+
|
73
|
+
<div id="bodyContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
<div id="contextContent">
|
78
|
+
|
79
|
+
<div id="description">
|
80
|
+
<p>
|
81
|
+
Peiji-San uses named scopes to create a thin pagination layer.
|
82
|
+
</p>
|
83
|
+
<p>
|
84
|
+
Example:
|
85
|
+
</p>
|
86
|
+
<pre>
|
87
|
+
class Member < ActiveRecord::Base
|
88
|
+
extend PeijiSan
|
89
|
+
self.entries_per_page = 32
|
90
|
+
end
|
91
|
+
</pre>
|
92
|
+
<p>
|
93
|
+
Now you can start scoping your queries by `<a
|
94
|
+
href="PeijiSan.html#M000003">page</a>’:
|
95
|
+
</p>
|
96
|
+
<pre>
|
97
|
+
Member.active.page(2)
|
98
|
+
</pre>
|
99
|
+
<p>
|
100
|
+
Which will return 32 records with an offset of 32, as that‘s the
|
101
|
+
second <a href="PeijiSan.html#M000003">page</a>.
|
102
|
+
</p>
|
103
|
+
<p>
|
104
|
+
See <a
|
105
|
+
href="PeijiSan/PaginationMethods.html">PeijiSan::PaginationMethods</a> and
|
106
|
+
<a href="PeijiSan/ViewHelper.html">PeijiSan::ViewHelper</a> for more info.
|
107
|
+
</p>
|
108
|
+
|
109
|
+
</div>
|
110
|
+
|
111
|
+
|
112
|
+
</div>
|
113
|
+
|
114
|
+
<div id="method-list">
|
115
|
+
<h3 class="section-bar">Methods</h3>
|
116
|
+
|
117
|
+
<div class="name-list">
|
118
|
+
<a href="#M000002">entries_per_page</a>
|
119
|
+
<a href="#M000001">entries_per_page=</a>
|
120
|
+
<a href="#M000003">page</a>
|
121
|
+
</div>
|
122
|
+
</div>
|
123
|
+
|
124
|
+
</div>
|
125
|
+
|
126
|
+
|
127
|
+
<!-- if includes -->
|
128
|
+
|
129
|
+
<div id="section">
|
130
|
+
|
131
|
+
<div id="class-list">
|
132
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
133
|
+
|
134
|
+
Module <a href="PeijiSan/PaginationMethods.html" class="link">PeijiSan::PaginationMethods</a><br />
|
135
|
+
Module <a href="PeijiSan/ViewHelper.html" class="link">PeijiSan::ViewHelper</a><br />
|
136
|
+
|
137
|
+
</div>
|
138
|
+
|
139
|
+
<div id="constants-list">
|
140
|
+
<h3 class="section-bar">Constants</h3>
|
141
|
+
|
142
|
+
<div class="name-list">
|
143
|
+
<table summary="Constants">
|
144
|
+
<tr class="top-aligned-row context-row">
|
145
|
+
<td class="context-item-name">ENTRIES_PER_PAGE</td>
|
146
|
+
<td>=</td>
|
147
|
+
<td class="context-item-value">32</td>
|
148
|
+
</tr>
|
149
|
+
</table>
|
150
|
+
</div>
|
151
|
+
</div>
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
<!-- if method_list -->
|
159
|
+
<div id="methods">
|
160
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
161
|
+
|
162
|
+
<div id="method-M000002" class="method-detail">
|
163
|
+
<a name="M000002"></a>
|
164
|
+
|
165
|
+
<div class="method-heading">
|
166
|
+
<a href="#M000002" class="method-signature">
|
167
|
+
<span class="method-name">entries_per_page</span><span class="method-args">()</span>
|
168
|
+
</a>
|
169
|
+
</div>
|
170
|
+
|
171
|
+
<div class="method-description">
|
172
|
+
<p>
|
173
|
+
Returns the number of entries you want per <a
|
174
|
+
href="PeijiSan.html#M000003">page</a>.
|
175
|
+
</p>
|
176
|
+
<pre>
|
177
|
+
class Member < ActiveRecord::Base
|
178
|
+
extend PeijiSan
|
179
|
+
self.entries_per_page = 32
|
180
|
+
end
|
181
|
+
Member.entries_per_page #=> 32
|
182
|
+
</pre>
|
183
|
+
<p><a class="source-toggle" href="#"
|
184
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
185
|
+
<div class="method-source-code" id="M000002-source">
|
186
|
+
<pre>
|
187
|
+
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 85</span>
|
188
|
+
85: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">entries_per_page</span>
|
189
|
+
86: <span class="ruby-ivar">@entries_per_page</span>
|
190
|
+
87: <span class="ruby-keyword kw">end</span>
|
191
|
+
</pre>
|
192
|
+
</div>
|
193
|
+
</div>
|
194
|
+
</div>
|
195
|
+
|
196
|
+
<div id="method-M000001" class="method-detail">
|
197
|
+
<a name="M000001"></a>
|
198
|
+
|
199
|
+
<div class="method-heading">
|
200
|
+
<a href="#M000001" class="method-signature">
|
201
|
+
<span class="method-name">entries_per_page=</span><span class="method-args">(entries)</span>
|
202
|
+
</a>
|
203
|
+
</div>
|
204
|
+
|
205
|
+
<div class="method-description">
|
206
|
+
<p>
|
207
|
+
Sets the number of entries you want per <a
|
208
|
+
href="PeijiSan.html#M000003">page</a>.
|
209
|
+
</p>
|
210
|
+
<pre>
|
211
|
+
class Member < ActiveRecord::Base
|
212
|
+
extend PeijiSan
|
213
|
+
self.entries_per_page = 32
|
214
|
+
end
|
215
|
+
</pre>
|
216
|
+
<p><a class="source-toggle" href="#"
|
217
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
218
|
+
<div class="method-source-code" id="M000001-source">
|
219
|
+
<pre>
|
220
|
+
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 74</span>
|
221
|
+
74: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">entries_per_page=</span>(<span class="ruby-identifier">entries</span>)
|
222
|
+
75: <span class="ruby-ivar">@entries_per_page</span> = <span class="ruby-identifier">entries</span>
|
223
|
+
76: <span class="ruby-keyword kw">end</span>
|
224
|
+
</pre>
|
225
|
+
</div>
|
226
|
+
</div>
|
227
|
+
</div>
|
228
|
+
|
229
|
+
<div id="method-M000003" class="method-detail">
|
230
|
+
<a name="M000003"></a>
|
231
|
+
|
232
|
+
<div class="method-heading">
|
233
|
+
<a href="#M000003" class="method-signature">
|
234
|
+
<span class="method-name">page</span><span class="method-args">(page, entries_per_page=nil)</span>
|
235
|
+
</a>
|
236
|
+
</div>
|
237
|
+
|
238
|
+
<div class="method-description">
|
239
|
+
<p>
|
240
|
+
Set the current scope to a given <a href="PeijiSan.html#M000003">page</a>
|
241
|
+
number.
|
242
|
+
</p>
|
243
|
+
<p>
|
244
|
+
Consider:
|
245
|
+
</p>
|
246
|
+
<pre>
|
247
|
+
class Member < ActiveRecord::Base
|
248
|
+
extend PeijiSan
|
249
|
+
self.entries_per_page = 32
|
250
|
+
end
|
251
|
+
</pre>
|
252
|
+
<p>
|
253
|
+
This adds <tt>{ :limit => 32, :offset => 0 }</tt> to the scope:
|
254
|
+
</p>
|
255
|
+
<pre>
|
256
|
+
Member.page(1)
|
257
|
+
</pre>
|
258
|
+
<p>
|
259
|
+
This adds <tt>{ :limit => 32, :offset => 31 }</tt> to the scope:
|
260
|
+
</p>
|
261
|
+
<pre>
|
262
|
+
Member.page(2)
|
263
|
+
</pre>
|
264
|
+
<p>
|
265
|
+
You can optionally override the <a
|
266
|
+
href="PeijiSan.html#M000002">entries_per_page</a> setting by sepcifying a
|
267
|
+
second argument:
|
268
|
+
</p>
|
269
|
+
<pre>
|
270
|
+
Member.page(2, 5) # Page 2, 5 entries
|
271
|
+
</pre>
|
272
|
+
<p><a class="source-toggle" href="#"
|
273
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
274
|
+
<div class="method-source-code" id="M000003-source">
|
275
|
+
<pre>
|
276
|
+
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 110</span>
|
277
|
+
110: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">page</span>(<span class="ruby-identifier">page</span>, <span class="ruby-identifier">entries_per_page</span>=<span class="ruby-keyword kw">nil</span>)
|
278
|
+
111: <span class="ruby-identifier">page</span> = <span class="ruby-identifier">page</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">? </span><span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">page</span>.<span class="ruby-identifier">to_i</span>
|
279
|
+
112: <span class="ruby-identifier">entries_per_page</span> = <span class="ruby-identifier">entries_per_page</span> <span class="ruby-operator">||</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">entries_per_page</span> <span class="ruby-operator">||</span> <span class="ruby-constant">ENTRIES_PER_PAGE</span>
|
280
|
+
113:
|
281
|
+
114: <span class="ruby-identifier">entries</span> = <span class="ruby-identifier">scoped</span>
|
282
|
+
115: <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">PeijiSan</span><span class="ruby-operator">::</span><span class="ruby-constant">PaginationMethods</span>)
|
283
|
+
116: <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">current_page</span> = <span class="ruby-identifier">page</span>
|
284
|
+
117: <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">entries_per_page</span> = <span class="ruby-identifier">entries_per_page</span>
|
285
|
+
118: <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">scope_without_pagination</span> = <span class="ruby-identifier">scoped</span>
|
286
|
+
119:
|
287
|
+
120: <span class="ruby-identifier">entries</span>.<span class="ruby-identifier">limit</span>(<span class="ruby-identifier">entries_per_page</span>).<span class="ruby-identifier">offset</span>((<span class="ruby-identifier">page</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>) <span class="ruby-operator">*</span> <span class="ruby-identifier">entries_per_page</span>)
|
288
|
+
121: <span class="ruby-keyword kw">end</span>
|
289
|
+
</pre>
|
290
|
+
</div>
|
291
|
+
</div>
|
292
|
+
</div>
|
293
|
+
|
294
|
+
|
295
|
+
</div>
|
296
|
+
|
297
|
+
|
298
|
+
</div>
|
299
|
+
|
300
|
+
|
301
|
+
<div id="validator-badges">
|
302
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
303
|
+
</div>
|
304
|
+
|
305
|
+
</body>
|
306
|
+
</html>
|
data/rdoc/created.rid
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Tue, 05 Apr 2011 13:57:44 +0200
|