lib/iord/output_helper.rb in iord-1.1.0 vs lib/iord/output_helper.rb in iord-1.1.1

- old
+ new

@@ -5,46 +5,48 @@ def initialize(view_context) @v = view_context end def display(object, attrs) - html = "<dl>" - attrs.each do |attr| - html += "<dt>#{v.field_name(object, attr).to_s.humanize}</dt>" - html += "<dd>#{v.field_value(object, attr)}</dd>" + v.content_tag(:dl, nil, nil, false) do + attrs.collect do |attr| + v.content_tag(:dt, v.field_name(object, attr).to_s.humanize) + + v.content_tag(:dd, v.field_value(object, attr)) + end.join.html_safe end - html += "</dl>" - html.html_safe end def display_array(array, attrs) - html = "<ul>" - array.each do |element| - html += "<li>#{display(element, attrs)}</li>" + v.content_tag(:ul, nil, nil, false) do + array.collect do |el| + v.content_tag(:li, display(el, attrs)) + end.join.html_safe end - html += "</ul>" - html.html_safe end def fieldset(title, attrs, form, predicate = nil) - html = %Q[<fieldset><legend>#{title}</legend>\n] - attrs.each do |attr| - if predicate.nil? or predicate.call(form, attr) - html += v.field_form(form, attr) - end + v.content_tag(:fieldset, nil, nil, false) do + c = v.content_tag(:legend, title) + c += attrs.collect do |attr| + if predicate.nil? or predicate.call(form, attr) + v.field_form(form, attr) + end + end.compact.join.html_safe + c += yield.to_s.html_safe if block_given? end - html += yield.to_s if block_given? - html += "\n</fieldset>\n" - html.html_safe end def input(label, input, errors) - %Q[<div class="input">#{label}#{input}<div class="error">#{errors.join('<br />')}</div></div>\n].html_safe + v.content_tag(:div, {'class' => :input}, nil, false) do + c = label.html_safe + c += input.html_safe + c += v.content_tag(:div, errors.join('<br />').html_safe, {'class' => :error}, false) + end end def submit(form) - %Q[<div class="actions">#{form.button nil, class: 'btn btn-default'}</div>] + v.content_tag(:div, form.button(nil, class: 'btn btn-default'), {'class' => :actions}) end def link_to_remove(form, attr_name) form.link_to_remove(v.t('iord.buttons.remove', model: attr_name), class: 'btn btn-default') end @@ -83,16 +85,16 @@ v.link_to(v.t('iord.buttons.destroy'), v.resource_url(object), data: {method: 'delete', confirm: v.t('iord.alert.destroy')}, class: 'btn btn-default') end - def link_to(label, url, hash) - v.link_to(label, url, hash) + def link_to(label, url, hsh) + v.link_to(label, url, hsh) end - def image(url, hash) - hash ||= {} - v.image_tag(url, hash) + def image(url, hsh) + hsh ||= {} + v.image_tag(url, hsh) end end end