roda-tags 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +24 -0
- data/.github/workflows/ruby.yml +45 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +33 -0
- data/.rubocop_todo.yml +7 -0
- data/CODE_OF_CONDUCT.md +22 -16
- data/Gemfile +86 -0
- data/Guardfile +25 -0
- data/README.md +234 -236
- data/Rakefile +14 -18
- data/lib/core_ext/blank.rb +37 -36
- data/lib/core_ext/hash.rb +39 -16
- data/lib/core_ext/object.rb +2 -2
- data/lib/core_ext/string.rb +290 -116
- data/lib/roda/plugins/tag_helpers.rb +795 -575
- data/lib/roda/plugins/tags.rb +531 -275
- data/lib/roda/tags/version.rb +2 -3
- data/lib/roda/tags.rb +2 -0
- data/roda-tags.gemspec +22 -26
- metadata +44 -141
- data/.travis.yml +0 -4
data/README.md
CHANGED
@@ -1,26 +1,37 @@
|
|
1
|
+
<!-- markdownlint-disable MD013 MD033 -->
|
2
|
+
|
1
3
|
# Roda::Tags
|
2
4
|
|
3
|
-
|
5
|
+
[![Ruby](https://github.com/kematzy/roda-tags/actions/workflows/ruby.yml/badge.svg?branch=master)](https://github.com/kematzy/roda-tags/actions/workflows/ruby.yml) - [![Gem Version](https://badge.fury.io/rb/roda-tags.svg)](https://badge.fury.io/rb/roda-tags) - [![Minitest Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop-minitest)
|
4
6
|
|
5
|
-
|
7
|
+
Coverage: **100%**
|
6
8
|
|
9
|
+
A [Roda](http://roda.jeremyevans.net/) plugin providing easy creation of flexible HTML tags within
|
10
|
+
Roda apps or Roda plugins.
|
11
|
+
|
12
|
+
Extensively tested and with 100% code test coverage.
|
7
13
|
|
8
14
|
## Installation
|
9
15
|
|
10
|
-
|
16
|
+
Add this line to your application's Gemfile:
|
11
17
|
|
12
|
-
```
|
13
|
-
|
18
|
+
```ruby
|
19
|
+
gem 'roda-tags'
|
14
20
|
```
|
15
21
|
|
16
|
-
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
bundle
|
26
|
+
```
|
17
27
|
|
28
|
+
Or install it yourself as:
|
18
29
|
|
19
|
-
```
|
20
|
-
gem
|
30
|
+
```bash
|
31
|
+
gem install roda-tags
|
21
32
|
```
|
22
33
|
|
23
|
-
|
34
|
+
---
|
24
35
|
|
25
36
|
## Getting Started
|
26
37
|
|
@@ -30,12 +41,12 @@ To use Roda::Tags just ensure the gem is included in the Gemfile and then...
|
|
30
41
|
|
31
42
|
```bash
|
32
43
|
class MyApp < Roda
|
33
|
-
|
44
|
+
|
34
45
|
plugin :tags # see Configurations below for options
|
35
46
|
# or
|
36
47
|
plugin :tag_helpers # , options
|
37
|
-
|
38
|
-
# <snip...>
|
48
|
+
|
49
|
+
# <snip...>
|
39
50
|
end
|
40
51
|
```
|
41
52
|
|
@@ -45,47 +56,41 @@ end
|
|
45
56
|
class Roda
|
46
57
|
module RodaPlugins
|
47
58
|
module YourPlugin
|
48
|
-
|
59
|
+
|
49
60
|
def self.load_dependencies(app, opts={})
|
50
61
|
app.plugin :tags, opts
|
51
62
|
# or
|
52
63
|
app.plugin :tag_helpers, opts
|
53
64
|
end
|
54
|
-
|
65
|
+
|
55
66
|
# <snip...>
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
59
70
|
```
|
60
|
-
<br>
|
61
|
-
|
62
|
-
## Usage
|
63
71
|
|
72
|
+
---
|
64
73
|
|
74
|
+
## Usage
|
65
75
|
|
66
|
-
|
76
|
+
TODO: add usage notes here...
|
67
77
|
|
68
78
|
## Key Methods / Functionality
|
69
79
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
Roda::Tags contains two plugins - [`:tags`, `:tag_helpers`] - that can be used independently or together.
|
80
|
+
Roda::Tags contains two plugins - [`:tags`, `:tag_helpers`] - that can be
|
81
|
+
used independently or together.
|
75
82
|
|
76
83
|
**Note!** The `:tags` plugin is loaded by the `:tag_helpers` plugin.
|
77
84
|
|
78
|
-
|
85
|
+
---
|
79
86
|
|
80
87
|
## 1. `:tags` Plugin
|
81
88
|
|
82
|
-
|
83
|
-
|
84
|
-
|
89
|
+
This plugin have one **key public method** - `tag()`, which supports this
|
90
|
+
**dynamic** syntax:
|
85
91
|
|
86
92
|
### -- `tag(*args, &block)`
|
87
93
|
|
88
|
-
|
89
94
|
```ruby
|
90
95
|
tag(name)
|
91
96
|
tag(name, &block)
|
@@ -100,7 +105,6 @@ tag(name, attributes, &block)
|
|
100
105
|
|
101
106
|
This makes the method very flexible as can be seen below.
|
102
107
|
|
103
|
-
|
104
108
|
#### Self closing tags
|
105
109
|
|
106
110
|
```ruby
|
@@ -114,21 +118,20 @@ tag(:hr, class: :divider) #=> <hr class="divider">
|
|
114
118
|
```ruby
|
115
119
|
tag(:div) #=> <div></div>
|
116
120
|
|
117
|
-
tag(:div, 'content')
|
121
|
+
tag(:div, 'content')
|
118
122
|
# <div>
|
119
123
|
# content
|
120
124
|
# </div>
|
121
125
|
|
122
|
-
tag(:div, 'content', id: 'comment')
|
126
|
+
tag(:div, 'content', id: 'comment')
|
123
127
|
# <div id="comment">
|
124
128
|
# content
|
125
129
|
# </div>
|
126
|
-
|
127
130
|
|
128
131
|
# NB! no content
|
129
|
-
tag(:div, id: :comment)
|
132
|
+
tag(:div, id: :comment)
|
130
133
|
#=> <div id="comment"></div>
|
131
|
-
|
134
|
+
|
132
135
|
```
|
133
136
|
|
134
137
|
#### Single line tags
|
@@ -149,7 +152,6 @@ end
|
|
149
152
|
# <p>Hello World</p>
|
150
153
|
# </div>
|
151
154
|
|
152
|
-
|
153
155
|
<% tag(:ul) do %>
|
154
156
|
<li>item 1</li>
|
155
157
|
<%= tag(:li, 'item 2') %>
|
@@ -161,7 +163,6 @@ end
|
|
161
163
|
# <li>item 3</li>
|
162
164
|
# </ul>
|
163
165
|
|
164
|
-
|
165
166
|
# NOTE: ignores tag contents when given a block
|
166
167
|
<% tag(:div, 'ignored tag-content') do %>
|
167
168
|
<%= tag(:label, 'Comments:', for: :comments) %>
|
@@ -175,7 +176,6 @@ end
|
|
175
176
|
# </div>
|
176
177
|
```
|
177
178
|
|
178
|
-
|
179
179
|
#### Boolean attributes
|
180
180
|
|
181
181
|
```ruby
|
@@ -184,63 +184,58 @@ tag(:input, type: :checkbox, checked: true)
|
|
184
184
|
|
185
185
|
tag(:option, 'Roda', value: "1" selected: true)
|
186
186
|
#=> <option selected="selected" value="1">Roda</option>
|
187
|
-
|
187
|
+
|
188
188
|
tag(:option, 'PHP', value: "0" selected: false)
|
189
189
|
#=> <option value="0">PHP</option>
|
190
190
|
```
|
191
191
|
|
192
|
-
|
192
|
+
---
|
193
193
|
|
194
194
|
The plugin also have a few other public helper methods:
|
195
195
|
|
196
|
-
|
197
196
|
### -- `merge_attr_classes(attr, *classes)`
|
198
197
|
|
199
198
|
Updates `attr[:class]` in the hash with the given `classes` and returns `attr`.
|
200
|
-
|
199
|
+
|
201
200
|
```ruby
|
202
201
|
attr = { class: 'alert', id: :idval }
|
203
|
-
|
204
|
-
merge_attr_classes(attr, 'alert-info')
|
202
|
+
|
203
|
+
merge_attr_classes(attr, 'alert-info')
|
205
204
|
#=> { class: 'alert alert-info', id: :idval }
|
206
|
-
|
207
|
-
merge_attr_classes(attr, [:alert, 'alert-info'])
|
205
|
+
|
206
|
+
merge_attr_classes(attr, [:alert, 'alert-info'])
|
208
207
|
#=> { class: 'alert alert-info', id: :idval }
|
209
208
|
```
|
210
|
-
|
211
|
-
<br>
|
212
|
-
|
213
209
|
|
210
|
+
---
|
214
211
|
|
215
212
|
### -- `merge_classes(*classes)`
|
216
|
-
|
213
|
+
|
217
214
|
Returns an alphabetised string from all given class values.
|
218
215
|
|
219
|
-
The method correctly handles a combination of `arrays`, `strings` & `symbols`
|
220
|
-
|
216
|
+
The method correctly handles a combination of `arrays`, `strings` & `symbols`
|
217
|
+
being passed in.
|
218
|
+
|
221
219
|
```ruby
|
222
220
|
attr = { class: 'alert', id: :idval }
|
223
|
-
|
221
|
+
|
224
222
|
merge_classes(attr[:class], ['alert', 'alert-info']) #=> 'alert alert-info'
|
225
|
-
|
223
|
+
|
226
224
|
merge_classes(attr[:class], :text) #=> 'alert text'
|
227
|
-
|
225
|
+
|
228
226
|
merge_classes(attr[:class], [:text, :'alert-info']) #=> 'alert alert-info text'
|
229
227
|
```
|
230
228
|
|
231
|
-
|
232
|
-
|
233
|
-
### Included Helper methods
|
229
|
+
---
|
234
230
|
|
235
|
-
|
231
|
+
### Included Helper methods
|
236
232
|
|
233
|
+
The `:tags` plugin also includes a few useful public helper methods for use
|
234
|
+
within other methods or gems.
|
237
235
|
|
238
236
|
### -- `capture(block='')`
|
239
237
|
|
240
238
|
Captures and returns a captured `ERB` block and restores the buffer afterwards.
|
241
|
-
|
242
|
-
<br>
|
243
|
-
|
244
239
|
|
245
240
|
### -- `capture_html(*args, &block)`
|
246
241
|
|
@@ -253,49 +248,44 @@ def some_method(*args, &block)
|
|
253
248
|
# <snip...>
|
254
249
|
end
|
255
250
|
```
|
256
|
-
|
257
|
-
<br>
|
258
251
|
|
252
|
+
---
|
259
253
|
|
260
254
|
### -- `concat_content(text="")`
|
261
255
|
|
262
256
|
Outputs the given content to the buffer directly.
|
263
|
-
|
257
|
+
|
264
258
|
```ruby
|
265
259
|
concat_content("This will be concatenated to the buffer")
|
266
260
|
```
|
267
|
-
|
268
|
-
<br>
|
269
|
-
|
270
261
|
|
271
|
-
|
262
|
+
---
|
272
263
|
|
273
|
-
|
264
|
+
### -- `block_is_template?(block)`
|
274
265
|
|
275
|
-
|
266
|
+
Returns `true` if the block is from an `ERB` or `HAML` template; `false`
|
267
|
+
otherwise. Used to determine if contents should be returned or concatenated
|
268
|
+
to output.
|
276
269
|
|
277
270
|
---
|
278
271
|
|
279
|
-
<br>
|
280
|
-
|
281
|
-
|
282
272
|
## 2. `:tag_helpers` Plugin
|
283
273
|
|
284
|
-
|
285
|
-
|
286
|
-
#### -- `form_tag(action, attrs={}, &block)`
|
274
|
+
### -- `form_tag(action, attrs={}, &block)`
|
287
275
|
|
288
276
|
Constructs a `<form>` without an object based on options passed.
|
289
277
|
|
290
278
|
```ruby
|
291
|
-
form_tag('/register') do
|
292
|
-
...
|
279
|
+
form_tag('/register') do
|
280
|
+
...
|
293
281
|
end
|
294
282
|
# <form action="/register" id="register-form" method="post">
|
295
283
|
# ...
|
296
284
|
# </form>
|
297
285
|
```
|
298
|
-
|
286
|
+
|
287
|
+
Automatically adds a hidden _faux method_ when `:method` is NOT either `POST`
|
288
|
+
or `GET`.
|
299
289
|
|
300
290
|
```ruby
|
301
291
|
form_tag('/user/1/profile', method: :put, id: 'profile-form')
|
@@ -320,25 +310,23 @@ form_tag('/upload', enctype: 'multipart/form-data')
|
|
320
310
|
# </form>
|
321
311
|
```
|
322
312
|
|
323
|
-
<br>
|
324
313
|
---
|
325
314
|
|
326
|
-
|
327
315
|
### -- `label_tag(field, attrs={}, &block)`
|
328
|
-
|
329
|
-
Constructs a `<label>` tag from the given options.
|
330
316
|
|
317
|
+
Constructs a `<label>` tag from the given options.
|
331
318
|
|
332
|
-
By default appends `':'` to the label name, based upon the plugin config
|
319
|
+
By default appends `':'` to the label name, based upon the plugin config
|
320
|
+
`:tags_label_append` value.
|
333
321
|
|
334
322
|
```ruby
|
335
323
|
label_tag(:name)
|
336
324
|
#=> <label for="name">Name:</label>
|
337
|
-
|
325
|
+
|
338
326
|
label_tag(:name, label: 'Custom label', class: 'sr-only')
|
339
327
|
#=> <label class="sr-only" for="name">Custom label:</label>
|
340
328
|
|
341
|
-
# uses a humanized version of the label name if { label: nil }
|
329
|
+
# uses a humanized version of the label name if { label: nil }
|
342
330
|
label_tag(:name, label: nil)
|
343
331
|
#=> <label for="name">Name:</label>
|
344
332
|
|
@@ -347,8 +335,8 @@ label_tag(:name, label: false)
|
|
347
335
|
#=> <label for="name"></label>
|
348
336
|
```
|
349
337
|
|
350
|
-
By default adds `'<span>*</span>'` to the label name when `{ required: true }`
|
351
|
-
|
338
|
+
By default adds `'<span>*</span>'` to the label name when `{ required: true }`
|
339
|
+
is passed. Based upon the plugin config `:tags_label_required_str` value.
|
352
340
|
|
353
341
|
```ruby
|
354
342
|
label_tag(:name, required: true)
|
@@ -362,19 +350,22 @@ Label tags also supports passing blocks.
|
|
362
350
|
<%= checkbox_tag :remember_me %>
|
363
351
|
<% end %>
|
364
352
|
# <label for="remember_me">Remember Me:
|
365
|
-
# <input
|
353
|
+
# <input
|
354
|
+
# class="checkbox"
|
355
|
+
# id="remember_me"
|
356
|
+
# name="remember_me"
|
357
|
+
# type="checkbox"
|
358
|
+
# value="1"
|
359
|
+
# >
|
366
360
|
# </label>
|
367
361
|
```
|
368
362
|
|
369
|
-
|
370
|
-
<br>
|
371
363
|
---
|
372
364
|
|
373
365
|
### -- `hidden_field_tag(name, attrs={})`
|
374
366
|
|
375
|
-
|
376
|
-
|
377
|
-
|
367
|
+
Constructs a hidden input field from the given options. Only
|
368
|
+
`[:value, :id, :name]` attributes are allowed.
|
378
369
|
|
379
370
|
```ruby
|
380
371
|
hidden_field_tag(:snippet_name)
|
@@ -389,14 +380,14 @@ hidden_field_tag(:snippet_id, id: 'some-id')
|
|
389
380
|
# removing the `:id` attribute completely.
|
390
381
|
hidden_field_tag(:snippet_name, id: false)
|
391
382
|
#=> <input name="snippet_name" type="hidden">
|
392
|
-
```
|
383
|
+
```
|
393
384
|
|
394
|
-
<br>
|
395
385
|
---
|
396
386
|
|
397
|
-
### -- `text_field_tag(name, attrs={})
|
398
|
-
|
399
|
-
|
387
|
+
### -- `text_field_tag(name, attrs={})`
|
388
|
+
|
389
|
+
- _also aliased as_ `textfield_tag()`
|
390
|
+
|
400
391
|
Creates a standard `<input type="text"...>` field from the given options.
|
401
392
|
|
402
393
|
```ruby
|
@@ -434,12 +425,12 @@ text_field_tag(:name, readonly: true)
|
|
434
425
|
#=> <input class="text" id="name" name="name" readonly="readonly" type="text">
|
435
426
|
```
|
436
427
|
|
437
|
-
<br>
|
438
428
|
---
|
439
429
|
|
440
430
|
### -- `password_field_tag(name, attrs={})`
|
441
|
-
|
442
|
-
|
431
|
+
|
432
|
+
- _also aliased as_ `passwordfield_tag()`
|
433
|
+
|
443
434
|
Constructs a `<input type="password"...>` field from the given options.
|
444
435
|
|
445
436
|
```ruby
|
@@ -447,7 +438,12 @@ password_field_tag(:snippet_name)
|
|
447
438
|
#=> <input class="text" id="snippet_name" name="snippet_name" type="password">
|
448
439
|
|
449
440
|
password_field_tag(:snippet_name, value: 'some-value')
|
450
|
-
#=> <input
|
441
|
+
#=> <input
|
442
|
+
# class="text"
|
443
|
+
# id="snippet_name"
|
444
|
+
# name="snippet_name"
|
445
|
+
# type="password"
|
446
|
+
# value="some-value">
|
451
447
|
|
452
448
|
password_field_tag(:snippet_name, id: 'some-id')
|
453
449
|
#=> <input class="text" id="some-id" name="snippet_name" type="password">
|
@@ -465,7 +461,13 @@ password_field_tag(:name, ui_hint: 'a user hint')
|
|
465
461
|
|
466
462
|
# supports `:maxlength` & `:size` attributes
|
467
463
|
password_field_tag(:ip_address, maxlength: 15, size: 20)
|
468
|
-
#=> <input
|
464
|
+
#=> <input
|
465
|
+
# class="text"
|
466
|
+
# id="ip_address"
|
467
|
+
# maxlength="15"
|
468
|
+
# name="ip_address"
|
469
|
+
# size="20"
|
470
|
+
# type="password">
|
469
471
|
|
470
472
|
# `disabled` attribute
|
471
473
|
password_field_tag(:name, disabled: true)
|
@@ -473,16 +475,16 @@ password_field_tag(:name, disabled: :disabled)
|
|
473
475
|
#=> <input class="text" id="name" disabled="disabled" name="name" type="password">
|
474
476
|
```
|
475
477
|
|
476
|
-
<br>
|
477
478
|
---
|
478
479
|
|
479
|
-
|
480
480
|
### -- `file_field_tag(name, attrs={})`
|
481
|
-
- *also aliased as* `filefield_tag()`
|
482
481
|
|
483
|
-
|
482
|
+
- _also aliased as_ `filefield_tag()`
|
484
483
|
|
485
|
-
|
484
|
+
Creates an `<input type="file"...>` field from given options.
|
485
|
+
|
486
|
+
**NOTE!** If you are using file uploads then you will also need to set the
|
487
|
+
multipart option for the form tag, like this:
|
486
488
|
|
487
489
|
```ruby
|
488
490
|
<% form_tag('/upload', multipart: true) do %>
|
@@ -492,8 +494,8 @@ Creates an `<input type="file"...>` field from given options.
|
|
492
494
|
<% end %>
|
493
495
|
```
|
494
496
|
|
495
|
-
The specified URL will then be passed a File object containing the selected file,
|
496
|
-
|
497
|
+
The specified URL will then be passed a File object containing the selected file,
|
498
|
+
or if the field was left blank, a StringIO object.
|
497
499
|
|
498
500
|
```ruby
|
499
501
|
file_field_tag('attachment')
|
@@ -524,22 +526,26 @@ file_field_tag(:photo, disabled: true)
|
|
524
526
|
|
525
527
|
# `:accept` attribute is subject to actual browser support.
|
526
528
|
file_field_tag(:photo, accept: 'image/png,image/jpeg' )
|
527
|
-
#=> <input
|
529
|
+
#=> <input
|
530
|
+
# accept="image/png,image/jpeg"
|
531
|
+
# class="file"
|
532
|
+
# id="photo"
|
533
|
+
# name="photo"
|
534
|
+
# type="file">
|
528
535
|
```
|
529
536
|
|
530
|
-
<br>
|
531
537
|
---
|
532
538
|
|
533
|
-
|
534
539
|
### -- `textarea_tag(name, attrs={})`
|
535
|
-
|
540
|
+
|
541
|
+
- _also aliased as_ `text_area_tag()`
|
536
542
|
|
537
543
|
Constructs a textarea input from the given options.
|
538
544
|
|
539
545
|
**TODO:** enable :escape functionality. How??
|
540
546
|
|
541
|
-
|
542
|
-
|
547
|
+
- `:escape` - By default, the contents of the text input are HTML escaped.
|
548
|
+
If you need unescaped contents, set this to false.
|
543
549
|
|
544
550
|
```ruby
|
545
551
|
textarea_tag('post')
|
@@ -565,25 +571,29 @@ textarea_tag(:body, ui_hint: 'a user hint')
|
|
565
571
|
textarea_tag('body', rows: 10, cols: 25)
|
566
572
|
#=> <textarea cols="25" id="body" name="body" rows="10">...</textarea>
|
567
573
|
|
568
|
-
# alternative `:size` shortcut to set `:rows` & `:cols`
|
574
|
+
# alternative `:size` shortcut to set `:rows` & `:cols`
|
569
575
|
textarea_tag('body', size: "25x10")
|
570
576
|
#=> <textarea cols="25" id="body" name="body" rows="10">...</textarea>
|
571
577
|
|
572
578
|
# `:disabled` attribute
|
573
579
|
textarea_tag(:description, disabled: true)
|
574
|
-
#=> <textarea disabled="disabled" id="description" name="description"
|
575
|
-
|
580
|
+
#=> <textarea disabled="disabled" id="description" name="description">
|
581
|
+
# ...
|
582
|
+
# </textarea>
|
583
|
+
|
576
584
|
# `:readonly` attribute
|
577
585
|
textarea_tag(:description, readonly: true)
|
578
|
-
#=> <textarea id="description" name="description" readonly="readonly"
|
579
|
-
|
586
|
+
#=> <textarea id="description" name="description" readonly="readonly">
|
587
|
+
# ...
|
588
|
+
# </textarea>
|
589
|
+
```
|
580
590
|
|
581
|
-
<br>
|
582
591
|
---
|
583
592
|
|
584
593
|
### -- `field_set_tag(*args, &block)`
|
585
|
-
|
586
|
-
|
594
|
+
|
595
|
+
- _also aliased as_ `fieldset_tag()`
|
596
|
+
|
587
597
|
Creates a `<fieldset..>` tag for grouping HTML form elements.
|
588
598
|
|
589
599
|
```ruby
|
@@ -631,13 +641,11 @@ field_set_tag('Users', id: false)
|
|
631
641
|
# <snip...>
|
632
642
|
```
|
633
643
|
|
634
|
-
<br>
|
635
644
|
---
|
636
645
|
|
637
646
|
### -- `legend_tag(contents, attrs={})`
|
638
|
-
|
639
|
-
Return a legend with _contents_ from the given options.
|
640
647
|
|
648
|
+
Return a legend with _contents_ from the given options.
|
641
649
|
|
642
650
|
```ruby
|
643
651
|
legend_tag('User Details')
|
@@ -652,15 +660,13 @@ legend_tag('User', class: 'some-class')
|
|
652
660
|
#=> <legend class="some-class">User</legend>
|
653
661
|
```
|
654
662
|
|
655
|
-
<br>
|
656
663
|
---
|
657
664
|
|
658
|
-
|
659
665
|
### -- `check_box_tag(name, attrs={})`
|
666
|
+
|
660
667
|
- also aliased as `checkbox_tag()`
|
661
|
-
|
662
|
-
Creates an `<input type="checkbox"...>` tag from the given options.
|
663
668
|
|
669
|
+
Creates an `<input type="checkbox"...>` tag from the given options.
|
664
670
|
|
665
671
|
```ruby
|
666
672
|
check_box_tag(:accept) || checkbox_tag(:accept)
|
@@ -680,27 +686,45 @@ check_box_tag(:rock, class: 'small')
|
|
680
686
|
|
681
687
|
# adds a `:title` attribute when passed `:ui_hint`
|
682
688
|
check_box_tag(:rock, ui_hint: 'a user hint')
|
683
|
-
#=> <input
|
689
|
+
#=> <input
|
690
|
+
# class="checkbox"
|
691
|
+
# id="rock"
|
692
|
+
# name="rock"
|
693
|
+
# title="a user hint"
|
694
|
+
# type="checkbox"
|
695
|
+
# value="1">
|
684
696
|
|
685
697
|
# `checked` attribute
|
686
698
|
check_box_tag(:rock, checked: true)
|
687
|
-
#=> <input
|
699
|
+
#=> <input
|
700
|
+
# checked="checked"
|
701
|
+
# class="checkbox"
|
702
|
+
# id="rock"
|
703
|
+
# name="rock"
|
704
|
+
# type="checkbox"
|
705
|
+
# value="1">
|
688
706
|
|
689
707
|
# `disabled` attribute
|
690
708
|
check_box_tag(:rock, disabled: true)
|
691
|
-
#=> <input
|
709
|
+
#=> <input
|
710
|
+
# class="checkbox"
|
711
|
+
# disabled="disabled"
|
712
|
+
# id="rock"
|
713
|
+
# name="rock"
|
714
|
+
# type="checkbox"
|
715
|
+
# value="1">
|
692
716
|
```
|
693
717
|
|
694
|
-
<br>
|
695
718
|
---
|
696
719
|
|
697
720
|
### -- `radio_button_tag(name, attrs={})`
|
698
|
-
- *also aliased as* `radiobutton_tag()`
|
699
|
-
|
700
|
-
Creates a `<input type="radio"...>` tag from the given options.
|
701
721
|
|
702
|
-
|
722
|
+
- _also aliased as_ `radiobutton_tag()`
|
703
723
|
|
724
|
+
Creates a `<input type="radio"...>` tag from the given options.
|
725
|
+
|
726
|
+
**NOTE!** use groups of radio buttons named the same to allow users to select
|
727
|
+
from a group of options.
|
704
728
|
|
705
729
|
```ruby
|
706
730
|
radio_button_tag(:accept) || radiobutton_tag(:accept)
|
@@ -710,15 +734,15 @@ radio_button_tag(:rock, value:'rock music')
|
|
710
734
|
#=> <input class="radio" id="rock_rock-music" name="rock" type="radio" value="rock music">
|
711
735
|
|
712
736
|
# setting a different :id.
|
713
|
-
radio_button_tag(:rock, id: 'some-id')
|
737
|
+
radio_button_tag(:rock, id: 'some-id')
|
714
738
|
#=> <input class="radio" id="some-id_1" name="rock" type="radio" value="1">
|
715
739
|
|
716
740
|
# append a CSS class. NB! default class: '.radio'
|
717
|
-
radio_button_tag(:rock, class: 'big')
|
741
|
+
radio_button_tag(:rock, class: 'big')
|
718
742
|
#=> <input class="big radio" id="rock_1" name="rock" type="radio" value="1">
|
719
743
|
|
720
744
|
# adds a `:title` attribute when passed `:ui_hint`
|
721
|
-
radio_button_tag(:rock, ui_hint: 'a user hint')
|
745
|
+
radio_button_tag(:rock, ui_hint: 'a user hint')
|
722
746
|
#=> <input class="radio" id="rock_1" value="1" name="rock" title="a user hint" type="radio">
|
723
747
|
|
724
748
|
# `checked` attribute
|
@@ -730,13 +754,12 @@ radio_button_tag(:yes, disabled: true)
|
|
730
754
|
#=> <input disabled="disabled" class="radio" id="yes_1" name="yes" type="radio" value="1">
|
731
755
|
```
|
732
756
|
|
733
|
-
<br>
|
734
757
|
---
|
735
758
|
|
759
|
+
### -- `submit_tag(value="Save Form", attrs={})`
|
760
|
+
|
761
|
+
- _also aliased as_ **`submit_button()`**
|
736
762
|
|
737
|
-
### -- `submit_tag(value="Save Form", attrs={})`
|
738
|
-
- *also aliased as* **`submit_button()`**
|
739
|
-
|
740
763
|
Creates a submit button with the text value as the caption.
|
741
764
|
|
742
765
|
```ruby
|
@@ -745,7 +768,7 @@ submit_tag() || submit_button()
|
|
745
768
|
|
746
769
|
submit_tag(nil)
|
747
770
|
#=> <input name="submit" type="submit" value="">
|
748
|
-
|
771
|
+
|
749
772
|
submit_tag('Custom Value')
|
750
773
|
#=> <input name="submit" type="submit" value="Custom Value">
|
751
774
|
|
@@ -762,13 +785,11 @@ submit_tag(ui_hint: 'a user hint')
|
|
762
785
|
#=> <input name="submit" title="a user hint" type="submit" value="Save Form">
|
763
786
|
```
|
764
787
|
|
765
|
-
<br>
|
766
788
|
---
|
767
789
|
|
768
790
|
### -- `image_submit_tag(src, attrs={})`
|
769
791
|
|
770
792
|
Adds a `<input src=""...>` tag which displays an image.
|
771
|
-
|
772
793
|
|
773
794
|
```ruby
|
774
795
|
@img = '/img/btn.png'
|
@@ -783,11 +804,11 @@ image_submit_tag(@img, class 'search-button')
|
|
783
804
|
#=> <input class="search-button" src="/img/btn.png" type="image">
|
784
805
|
```
|
785
806
|
|
786
|
-
<br>
|
787
807
|
---
|
788
808
|
|
789
809
|
### -- `reset_tag(value='Reset Form', attrs={})`
|
790
|
-
|
810
|
+
|
811
|
+
- _also aliased as_ **`reset_button()`**
|
791
812
|
|
792
813
|
Creates a reset button with the text value as the caption.
|
793
814
|
|
@@ -807,20 +828,18 @@ reset_tag(class: 'some-class')
|
|
807
828
|
|
808
829
|
# supports the `:disabled` attribute
|
809
830
|
reset_tag(disabled: true)
|
810
|
-
#=> <input disabled="disabled" name="reset" type="reset" value="Reset Form">
|
831
|
+
#=> <input disabled="disabled" name="reset" type="reset" value="Reset Form">
|
811
832
|
|
812
833
|
# adds a `:title` attribute when passed `:ui_hint`
|
813
834
|
reset_tag(ui_hint: 'a user hint')
|
814
835
|
#=> <input name="reset" title="a user hint" type="submit" value="Reset Form">
|
815
836
|
```
|
816
837
|
|
817
|
-
<br>
|
818
838
|
---
|
819
839
|
|
820
840
|
### -- `select_tag(name, options, attrs={})`
|
821
|
-
|
822
|
-
Creates a `<select..>` tag (dropdown menu), including the various select options.
|
823
841
|
|
842
|
+
Creates a `<select..>` tag (dropdown menu), including the various select options.
|
824
843
|
|
825
844
|
**Note!** the format for the options values must be `[value, key]`.
|
826
845
|
|
@@ -887,8 +906,9 @@ select_tag(:letters, @letters, selected: :a)
|
|
887
906
|
# <snip...>
|
888
907
|
```
|
889
908
|
|
890
|
-
|
891
|
-
|
909
|
+
When passing multiple items to `:selected` option or setting the
|
910
|
+
`{ multiple: true }` option, the select menu automatically becomes
|
911
|
+
a multiple select box.
|
892
912
|
|
893
913
|
**NOTE!** the `name="letters[]"` attribute.
|
894
914
|
|
@@ -904,10 +924,9 @@ select_tag(:letters, @letters, multiple: true)
|
|
904
924
|
# <snip...>
|
905
925
|
```
|
906
926
|
|
907
|
-
<br>
|
908
927
|
---
|
909
928
|
|
910
|
-
### -- `select_option(value, key, attrs={})`
|
929
|
+
### -- `select_option(value, key, attrs={})`
|
911
930
|
|
912
931
|
Creates an `<option...>` tag for `<select...>` menus.
|
913
932
|
|
@@ -917,7 +936,7 @@ select_option('a', 'Letter A')
|
|
917
936
|
|
918
937
|
select_option('on', '') # , nil)
|
919
938
|
#=> <option value="on">On</option>
|
920
|
-
|
939
|
+
|
921
940
|
# handling selected options
|
922
941
|
select_option('a', 'Letter A', selected: true)
|
923
942
|
#=> <option selected="selected" value="a">Letter A</option>
|
@@ -926,60 +945,59 @@ select_option('a', 'Letter A', selected: false)
|
|
926
945
|
#=> <option value="a">Letter A</option>
|
927
946
|
```
|
928
947
|
|
929
|
-
<br>
|
930
948
|
---
|
931
949
|
|
932
950
|
### -- `faux_method(method='PUT')`
|
933
951
|
|
934
|
-
|
935
952
|
```ruby
|
936
953
|
faux_method() #=> <input name="_method" type="hidden" value="PUT">
|
937
954
|
|
938
955
|
# handling DELETE requests
|
939
956
|
faux_method(:delete) #=> <input name="_method" type="hidden" value="DELETE">
|
940
|
-
|
941
|
-
```
|
942
957
|
|
943
|
-
|
958
|
+
```
|
959
|
+
|
944
960
|
---
|
945
961
|
|
946
962
|
## Plugin Configurations
|
947
963
|
|
948
|
-
The default settings should help you get moving quickly, and are fairly common
|
964
|
+
The default settings should help you get moving quickly, and are fairly common
|
965
|
+
sense based.
|
949
966
|
|
950
967
|
However the `:tags` plugin supports these config options:
|
951
968
|
|
952
|
-
|
953
|
-
|
954
|
-
Sets the HTML output format, toggling between `HTML 5` (`false`) and `XHTML` (`true`). Default is: `false`.
|
969
|
+
### `:tag_output_format_is_xhtml`
|
955
970
|
|
956
|
-
|
971
|
+
Sets the HTML output format, toggling between `HTML 5` (`false`) and `XHTML`
|
972
|
+
(`true`). Default is: `false`.
|
957
973
|
|
958
|
-
|
974
|
+
This option is retained for legacy support and in memory of the
|
975
|
+
_"good old days"_ ;-).
|
959
976
|
|
960
|
-
|
977
|
+
### `:tag_add_newlines_after_tags`
|
961
978
|
|
979
|
+
Sets the formatting of the HTML output, whether it should be more compact in
|
980
|
+
nature or slightly better formatted. Default is: `true`.
|
962
981
|
|
963
982
|
The `:tag_helpers` plugin supports these config options:
|
964
983
|
|
965
|
-
|
966
984
|
#### `:tags_label_required_str`
|
967
985
|
|
968
|
-
Sets the formatting of the string appended to required `<label...>` tags.
|
986
|
+
Sets the formatting of the string appended to required `<label...>` tags.
|
987
|
+
Default is: `'<span>*</span>'`.
|
969
988
|
|
970
989
|
#### `:tags_label_append_str`
|
971
990
|
|
972
991
|
Sets the formatting of the string appended to `<label...>` tags. Default is: `':'`.
|
973
992
|
|
974
|
-
|
975
993
|
#### `:tags_forms_default_class`
|
976
994
|
|
977
995
|
Sets the default class value for form tags. Default is: `''` (empty).
|
978
996
|
|
979
|
-
This is a shortcut to automatically add something like
|
980
|
-
|
997
|
+
This is a shortcut to automatically add something like
|
998
|
+
[Bootstrap](https://getbootstrap.com/) support with `'form-control'`
|
981
999
|
|
982
|
-
**NOTE!**
|
1000
|
+
**NOTE!**
|
983
1001
|
|
984
1002
|
Config options set in `:tag_helpers` are passed on to the `:tags` plugin.
|
985
1003
|
|
@@ -990,94 +1008,74 @@ plugin :tag_helpers, { tag_output_format_is_xhtml: true, ... }
|
|
990
1008
|
# <snip...>
|
991
1009
|
```
|
992
1010
|
|
993
|
-
|
994
|
-
|
995
1011
|
## RTFM
|
996
1012
|
|
997
|
-
If the above is not clear enough, please check the specs for a better
|
998
|
-
|
999
|
-
<br>
|
1013
|
+
If the above is not clear enough, please check the specs for a better
|
1014
|
+
understanding.
|
1000
1015
|
|
1001
1016
|
## Errors / Bugs
|
1002
1017
|
|
1003
1018
|
If something is not behaving intuitively, it is a bug, and should be reported.
|
1004
|
-
Report
|
1019
|
+
Report [Issues here](http://github.com/kematzy/roda-tags/issues)
|
1005
1020
|
|
1006
|
-
|
1021
|
+
---
|
1007
1022
|
|
1008
1023
|
## TODOs
|
1009
1024
|
|
1010
|
-
|
1011
|
-
|
1012
|
-
* Decide on if it's worth it to do validity checks on all attributes passed to tags
|
1013
|
-
ie: reject attributes based upon what is allowed for the tag.
|
1014
|
-
|
1015
|
-
```ruby
|
1016
|
-
tag(:base, href: 'url', target: '_self', id: 'is-ignored')
|
1017
|
-
#=> <base href="url", target="_self">
|
1018
|
-
```
|
1025
|
+
- Keep it up to date with any changes in `Roda` or `HTML`.
|
1019
1026
|
|
1020
|
-
|
1021
|
-
|
1022
|
-
- ```meta(name, contents)```
|
1023
|
-
|
1024
|
-
- ```img(src, attrs={})```
|
1025
|
-
|
1027
|
+
- Decide on if it's worth it to do validity checks on all attributes passed to tags
|
1028
|
+
ie: reject attributes based upon what is allowed for the tag.
|
1026
1029
|
|
1027
|
-
|
1030
|
+
```ruby
|
1031
|
+
tag(:base, href: 'url', target: '_self', id: 'is-ignored')
|
1032
|
+
#=> <base href="url", target="_self">
|
1033
|
+
```
|
1028
1034
|
|
1035
|
+
- Decide on whether to add a number of convenience tags (methods), such as:
|
1029
1036
|
|
1030
|
-
|
1037
|
+
- `meta(name, contents)`
|
1038
|
+
- `img(src, attrs={})`
|
1031
1039
|
|
1032
|
-
|
1040
|
+
- Any other improvements we may think of.
|
1033
1041
|
|
1034
|
-
|
1042
|
+
---
|
1035
1043
|
|
1036
|
-
|
1044
|
+
## Acknowledgements
|
1037
1045
|
|
1038
|
-
|
1039
|
-
|
1040
|
-
* erubis
|
1046
|
+
Inspiration for this gem was taken from the ActiveSupport gem by DHH & Rails Core Team released
|
1047
|
+
under the MIT license.
|
1041
1048
|
|
1049
|
+
---
|
1042
1050
|
|
1043
|
-
|
1051
|
+
## Development
|
1044
1052
|
|
1045
|
-
|
1046
|
-
|
1047
|
-
* minitest
|
1048
|
-
* minitest-hooks
|
1049
|
-
* minitest-rg
|
1050
|
-
* rack-test
|
1051
|
-
* nokogiri => for the `assert_have_tag()` tests
|
1053
|
+
After checking out the repo, run `bundle install` to install dependencies.
|
1054
|
+
Then, run `bundle exec rake spec` to run the tests.
|
1052
1055
|
|
1053
|
-
|
1056
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
1054
1057
|
|
1058
|
+
To release a new version:
|
1055
1059
|
|
1056
|
-
|
1060
|
+
1. update the version number in `version.rb`
|
1061
|
+
2. run `bundle exec rake release`, which will create a git tag for the version
|
1062
|
+
3. push git commits and tags
|
1063
|
+
4. push the `.gem` file to [rubygems.org](https://rubygems.org).
|
1057
1064
|
|
1058
|
-
##
|
1059
|
-
|
1060
|
-
* Fork the project.
|
1061
|
-
* Make your feature addition or bug fix.
|
1062
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
1063
|
-
* Commit, do not mess with Rakefile, version, or history.
|
1064
|
-
* (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
1065
|
-
* Send me a pull request. Bonus points for topic branches.
|
1065
|
+
## Contributing
|
1066
1066
|
|
1067
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/kematzy/roda-tags).
|
1067
1068
|
|
1068
|
-
|
1069
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are
|
1070
|
+
expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
1069
1071
|
|
1070
1072
|
## Copyright
|
1071
1073
|
|
1072
|
-
Copyright (c) 2010-
|
1074
|
+
Copyright (c) 2010 - 2024 Kematzy
|
1073
1075
|
|
1074
1076
|
Released under the MIT License. See LICENSE for further details.
|
1075
1077
|
|
1076
|
-
|
1077
|
-
|
1078
|
-
## Code Inspirations:
|
1079
|
-
|
1080
|
-
* The ActiveSupport gem by DHH & Rails Core Team
|
1081
|
-
|
1082
|
-
|
1078
|
+
## License
|
1083
1079
|
|
1080
|
+
The gem is available as open source under the terms of the
|
1081
|
+
[MIT License](http://opensource.org/licenses/MIT).
|