lib/yaks/format/html.rb in yaks-html-0.7.6 vs lib/yaks/format/html.rb in yaks-html-0.7.7
- old
+ new
@@ -25,11 +25,11 @@
def render_resource(resource, templ = section('resource'))
templ
.replace('.type') { |header| header.content(resource.type.to_s + (resource.collection? ? ' collection' : '')) }
.replace('.attribute', &render_attributes(resource.attributes))
.replace('.links') {|links| resource.links.empty? ? [] : links.replace('.link', &render_links(resource.links)) }
- .replace('.controls') {|div| render_controls(resource.controls).call(div) }
+ .replace('.forms') {|div| render_forms(resource.forms).call(div) }
.replace('.subresource') {|sub_templ| render_subresources(resource, templ, sub_templ) }
end
def render_attributes(attributes)
->(templ) do
@@ -68,36 +68,36 @@
end
end
end
- def render_controls(controls)
+ def render_forms(forms)
->(div) do
div.content(
- controls.map(&method(:render_control))
+ forms.map(&method(:render_form))
)
end
end
- def render_control(control)
+ def render_form(form_control)
form = H[:form]
- form = form.attr('name', control.name) if control.name
- form = form.attr('method', control.method) if control.method
- form = form.attr('action', control.action) if control.action
- form = form.attr('enctype', control.media_type) if control.media_type
+ form = form.attr('name', form_control.name) if form_control.name
+ form = form.attr('method', form_control.method) if form_control.method
+ form = form.attr('action', form_control.action) if form_control.action
+ form = form.attr('enctype', form_control.media_type) if form_control.media_type
- rows = control.fields.map do |field|
+ rows = form_control.fields.map do |field|
H[:tr,
H[:td, H[:label, {for: field.name}, field.label || '']],
H[:td, case field.type
when /\A(button|checkbox|file|hidden|image|password|radio|reset|submit|text)\z/
H[:input, type: field.type, value: field.value, name: field.name]
when /textarea/
H[:textarea, { name: field.name }, field.value || '']
end]
]
end
- form.content(H[:table, control.title || '', *rows, H[:tr, H[:td, H[:input, {type: 'submit'}]]]])
+ form.content(H[:table, form_control.title || '', *rows, H[:tr, H[:td, H[:input, {type: 'submit'}]]]])
end
end
end
end