dohweb 0.1.8 → 0.1.9
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/lib/doh/web/html_tags.rb +10 -5
- data/test/html_tags.dt.rb +15 -0
- metadata +4 -2
data/lib/doh/web/html_tags.rb
CHANGED
@@ -9,9 +9,13 @@ module HtmlTags
|
|
9
9
|
valstr = options[:value].to_s.strip
|
10
10
|
options[:value] = valstr.to_d.to_dig(num_digits) unless valstr.empty?
|
11
11
|
end
|
12
|
-
|
12
|
+
if options.empty?
|
13
|
+
options_str = ''
|
14
|
+
else
|
15
|
+
options_str = ' ' + options.collect {|key, value| %(#{key}="#{value}") }.join(' ')
|
16
|
+
end
|
13
17
|
open_str = open ? '' : ' /'
|
14
|
-
"<#{tag}
|
18
|
+
"<#{tag}#{options_str}#{open_str}>"
|
15
19
|
end
|
16
20
|
|
17
21
|
def full_tag(tag, body, options = {})
|
@@ -29,13 +33,14 @@ module HtmlTags
|
|
29
33
|
options[:name] = name
|
30
34
|
lines = [start_tag('select', true, options)]
|
31
35
|
items.each do |elem|
|
36
|
+
subopts = {}
|
32
37
|
if elem.is_a?(Array)
|
33
|
-
text
|
38
|
+
text = elem.first
|
39
|
+
subopts[:value] = elem.last
|
34
40
|
else
|
35
41
|
text = value = elem
|
36
42
|
end
|
37
|
-
subopts =
|
38
|
-
subopts[:selected] = 'selected' if value.to_s == selected_value
|
43
|
+
subopts[:selected] = 'selected' if (selected_value.size > 0) && (value.to_s == selected_value)
|
39
44
|
lines.push("#{start_tag(:option, true, subopts)}#{text}</option>")
|
40
45
|
end
|
41
46
|
lines.push('</select>')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'doh/web/html_tags'
|
2
|
+
|
3
|
+
module DohWeb
|
4
|
+
|
5
|
+
class Test_html_tags < DohTest::TestGroup
|
6
|
+
include DohWeb::HtmlTags
|
7
|
+
|
8
|
+
def test_stuff
|
9
|
+
assert_equal(%%<select name="tinker">\n<option>1</option>\n<option>2</option>\n</select>%, select_tag('tinker', [1,2]))
|
10
|
+
assert_equal(%%<select name="tinker">\n<option></option>\n<option>blah</option>\n</select>%, select_tag('tinker', ['','blah']))
|
11
|
+
assert_equal(%%<select name="tinker">\n<option value="">blee</option>\n<option>blah</option>\n</select>%, select_tag('tinker', [['blee',''],'blah']))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dohweb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-01-
|
13
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dohtest
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/doh/web/html_tags.rb
|
42
42
|
- lib/doh/web/util.rb
|
43
43
|
- test/group_params.dt.rb
|
44
|
+
- test/html_tags.dt.rb
|
44
45
|
- test/util.dt.rb
|
45
46
|
- MIT-LICENSE
|
46
47
|
homepage: https://github.com/atpsoft/dohweb
|
@@ -70,5 +71,6 @@ specification_version: 3
|
|
70
71
|
summary: utilities for building web apps
|
71
72
|
test_files:
|
72
73
|
- test/group_params.dt.rb
|
74
|
+
- test/html_tags.dt.rb
|
73
75
|
- test/util.dt.rb
|
74
76
|
has_rdoc:
|