yaks-html 0.8.0.alpha → 0.8.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yaks/format/html.rb +34 -12
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f4a1a3e001c86f0d5f082c13a303e78fdd77d55
|
4
|
+
data.tar.gz: 23735a387547e42f645f550351ea342c61d64157
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eda417afcb0ba6373fd52fb4424496d7b225d9d82513cb4dbd31aa4fc78ff927736e03615ba3fac204866288d7c8da345d8052b937f8fe805b0dc7a843682d94
|
7
|
+
data.tar.gz: fafefd706104b3e43fa28353a2197fe65bcf5db32eb1cdb9ee99dc9098b2f461534d95681a205563b6fd626e704804e9d2ad6a37bdec5d3641d68e3022d6896e
|
data/lib/yaks/format/html.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Yaks
|
4
4
|
class Format
|
5
5
|
class HTML < self
|
6
|
-
include Adamantium
|
6
|
+
include Adamantium, Util
|
7
7
|
|
8
8
|
register :html, :html, 'text/html'
|
9
9
|
|
@@ -85,19 +85,41 @@ module Yaks
|
|
85
85
|
form = form.attr('action', form_control.action) if form_control.action
|
86
86
|
form = form.attr('enctype', form_control.media_type) if form_control.media_type
|
87
87
|
|
88
|
-
rows = form_control.fields.map
|
89
|
-
|
90
|
-
H[:td, H[:label, {for: field.name}, field.label || '']],
|
91
|
-
H[:td, case field.type
|
92
|
-
when /\A(button|checkbox|file|hidden|image|password|radio|reset|submit|text)\z/
|
93
|
-
H[:input, type: field.type, value: field.value, name: field.name]
|
94
|
-
when /textarea/
|
95
|
-
H[:textarea, { name: field.name }, field.value || '']
|
96
|
-
end]
|
97
|
-
]
|
98
|
-
end
|
88
|
+
rows = form_control.fields.map(&method(:render_field))
|
89
|
+
|
99
90
|
form.content(H[:table, form_control.title || '', *rows, H[:tr, H[:td, H[:input, {type: 'submit'}]]]])
|
100
91
|
end
|
92
|
+
|
93
|
+
def render_field(field)
|
94
|
+
return render_fieldset(field) if field.type == :fieldset
|
95
|
+
extra_info = reject_keys(field.to_h_compact, :type, :name, :value, :label, :options)
|
96
|
+
H[:tr,
|
97
|
+
H[:td,
|
98
|
+
H[:label, {for: field.name}, [field.label, field.required ? '*' : ''].join]],
|
99
|
+
H[:td,
|
100
|
+
case field.type
|
101
|
+
when /select/
|
102
|
+
H[:select, reject_keys(field.to_h_compact, :options), render_select_options(field.options)]
|
103
|
+
when /textarea/
|
104
|
+
H[:textarea, reject_keys(field.to_h_compact, :value), field.value || '']
|
105
|
+
when /legend/
|
106
|
+
H[:legend, field.to_h_compact]
|
107
|
+
else
|
108
|
+
H[:input, field.to_h_compact]
|
109
|
+
end],
|
110
|
+
H[:td, extra_info.empty? ? '' : extra_info.inspect]
|
111
|
+
]
|
112
|
+
end
|
113
|
+
|
114
|
+
def render_fieldset(fieldset)
|
115
|
+
H[:fieldset, fieldset.fields.map(&method(:render_field))]
|
116
|
+
end
|
117
|
+
|
118
|
+
def render_select_options(options)
|
119
|
+
options.map do |o|
|
120
|
+
H[:option, reject_keys(o.to_h_compact, :label), o.label]
|
121
|
+
end
|
122
|
+
end
|
101
123
|
end
|
102
124
|
end
|
103
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaks-html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.0.
|
4
|
+
version: 0.8.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Brasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaks
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.0.
|
19
|
+
version: 0.8.0.beta1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.0.
|
26
|
+
version: 0.8.0.beta1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hexp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|