peiji-san 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -0
- data/Rakefile +7 -21
- data/init.rb +2 -1
- data/lib/peiji_san.rb +2 -1
- data/lib/peiji_san/view_helper.rb +36 -4
- data/test/peiji_san_test.rb +35 -34
- data/test/sinatra_test.rb +43 -0
- data/test/test_helper.rb +13 -9
- data/test/view_helper_test.rb +26 -25
- metadata +159 -34
- data/TODO +0 -1
- data/VERSION.yml +0 -5
- data/peiji-san.gemspec +0 -30
- data/rdoc/classes/PeijiSan.html +0 -306
- data/rdoc/classes/PeijiSan/PaginationMethods.html +0 -344
- data/rdoc/classes/PeijiSan/ViewHelper.html +0 -303
- data/rdoc/created.rid +0 -1
- data/rdoc/files/LICENSE.html +0 -129
- data/rdoc/files/README_rdoc.html +0 -157
- data/rdoc/files/lib/peiji_san/view_helper_rb.html +0 -101
- data/rdoc/files/lib/peiji_san_rb.html +0 -133
- data/rdoc/fr_class_index.html +0 -29
- data/rdoc/fr_file_index.html +0 -30
- data/rdoc/fr_method_index.html +0 -39
- data/rdoc/index.html +0 -24
- data/rdoc/rdoc-style.css +0 -208
@@ -1,344 +0,0 @@
|
|
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::PaginationMethods</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::PaginationMethods</td>
|
54
|
-
</tr>
|
55
|
-
<tr class="top-aligned-row">
|
56
|
-
<td><strong>In:</strong></td>
|
57
|
-
<td>
|
58
|
-
<a href="../../files/lib/peiji_san_rb.html">
|
59
|
-
lib/peiji_san.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
|
-
The page scope is extended with the <a
|
78
|
-
href="PaginationMethods.html">PaginationMethods</a>. This means that all
|
79
|
-
methods defined on this module will be available on the resulting
|
80
|
-
collection.
|
81
|
-
</p>
|
82
|
-
<pre>
|
83
|
-
collection = Member.active.page(1)
|
84
|
-
collection.has_next_page?
|
85
|
-
</pre>
|
86
|
-
|
87
|
-
</div>
|
88
|
-
|
89
|
-
|
90
|
-
</div>
|
91
|
-
|
92
|
-
<div id="method-list">
|
93
|
-
<h3 class="section-bar">Methods</h3>
|
94
|
-
|
95
|
-
<div class="name-list">
|
96
|
-
<a href="#M000007">current_page?</a>
|
97
|
-
<a href="#M000008">has_next_page?</a>
|
98
|
-
<a href="#M000009">has_previous_page?</a>
|
99
|
-
<a href="#M000010">next_page</a>
|
100
|
-
<a href="#M000013">page_count</a>
|
101
|
-
<a href="#M000011">previous_page</a>
|
102
|
-
<a href="#M000012">unpaged_count</a>
|
103
|
-
</div>
|
104
|
-
</div>
|
105
|
-
|
106
|
-
</div>
|
107
|
-
|
108
|
-
|
109
|
-
<!-- if includes -->
|
110
|
-
|
111
|
-
<div id="section">
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
<div id="attribute-list">
|
118
|
-
<h3 class="section-bar">Attributes</h3>
|
119
|
-
|
120
|
-
<div class="name-list">
|
121
|
-
<table>
|
122
|
-
<tr class="top-aligned-row context-row">
|
123
|
-
<td class="context-item-name">current_page</td>
|
124
|
-
<td class="context-item-value"> [RW] </td>
|
125
|
-
<td class="context-item-desc"></td>
|
126
|
-
</tr>
|
127
|
-
<tr class="top-aligned-row context-row">
|
128
|
-
<td class="context-item-name">entries_per_page</td>
|
129
|
-
<td class="context-item-value"> [RW] </td>
|
130
|
-
<td class="context-item-desc"></td>
|
131
|
-
</tr>
|
132
|
-
<tr class="top-aligned-row context-row">
|
133
|
-
<td class="context-item-name">scope_without_pagination</td>
|
134
|
-
<td class="context-item-value"> [RW] </td>
|
135
|
-
<td class="context-item-desc"></td>
|
136
|
-
</tr>
|
137
|
-
</table>
|
138
|
-
</div>
|
139
|
-
</div>
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
<!-- if method_list -->
|
144
|
-
<div id="methods">
|
145
|
-
<h3 class="section-bar">Public Instance methods</h3>
|
146
|
-
|
147
|
-
<div id="method-M000007" class="method-detail">
|
148
|
-
<a name="M000007"></a>
|
149
|
-
|
150
|
-
<div class="method-heading">
|
151
|
-
<a href="#M000007" class="method-signature">
|
152
|
-
<span class="method-name">current_page?</span><span class="method-args">(page)</span>
|
153
|
-
</a>
|
154
|
-
</div>
|
155
|
-
|
156
|
-
<div class="method-description">
|
157
|
-
<p>
|
158
|
-
Returns whether or not the given page is the current page.
|
159
|
-
</p>
|
160
|
-
<p><a class="source-toggle" href="#"
|
161
|
-
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
162
|
-
<div class="method-source-code" id="M000007-source">
|
163
|
-
<pre>
|
164
|
-
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 30</span>
|
165
|
-
30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_page?</span>(<span class="ruby-identifier">page</span>)
|
166
|
-
31: <span class="ruby-ivar">@current_page</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">page</span>
|
167
|
-
32: <span class="ruby-keyword kw">end</span>
|
168
|
-
</pre>
|
169
|
-
</div>
|
170
|
-
</div>
|
171
|
-
</div>
|
172
|
-
|
173
|
-
<div id="method-M000008" class="method-detail">
|
174
|
-
<a name="M000008"></a>
|
175
|
-
|
176
|
-
<div class="method-heading">
|
177
|
-
<a href="#M000008" class="method-signature">
|
178
|
-
<span class="method-name">has_next_page?</span><span class="method-args">()</span>
|
179
|
-
</a>
|
180
|
-
</div>
|
181
|
-
|
182
|
-
<div class="method-description">
|
183
|
-
<p>
|
184
|
-
Returns whether or not there is a next page for the current scope.
|
185
|
-
</p>
|
186
|
-
<p><a class="source-toggle" href="#"
|
187
|
-
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
188
|
-
<div class="method-source-code" id="M000008-source">
|
189
|
-
<pre>
|
190
|
-
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 35</span>
|
191
|
-
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_next_page?</span>
|
192
|
-
36: <span class="ruby-ivar">@current_page</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">page_count</span>
|
193
|
-
37: <span class="ruby-keyword kw">end</span>
|
194
|
-
</pre>
|
195
|
-
</div>
|
196
|
-
</div>
|
197
|
-
</div>
|
198
|
-
|
199
|
-
<div id="method-M000009" class="method-detail">
|
200
|
-
<a name="M000009"></a>
|
201
|
-
|
202
|
-
<div class="method-heading">
|
203
|
-
<a href="#M000009" class="method-signature">
|
204
|
-
<span class="method-name">has_previous_page?</span><span class="method-args">()</span>
|
205
|
-
</a>
|
206
|
-
</div>
|
207
|
-
|
208
|
-
<div class="method-description">
|
209
|
-
<p>
|
210
|
-
Returns whether or not there is a previous page for the current scope.
|
211
|
-
</p>
|
212
|
-
<p><a class="source-toggle" href="#"
|
213
|
-
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
214
|
-
<div class="method-source-code" id="M000009-source">
|
215
|
-
<pre>
|
216
|
-
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 40</span>
|
217
|
-
40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_previous_page?</span>
|
218
|
-
41: <span class="ruby-ivar">@current_page</span> <span class="ruby-operator">!=</span> <span class="ruby-value">1</span>
|
219
|
-
42: <span class="ruby-keyword kw">end</span>
|
220
|
-
</pre>
|
221
|
-
</div>
|
222
|
-
</div>
|
223
|
-
</div>
|
224
|
-
|
225
|
-
<div id="method-M000010" class="method-detail">
|
226
|
-
<a name="M000010"></a>
|
227
|
-
|
228
|
-
<div class="method-heading">
|
229
|
-
<a href="#M000010" class="method-signature">
|
230
|
-
<span class="method-name">next_page</span><span class="method-args">()</span>
|
231
|
-
</a>
|
232
|
-
</div>
|
233
|
-
|
234
|
-
<div class="method-description">
|
235
|
-
<p>
|
236
|
-
Returns the next page number if there is a next page, returns <tt>nil</tt>
|
237
|
-
otherwise.
|
238
|
-
</p>
|
239
|
-
<p><a class="source-toggle" href="#"
|
240
|
-
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
241
|
-
<div class="method-source-code" id="M000010-source">
|
242
|
-
<pre>
|
243
|
-
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 46</span>
|
244
|
-
46: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">next_page</span>
|
245
|
-
47: <span class="ruby-ivar">@current_page</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">has_next_page?</span>
|
246
|
-
48: <span class="ruby-keyword kw">end</span>
|
247
|
-
</pre>
|
248
|
-
</div>
|
249
|
-
</div>
|
250
|
-
</div>
|
251
|
-
|
252
|
-
<div id="method-M000013" class="method-detail">
|
253
|
-
<a name="M000013"></a>
|
254
|
-
|
255
|
-
<div class="method-heading">
|
256
|
-
<a href="#M000013" class="method-signature">
|
257
|
-
<span class="method-name">page_count</span><span class="method-args">()</span>
|
258
|
-
</a>
|
259
|
-
</div>
|
260
|
-
|
261
|
-
<div class="method-description">
|
262
|
-
<p>
|
263
|
-
Returns the number of pages for the current scope.
|
264
|
-
</p>
|
265
|
-
<p><a class="source-toggle" href="#"
|
266
|
-
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
267
|
-
<div class="method-source-code" id="M000013-source">
|
268
|
-
<pre>
|
269
|
-
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 63</span>
|
270
|
-
63: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">page_count</span>
|
271
|
-
64: (<span class="ruby-identifier">unpaged_count</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-ivar">@entries_per_page</span>).<span class="ruby-identifier">ceil</span>
|
272
|
-
65: <span class="ruby-keyword kw">end</span>
|
273
|
-
</pre>
|
274
|
-
</div>
|
275
|
-
</div>
|
276
|
-
</div>
|
277
|
-
|
278
|
-
<div id="method-M000011" class="method-detail">
|
279
|
-
<a name="M000011"></a>
|
280
|
-
|
281
|
-
<div class="method-heading">
|
282
|
-
<a href="#M000011" class="method-signature">
|
283
|
-
<span class="method-name">previous_page</span><span class="method-args">()</span>
|
284
|
-
</a>
|
285
|
-
</div>
|
286
|
-
|
287
|
-
<div class="method-description">
|
288
|
-
<p>
|
289
|
-
Returns the previous page number if there is a previous page, returns
|
290
|
-
<tt>nil</tt> otherwise.
|
291
|
-
</p>
|
292
|
-
<p><a class="source-toggle" href="#"
|
293
|
-
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
294
|
-
<div class="method-source-code" id="M000011-source">
|
295
|
-
<pre>
|
296
|
-
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 52</span>
|
297
|
-
52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">previous_page</span>
|
298
|
-
53: <span class="ruby-ivar">@current_page</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">has_previous_page?</span>
|
299
|
-
54: <span class="ruby-keyword kw">end</span>
|
300
|
-
</pre>
|
301
|
-
</div>
|
302
|
-
</div>
|
303
|
-
</div>
|
304
|
-
|
305
|
-
<div id="method-M000012" class="method-detail">
|
306
|
-
<a name="M000012"></a>
|
307
|
-
|
308
|
-
<div class="method-heading">
|
309
|
-
<a href="#M000012" class="method-signature">
|
310
|
-
<span class="method-name">unpaged_count</span><span class="method-args">()</span>
|
311
|
-
</a>
|
312
|
-
</div>
|
313
|
-
|
314
|
-
<div class="method-description">
|
315
|
-
<p>
|
316
|
-
Returns the row count for all the rows that would match the current scope,
|
317
|
-
so not only on the current page.
|
318
|
-
</p>
|
319
|
-
<p><a class="source-toggle" href="#"
|
320
|
-
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
321
|
-
<div class="method-source-code" id="M000012-source">
|
322
|
-
<pre>
|
323
|
-
<span class="ruby-comment cmt"># File lib/peiji_san.rb, line 58</span>
|
324
|
-
58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unpaged_count</span>
|
325
|
-
59: <span class="ruby-identifier">scope_without_pagination</span>.<span class="ruby-identifier">count</span>
|
326
|
-
60: <span class="ruby-keyword kw">end</span>
|
327
|
-
</pre>
|
328
|
-
</div>
|
329
|
-
</div>
|
330
|
-
</div>
|
331
|
-
|
332
|
-
|
333
|
-
</div>
|
334
|
-
|
335
|
-
|
336
|
-
</div>
|
337
|
-
|
338
|
-
|
339
|
-
<div id="validator-badges">
|
340
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
341
|
-
</div>
|
342
|
-
|
343
|
-
</body>
|
344
|
-
</html>
|
@@ -1,303 +0,0 @@
|
|
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>
|