dm-is-select 0.0.9 → 1.2.0
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 +36 -12
- data/Gemfile +23 -0
- data/Guardfile +13 -0
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.rdoc +32 -7
- data/Rakefile +33 -69
- data/VERSION +1 -1
- data/dm-is-select.gemspec +94 -44
- data/docs/apple-touch-icon.png +0 -0
- data/docs/classes/DataMapper.html +81 -0
- data/docs/classes/DataMapper/Is.html +81 -0
- data/docs/classes/DataMapper/Is/Select.html +205 -0
- data/docs/classes/DataMapper/Is/Select/ClassMethods.html +258 -0
- data/docs/created.rid +4 -0
- data/docs/css/github.css +129 -0
- data/docs/css/main.css +333 -0
- data/docs/css/panel.css +384 -0
- data/docs/css/reset.css +48 -0
- data/docs/favicon.ico +0 -0
- data/docs/files/README_rdoc.html +272 -0
- data/docs/files/lib/dm-is-select_rb.html +88 -0
- data/docs/files/lib/is/select_rb.html +94 -0
- data/docs/i/arrows.png +0 -0
- data/docs/i/results_bg.png +0 -0
- data/docs/i/tree_bg.png +0 -0
- data/docs/index.html +13 -0
- data/docs/js/highlight.pack.js +1 -0
- data/docs/js/jquery-1.3.2.min.js +19 -0
- data/docs/js/jquery-effect.js +593 -0
- data/docs/js/main.js +24 -0
- data/docs/js/navigation.js +142 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/searchdoc.js +449 -0
- data/docs/js/searcher.js +228 -0
- data/docs/panel/index.html +73 -0
- data/docs/panel/links.html +12 -0
- data/docs/panel/tree.js +1 -0
- data/lib/dm-is-select.rb +5 -11
- data/lib/{dm-is-select/is → is}/select.rb +12 -10
- data/spec/{integration/select_spec.rb → dm-is-select_spec.rb} +25 -13
- data/spec/spec_helper.rb +10 -8
- metadata +278 -94
- data/History.rdoc +0 -24
- data/TODO +0 -0
- data/lib/dm-is-select/is/version.rb +0 -7
data/docs/css/panel.css
ADDED
@@ -0,0 +1,384 @@
|
|
1
|
+
/* Panel (begin) */
|
2
|
+
.panel
|
3
|
+
{
|
4
|
+
position: absolute;
|
5
|
+
width: 100%;
|
6
|
+
height: 100%;
|
7
|
+
top: 0;
|
8
|
+
left: 0;
|
9
|
+
background: #FFF;
|
10
|
+
z-index: 2;
|
11
|
+
font-family: "Helvetica Neue", "Arial", sans-serif;
|
12
|
+
//zoom: 1;
|
13
|
+
}
|
14
|
+
|
15
|
+
.panel_tree .results,
|
16
|
+
.panel_results .tree
|
17
|
+
{
|
18
|
+
display: none;
|
19
|
+
}
|
20
|
+
|
21
|
+
/* Header with search box (begin) */
|
22
|
+
.panel .header
|
23
|
+
{
|
24
|
+
width: 100%;
|
25
|
+
height: 29px;
|
26
|
+
border-bottom: 1px solid #666;
|
27
|
+
position: relative;
|
28
|
+
left: 0; top: 0;
|
29
|
+
background: #e8e8e8;
|
30
|
+
}
|
31
|
+
|
32
|
+
.panel .header div
|
33
|
+
{
|
34
|
+
margin: 0 7px;
|
35
|
+
}
|
36
|
+
.panel .header table
|
37
|
+
{
|
38
|
+
height: 29px;
|
39
|
+
width: 100%;
|
40
|
+
}
|
41
|
+
|
42
|
+
.panel .header table td
|
43
|
+
{
|
44
|
+
vertical-align: middle;
|
45
|
+
text-align: middle;
|
46
|
+
}
|
47
|
+
|
48
|
+
.panel .header label
|
49
|
+
{
|
50
|
+
position: absolute;
|
51
|
+
font-size: 12px;
|
52
|
+
line-height: 29px;
|
53
|
+
margin-left: 3px;
|
54
|
+
color: #999;
|
55
|
+
cursor: text;
|
56
|
+
}
|
57
|
+
|
58
|
+
.panel .header table input
|
59
|
+
{
|
60
|
+
width: 100%;
|
61
|
+
box-sizing: border-box;
|
62
|
+
-moz-box-sizing: border-box;
|
63
|
+
-webkit-box-sizing: border-box;
|
64
|
+
display: inline-block;
|
65
|
+
-webkit-appearance: searchfield;
|
66
|
+
height: 22px;
|
67
|
+
//height: auto;
|
68
|
+
}
|
69
|
+
|
70
|
+
/* Header with search box (end) */
|
71
|
+
|
72
|
+
|
73
|
+
/* Results (begin) */
|
74
|
+
.panel .result
|
75
|
+
{
|
76
|
+
position: absolute;
|
77
|
+
top: 30px;
|
78
|
+
bottom: 0;
|
79
|
+
left: 0;
|
80
|
+
width: 100%;
|
81
|
+
//height: expression((this.parentNode.offsetHeight - 31));
|
82
|
+
overflow-y: scroll;
|
83
|
+
overflow-x: hidden;
|
84
|
+
-overflow-y: hidden;
|
85
|
+
background: #EDF3FE url(../i/results_bg.png);
|
86
|
+
z-index: 2;
|
87
|
+
//zoom:1;
|
88
|
+
}
|
89
|
+
|
90
|
+
.panel .result ul
|
91
|
+
{
|
92
|
+
font-size: 0.8em;
|
93
|
+
width: 100%;
|
94
|
+
background: #EDF3FE url(../i/results_bg.png);
|
95
|
+
//zoom:1;
|
96
|
+
}
|
97
|
+
|
98
|
+
.panel .result ul li
|
99
|
+
{
|
100
|
+
height: 46px;
|
101
|
+
-height: 50px;
|
102
|
+
//display: inline;
|
103
|
+
//width: 100%;
|
104
|
+
//zoom: 1;
|
105
|
+
overflow: hidden;
|
106
|
+
padding: 4px 10px 0 10px;
|
107
|
+
cursor: pointer;
|
108
|
+
}
|
109
|
+
|
110
|
+
.panel .result ul li h1
|
111
|
+
{
|
112
|
+
font-size: 13px;
|
113
|
+
font-weight: normal;
|
114
|
+
color: #333;
|
115
|
+
margin-bottom: 2px;
|
116
|
+
white-space: nowrap;
|
117
|
+
}
|
118
|
+
|
119
|
+
.panel .result ul li p
|
120
|
+
{
|
121
|
+
font-size: 11px;
|
122
|
+
color: #333;
|
123
|
+
margin-bottom: 2px;
|
124
|
+
white-space: nowrap;
|
125
|
+
}
|
126
|
+
|
127
|
+
.panel .result ul li h1 i,
|
128
|
+
.panel .result ul li p.snippet
|
129
|
+
{
|
130
|
+
color: #999;
|
131
|
+
}
|
132
|
+
|
133
|
+
.panel .result ul li b
|
134
|
+
{
|
135
|
+
color: #000;
|
136
|
+
}
|
137
|
+
|
138
|
+
.panel .result ul li.current
|
139
|
+
{
|
140
|
+
background: #3875D7;
|
141
|
+
}
|
142
|
+
|
143
|
+
.panel .result ul li.current h1,
|
144
|
+
.panel .result ul li.current p
|
145
|
+
{
|
146
|
+
color: #DDD;
|
147
|
+
}
|
148
|
+
|
149
|
+
.panel .result ul li.current h1 i,
|
150
|
+
.panel .result ul li.current p.snippet
|
151
|
+
{
|
152
|
+
color: #AAA;
|
153
|
+
}
|
154
|
+
|
155
|
+
.panel .result ul li.current b
|
156
|
+
{
|
157
|
+
color: #FFF;
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
.panel .result ul li:hover,
|
162
|
+
.panel .result ul li.selected
|
163
|
+
{
|
164
|
+
background: #d0d0d0;
|
165
|
+
}
|
166
|
+
|
167
|
+
.panel .result ul li.current:hover
|
168
|
+
{
|
169
|
+
background: #2965C0;
|
170
|
+
}
|
171
|
+
|
172
|
+
.panel .result ul li .badge
|
173
|
+
{
|
174
|
+
margin-right: 0.4em;
|
175
|
+
margin-left: -0.2em;
|
176
|
+
padding: 0 0.2em;
|
177
|
+
color: #000;
|
178
|
+
border-radius: 3px;
|
179
|
+
}
|
180
|
+
|
181
|
+
.panel .result ul li .badge_1
|
182
|
+
{
|
183
|
+
background: #ACDBF4;
|
184
|
+
}
|
185
|
+
|
186
|
+
.panel .result ul li.current .badge_1
|
187
|
+
{
|
188
|
+
background: #97BFD7;
|
189
|
+
}
|
190
|
+
|
191
|
+
.panel .result ul li .badge_2
|
192
|
+
{
|
193
|
+
background: #ACF3C3;
|
194
|
+
}
|
195
|
+
|
196
|
+
.panel .result ul li.current .badge_2
|
197
|
+
{
|
198
|
+
background: #98D7AC;
|
199
|
+
}
|
200
|
+
|
201
|
+
.panel .result ul li .badge_3
|
202
|
+
{
|
203
|
+
background: #E0F3AC;
|
204
|
+
}
|
205
|
+
|
206
|
+
.panel .result ul li.current .badge_3
|
207
|
+
{
|
208
|
+
background: #C4D798;
|
209
|
+
}
|
210
|
+
|
211
|
+
.panel .result ul li .badge_4
|
212
|
+
{
|
213
|
+
background: #D7CA98;
|
214
|
+
}
|
215
|
+
|
216
|
+
.panel .result ul li.current .badge_4
|
217
|
+
{
|
218
|
+
background: #A6B0AC;
|
219
|
+
}
|
220
|
+
|
221
|
+
.panel .result ul li .badge_5
|
222
|
+
{
|
223
|
+
background: #F3C8AC;
|
224
|
+
}
|
225
|
+
|
226
|
+
.panel .result ul li.current .badge_5
|
227
|
+
{
|
228
|
+
background: #D7B198;
|
229
|
+
}
|
230
|
+
|
231
|
+
.panel .result ul li .badge_6
|
232
|
+
{
|
233
|
+
background: #F3ACC3;
|
234
|
+
}
|
235
|
+
|
236
|
+
.panel .result ul li.current .badge_6
|
237
|
+
{
|
238
|
+
background: #D798AB;
|
239
|
+
}
|
240
|
+
|
241
|
+
/* Results (end) */
|
242
|
+
|
243
|
+
/* Tree (begin) */ /**/
|
244
|
+
.panel .tree
|
245
|
+
{
|
246
|
+
position: absolute;
|
247
|
+
top: 30px;
|
248
|
+
bottom: 0;
|
249
|
+
left: 0;
|
250
|
+
width: 100%;
|
251
|
+
//zoom: 1;
|
252
|
+
//height: expression((this.parentNode.offsetHeight - 31));
|
253
|
+
overflow-y: scroll;
|
254
|
+
overflow-x: hidden;
|
255
|
+
-overflow-y: hidden;
|
256
|
+
background: #EDF3FE url(../i/tree_bg.png);
|
257
|
+
z-index: 30;
|
258
|
+
}
|
259
|
+
|
260
|
+
.panel .tree ul
|
261
|
+
{
|
262
|
+
background: #EDF3FE url(../i/tree_bg.png);
|
263
|
+
}
|
264
|
+
|
265
|
+
.panel .tree li
|
266
|
+
{
|
267
|
+
cursor: pointer;
|
268
|
+
overflow: hidden;
|
269
|
+
//height: 23px;
|
270
|
+
//display: inline;
|
271
|
+
//zoom: 1;
|
272
|
+
//width: 100%;
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
.panel .tree li .content
|
277
|
+
{
|
278
|
+
padding-left: 18px;
|
279
|
+
padding-top: 5px;
|
280
|
+
height: 18px;
|
281
|
+
overflow: hidden;
|
282
|
+
position: relative;
|
283
|
+
}
|
284
|
+
|
285
|
+
.panel .tree li .icon
|
286
|
+
{
|
287
|
+
width: 10px;
|
288
|
+
height: 9px;
|
289
|
+
background: url(../i/arrows.png);
|
290
|
+
background-position: 0 -9px;
|
291
|
+
position: absolute;
|
292
|
+
left: 1px;
|
293
|
+
top: 8px;
|
294
|
+
cursor: default;
|
295
|
+
}
|
296
|
+
|
297
|
+
.panel .tree li.closed .icon
|
298
|
+
{
|
299
|
+
background-position: 0 0;
|
300
|
+
}
|
301
|
+
|
302
|
+
.panel .tree ul li h1
|
303
|
+
{
|
304
|
+
font-size: 13px;
|
305
|
+
font-weight: normal;
|
306
|
+
color: #000;
|
307
|
+
margin-bottom: 2px;
|
308
|
+
white-space: nowrap;
|
309
|
+
}
|
310
|
+
|
311
|
+
.panel .tree ul li p
|
312
|
+
{
|
313
|
+
font-size: 11px;
|
314
|
+
color: #666;
|
315
|
+
margin-bottom: 2px;
|
316
|
+
white-space: nowrap;
|
317
|
+
}
|
318
|
+
|
319
|
+
.panel .tree ul li h1 i
|
320
|
+
{
|
321
|
+
color: #999;
|
322
|
+
font-style: normal;
|
323
|
+
}
|
324
|
+
|
325
|
+
.panel .tree ul li.empty
|
326
|
+
{
|
327
|
+
cursor: text;
|
328
|
+
}
|
329
|
+
|
330
|
+
.panel .tree ul li.empty h1,
|
331
|
+
.panel .tree ul li.empty p
|
332
|
+
{
|
333
|
+
color: #666;
|
334
|
+
font-style: italic;
|
335
|
+
}
|
336
|
+
|
337
|
+
.panel .tree ul li.current
|
338
|
+
{
|
339
|
+
background: #3875D7;
|
340
|
+
}
|
341
|
+
|
342
|
+
.panel .tree ul li.current .icon
|
343
|
+
{
|
344
|
+
background-position: -10px -9px;
|
345
|
+
}
|
346
|
+
|
347
|
+
.panel .tree ul li.current.closed .icon
|
348
|
+
{
|
349
|
+
background-position: -10px 0;
|
350
|
+
}
|
351
|
+
|
352
|
+
.panel .tree ul li.current h1
|
353
|
+
{
|
354
|
+
color: #FFF;
|
355
|
+
}
|
356
|
+
|
357
|
+
.panel .tree ul li.current p
|
358
|
+
{
|
359
|
+
color: #CCC;
|
360
|
+
}
|
361
|
+
|
362
|
+
.panel .tree ul li.current.empty h1,
|
363
|
+
.panel .tree ul li.current.empty p
|
364
|
+
{
|
365
|
+
color: #999;
|
366
|
+
}
|
367
|
+
|
368
|
+
.panel .tree ul li:hover
|
369
|
+
{
|
370
|
+
background: #d0d0d0;
|
371
|
+
}
|
372
|
+
|
373
|
+
.panel .tree ul li.current:hover
|
374
|
+
{
|
375
|
+
background: #2965C0;
|
376
|
+
}
|
377
|
+
|
378
|
+
.panel .tree .stopper
|
379
|
+
{
|
380
|
+
display: none;
|
381
|
+
}
|
382
|
+
/* Tree (end) */ /**/
|
383
|
+
|
384
|
+
/* Panel (end) */
|
data/docs/css/reset.css
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
/* http://meyerweb.com/eric/tools/css/reset/ */
|
2
|
+
/* v1.0 | 20080212 */
|
3
|
+
|
4
|
+
html, body, div, span, applet, object, iframe,
|
5
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
6
|
+
a, abbr, acronym, address, big, cite, code,
|
7
|
+
del, dfn, em, font, img, ins, kbd, q, s, samp,
|
8
|
+
small, strike, strong, sub, sup, tt, var,
|
9
|
+
b, u, i, center,
|
10
|
+
dl, dt, dd, ol, ul, li,
|
11
|
+
fieldset, form, label, legend,
|
12
|
+
table, caption, tbody, tfoot, thead, tr, th, td {
|
13
|
+
margin: 0;
|
14
|
+
padding: 0;
|
15
|
+
border: 0;
|
16
|
+
outline: 0;
|
17
|
+
font-size: 100%;
|
18
|
+
vertical-align: baseline;
|
19
|
+
background: transparent;
|
20
|
+
}
|
21
|
+
body {
|
22
|
+
line-height: 1;
|
23
|
+
}
|
24
|
+
ol, ul {
|
25
|
+
list-style: none;
|
26
|
+
}
|
27
|
+
blockquote, q {
|
28
|
+
quotes: none;
|
29
|
+
}
|
30
|
+
blockquote:before, blockquote:after,
|
31
|
+
q:before, q:after {
|
32
|
+
content: '';
|
33
|
+
content: none;
|
34
|
+
}
|
35
|
+
|
36
|
+
/* remember to highlight inserts somehow! */
|
37
|
+
ins {
|
38
|
+
text-decoration: none;
|
39
|
+
}
|
40
|
+
del {
|
41
|
+
text-decoration: line-through;
|
42
|
+
}
|
43
|
+
|
44
|
+
/* tables still need 'cellspacing="0"' in the markup */
|
45
|
+
table {
|
46
|
+
border-collapse: collapse;
|
47
|
+
border-spacing: 0;
|
48
|
+
}
|
data/docs/favicon.ico
ADDED
Binary file
|
@@ -0,0 +1,272 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>README.rdoc</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
|
9
|
+
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
|
10
|
+
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
|
11
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<div class="banner">
|
20
|
+
|
21
|
+
<h1>
|
22
|
+
README.rdoc
|
23
|
+
</h1>
|
24
|
+
<ul class="files">
|
25
|
+
<li>README.rdoc</li>
|
26
|
+
<li>Last modified: 2013-03-11 01:48:40 +0800</li>
|
27
|
+
</ul>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div id="bodyContent">
|
31
|
+
<div id="content">
|
32
|
+
|
33
|
+
<div class="description">
|
34
|
+
|
35
|
+
<h1 id="label-dm-is-select">dm-is-select</h1>
|
36
|
+
|
37
|
+
<p>A <a href="../classes/DataMapper.html">DataMapper</a> plugin that makes
|
38
|
+
getting the <code><select></code> options from a Model easier.</p>
|
39
|
+
|
40
|
+
<h2 id="label-Installation">Installation</h2>
|
41
|
+
|
42
|
+
<pre>$ gem install dm-is-select</pre>
|
43
|
+
|
44
|
+
<p>Or add the gem to your Gemfile, and then run <code>bundle install</code>.</p>
|
45
|
+
|
46
|
+
<pre>gem 'dm-is-select', 'CURRENT_VERSION_NUMBER'</pre>
|
47
|
+
|
48
|
+
<h3 id="label-Dependencies">Dependencies</h3>
|
49
|
+
|
50
|
+
<p>The plugin depends upon the following:</p>
|
51
|
+
<ul><li>
|
52
|
+
<p>dm-mysql-adapter OR dm-sqlite3-adapter ( >= 1.2.0)</p>
|
53
|
+
</li><li>
|
54
|
+
<p>data_mapper ( >= 1.2.0)</p>
|
55
|
+
</li><li>
|
56
|
+
<p>dm-is-tree ( >= 1.2.0)</p>
|
57
|
+
</li><li>
|
58
|
+
<p>activesupport (>= 3.2.7) - methods => Hash#except and Hash#slice</p>
|
59
|
+
</li></ul>
|
60
|
+
|
61
|
+
<h2 id="label-Getting+Started">Getting Started</h2>
|
62
|
+
|
63
|
+
<p>Let’s say you got a basic Category Model.</p>
|
64
|
+
|
65
|
+
<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Category</span>
|
66
|
+
<span class="ruby-identifier">include</span> <span class="ruby-constant">DataMapper</span><span class="ruby-operator">::</span><span class="ruby-constant">Resource</span>
|
67
|
+
<span class="ruby-identifier">property</span> :<span class="ruby-identifier">id</span>, <span class="ruby-constant">Serial</span>
|
68
|
+
<span class="ruby-identifier">property</span> :<span class="ruby-identifier">name</span>, <span class="ruby-constant">String</span>
|
69
|
+
|
70
|
+
<span class="ruby-identifier">is</span> :<span class="ruby-identifier">select</span>, :<span class="ruby-identifier">name</span>
|
71
|
+
|
72
|
+
<span class="ruby-keyword">end</span>
|
73
|
+
</pre>
|
74
|
+
|
75
|
+
<p>Through that simple declaration you get the following class method ..</p>
|
76
|
+
|
77
|
+
<pre>Category.items_for_select_menu</pre>
|
78
|
+
|
79
|
+
<p>…which returns an Array with the Model items in a structured way, ready for
|
80
|
+
use.</p>
|
81
|
+
|
82
|
+
<pre>[
|
83
|
+
[nil, "Select Category"],
|
84
|
+
["nil", " ------ "],
|
85
|
+
[1, "Category 1"],
|
86
|
+
[2, "Category 2"],
|
87
|
+
[3, "Category 3"],
|
88
|
+
[4, "Category 4"],
|
89
|
+
[5, "Category 5"]
|
90
|
+
]</pre>
|
91
|
+
|
92
|
+
<p>Great, but you don’t want the prompt to say “Select Category”, but</p>
|
93
|
+
|
94
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>( :<span class="ruby-identifier">prompt</span> =<span class="ruby-operator">></span> <span class="ruby-string">"Choose Whatever"</span> )
|
95
|
+
</pre>
|
96
|
+
|
97
|
+
<p>…which returns the Array with the prompt changed</p>
|
98
|
+
|
99
|
+
<pre>[
|
100
|
+
[nil, "Choose Whatever"],
|
101
|
+
["nil", " ------ "],
|
102
|
+
[1, "Category 1"],
|
103
|
+
...<snip>...
|
104
|
+
]</pre>
|
105
|
+
|
106
|
+
<p>OK, but you don’t like the divider node (2nd in output above). That’s fine,
|
107
|
+
you remove it like this:</p>
|
108
|
+
|
109
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>( :<span class="ruby-identifier">divider</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span> )
|
110
|
+
</pre>
|
111
|
+
|
112
|
+
<p>…which returns the Array with the divider removed</p>
|
113
|
+
|
114
|
+
<pre>[
|
115
|
+
[nil, "Select Category"],
|
116
|
+
[1, "Category 1"],
|
117
|
+
...<snip>...
|
118
|
+
]</pre>
|
119
|
+
|
120
|
+
<p>Hmm, fine, but I don’t want either a prompt or a divider, you say. That’s
|
121
|
+
fine too.</p>
|
122
|
+
|
123
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>( :<span class="ruby-identifier">prompt</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span> )
|
124
|
+
</pre>
|
125
|
+
|
126
|
+
<p>…which returns the Array with the prompt and divider removed</p>
|
127
|
+
|
128
|
+
<pre>[
|
129
|
+
[1, "Category 1"],
|
130
|
+
[1, "Category 2"],
|
131
|
+
...<snip>...
|
132
|
+
]</pre>
|
133
|
+
|
134
|
+
<p>OK, that’s smooth, but my Category model is a tree with parents, children
|
135
|
+
and so on. This won’t work with that.</p>
|
136
|
+
|
137
|
+
<p>Sure, no problem, just do this when you declare the Model:</p>
|
138
|
+
|
139
|
+
<pre class="ruby"><span class="ruby-identifier">is</span> :<span class="ruby-identifier">select</span>, :<span class="ruby-identifier">name</span>, :<span class="ruby-identifier">is_tree</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>
|
140
|
+
</pre>
|
141
|
+
|
142
|
+
<p>Then you can just use this</p>
|
143
|
+
|
144
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>( :<span class="ruby-identifier">prompt</span> =<span class="ruby-operator">></span> <span class="ruby-string">"Choose Parent"</span> )
|
145
|
+
</pre>
|
146
|
+
|
147
|
+
<p>…and you get this nicely formatted <code><select></code> options
|
148
|
+
array</p>
|
149
|
+
|
150
|
+
<pre>[
|
151
|
+
[nil, "Choose Parent"],
|
152
|
+
["nil", " ------ "],
|
153
|
+
[0, "Top Level Category"],
|
154
|
+
["nil", " ------ "],
|
155
|
+
[1, "Parent-1"],
|
156
|
+
[2, "-- Parent-1-Child"],
|
157
|
+
[3, "-- -- Parent-1-Child-GrandChild"],
|
158
|
+
[4, "Parent-2"],
|
159
|
+
[5, "-- Parent-2-Child"],
|
160
|
+
[6, "-- -- Parent-2-Child-GrandChild"]
|
161
|
+
]</pre>
|
162
|
+
|
163
|
+
<p><strong>NB!</strong> It only supports 3 levels at this point in time, as I
|
164
|
+
think that's enough in most use cases, but IF not, fix the code and let me
|
165
|
+
know and I'll add it.</p>
|
166
|
+
|
167
|
+
<p>Cool, but that “Top Level Category” node is a bit ugly, but easily fixed.</p>
|
168
|
+
|
169
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>( :<span class="ruby-identifier">root_text</span> =<span class="ruby-operator">></span> <span class="ruby-string">"1st Parent (root)"</span> )
|
170
|
+
</pre>
|
171
|
+
|
172
|
+
<p>…gives you:</p>
|
173
|
+
|
174
|
+
<pre>[
|
175
|
+
...<snip>...
|
176
|
+
["nil", " ------ "],
|
177
|
+
[0, "1st Parent (root)"],
|
178
|
+
["nil", " ------ "],
|
179
|
+
...<snip>...
|
180
|
+
]</pre>
|
181
|
+
|
182
|
+
<p>You can even remove it all together by doing this:</p>
|
183
|
+
|
184
|
+
<pre class="ruby"><span class="ruby-constant">Category</span>.<span class="ruby-identifier">items_for_select_menu</span>( :<span class="ruby-identifier">show_root</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span> )
|
185
|
+
</pre>
|
186
|
+
|
187
|
+
<p>Obviously all the config options from above works with Tree models as well.</p>
|
188
|
+
|
189
|
+
<h2 id="label-Last+Few+Words">Last Few Words</h2>
|
190
|
+
|
191
|
+
<p>OK, I admit it, not the most impressive DM plugin there is, but hey, it
|
192
|
+
sure helps keeping your model/views cleaner.</p>
|
193
|
+
|
194
|
+
<h2 id="label-RTFM+">RTFM </h2>
|
195
|
+
|
196
|
+
<p>For a better understanding of this gem/plugin, make sure you study the
|
197
|
+
‘<code>dm-is-select/spec/dm-is-select_spec.rb</code>’ file.</p>
|
198
|
+
|
199
|
+
<h2 id="label-Errors+%2F+Bugs">Errors / Bugs</h2>
|
200
|
+
|
201
|
+
<p>If something is not behaving intuitively, it is a bug, and should be
|
202
|
+
reported. Report it here: <a
|
203
|
+
href="http://github.com/kematzy/dm-is-select/issues">github.com/kematzy/dm-is-select/issues</a></p>
|
204
|
+
|
205
|
+
<h2 id="label-Contributing+to+dm-is-select">Contributing to dm-is-select</h2>
|
206
|
+
<ul><li>
|
207
|
+
<p>Check out the latest master to make sure the feature hasn’t been
|
208
|
+
implemented or the bug hasn’t been fixed yet.</p>
|
209
|
+
</li><li>
|
210
|
+
<p>Check out the issue tracker to make sure someone already hasn’t requested
|
211
|
+
it and/or contributed it.</p>
|
212
|
+
</li><li>
|
213
|
+
<p>Fork the project.</p>
|
214
|
+
</li><li>
|
215
|
+
<p>Start a feature/bugfix branch.</p>
|
216
|
+
</li><li>
|
217
|
+
<p>Commit and push until you are happy with your contribution.</p>
|
218
|
+
</li><li>
|
219
|
+
<p>Make sure to add tests for it. This is important so I don’t break it in a
|
220
|
+
future version unintentionally.</p>
|
221
|
+
</li><li>
|
222
|
+
<p>Please try not to mess with the Rakefile, version, or history. If you want
|
223
|
+
to have your own version, or is otherwise necessary, that is fine, but
|
224
|
+
please isolate to its own commit so I can cherry-pick around it.</p>
|
225
|
+
</li></ul>
|
226
|
+
|
227
|
+
<h2 id="label-Copyright">Copyright</h2>
|
228
|
+
|
229
|
+
<p>Copyright © 2009 - 2013 Kematzy.</p>
|
230
|
+
|
231
|
+
<h2 id="label-Licence">Licence</h2>
|
232
|
+
|
233
|
+
<p>Released under the MIT license.</p>
|
234
|
+
|
235
|
+
</div>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
<!-- Methods -->
|
268
|
+
</div>
|
269
|
+
|
270
|
+
</div>
|
271
|
+
</body>
|
272
|
+
</html>
|