Module: Admin::ShowViewHelper
- Defined in:
- app/helpers/admin/show_view_helper.rb
Instance Method Summary collapse
- #build_action_buttons ⇒ Object
- #build_fields_for(decorator, fields) ⇒ Object
- #build_view_for(attribute_name) ⇒ Object
- #field_wrapper(method, options = {}, &block) ⇒ Object
- #render_view(method, options = {}) ⇒ Object
Instance Method Details
#build_action_buttons ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/helpers/admin/show_view_helper.rb', line 24 def edit_btn = Array(decorate.class.permitted_instance_methods_for(action_name)).collect { |action| render_to_string("actions/#{action}", locals: {record: decorate.object}, layout: false) }.join("\n").html_safe # edit_btn = link_to t('actions.edit'), [scope, record, action: 'edit'], class: 'btn btn-primary' content_tag(:div, edit_btn, class: 'pull-right') end |
#build_fields_for(decorator, fields) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/admin/show_view_helper.rb', line 33 def build_fields_for(decorator, fields) content_tag(:div, class: 'row detail-info clearfix') do content_tag(:ul, class: 'col-sm-12 col-md-12 list-unstyled') do fields.each do |field_name| = decorator.try(:attribute_type_for, field_name, true) || {} concat(render_view(field_name, )) end end end end |
#build_view_for(attribute_name) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/admin/show_view_helper.rb', line 5 def build_view_for(attribute_name) fields_hash = decorator.try(attribute_name) || {} profiles = fields_hash.fetch(:profiles, []) form_fields = if profiles.present? profiles.collect { |profile| fields = fields_hash.fetch(profile.to_sym, {}) content = [] content << content_tag(:h3, I18n.t("profiles.#{profile}", default: profile), class: 'lead clearfix') content << build_fields_for(decorator, fields) content.join.html_safe }.join.html_safe else build_fields_for(decorator, fields_hash) end [, form_fields].join.html_safe end |
#field_wrapper(method, options = {}, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/admin/show_view_helper.rb', line 50 def field_wrapper(method, = {}, &block) = .extract!(:label_class, :required, :block) is_block = [:block] [:class] ||= 'form-control' .merge!(id: '_form_id_'.concat(method)) content_tag(:li, class: is_block ? 'col-sm-12 col-md-12' : 'col-sm-6 col-md-6') do content = [content_tag(:b, [model.human_attribute_name(method), ":"].join, default: method)] if is_block content << content_tag(:p, yield(block)) else content << content_tag(:span, yield(block)) end content.join.html_safe end end |
#render_view(method, options = {}) ⇒ Object
44 45 46 47 48 |
# File 'app/helpers/admin/show_view_helper.rb', line 44 def render_view(method, = {}) field_wrapper(method, ) do decorate.human(method) end end |