Module: EffectiveResourcesHelper
- Defined in:
- app/helpers/effective_resources_helper.rb
Instance Method Summary collapse
- #approve_icon_to(path, options = {}) ⇒ Object
- #destroy_icon_to(path, options = {}) ⇒ Object
- #edit_icon_to(path, options = {}) ⇒ Object
- #format_resource_value(value) ⇒ Object
- #glyphicon_to(icon, path, options = {}) ⇒ Object (also: #bootstrap_icon_to, #glyph_icon_to)
- #number_to_duration(duration) ⇒ Object
- #ok_icon_to(path, options = {}) ⇒ Object
- #remove_icon_to(path, options = {}) ⇒ Object
- #settings_icon_to(path, options = {}) ⇒ Object
-
#show_icon_to(path, options = {}) ⇒ Object
Icon Helpers for actions_column or elsewhere.
- #simple_form_save(form, options = {class: 'text-right'}, &block) ⇒ Object
- #simple_form_submit(form, options = {class: 'text-right'}, &block) ⇒ Object
-
#tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true) ⇒ Object
This is used by effective_orders, effective_logging, effective_trash and effective_mergery.
Instance Method Details
#approve_icon_to(path, options = {}) ⇒ Object
54 55 56 |
# File 'app/helpers/effective_resources_helper.rb', line 54 def approve_icon_to(path, = {}) glyphicon_to('ok', path, {title: 'Approve'}.merge()) end |
#destroy_icon_to(path, options = {}) ⇒ Object
41 42 43 44 |
# File 'app/helpers/effective_resources_helper.rb', line 41 def destroy_icon_to(path, = {}) defaults = {title: 'Destroy', data: {method: :delete, confirm: 'Delete this item?'}} glyphicon_to('trash', path, defaults.merge()) end |
#edit_icon_to(path, options = {}) ⇒ Object
37 38 39 |
# File 'app/helpers/effective_resources_helper.rb', line 37 def edit_icon_to(path, = {}) glyphicon_to('edit', path, {title: 'Edit'}.merge()) end |
#format_resource_value(value) ⇒ Object
105 106 107 108 109 110 |
# File 'app/helpers/effective_resources_helper.rb', line 105 def format_resource_value(value) ||= ActionView::Base..to_a + ['table', 'thead', 'tbody', 'tfoot', 'tr', 'td', 'th'] @format_resource_atts ||= ActionView::Base.sanitized_allowed_attributes.to_a + ['colspan', 'rowspan'] simple_format(sanitize(value.to_s, tags: , attributes: @format_resource_atts), {}, sanitize: false) end |
#glyphicon_to(icon, path, options = {}) ⇒ Object Also known as: bootstrap_icon_to, glyph_icon_to
62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/effective_resources_helper.rb', line 62 def glyphicon_to(icon, path, = {}) content_tag(:a, .merge(href: path)) do if icon.start_with?('glyphicon-') content_tag(:span, '', class: "glyphicon #{icon}") else content_tag(:span, '', class: "glyphicon glyphicon-#{icon}") end end end |
#number_to_duration(duration) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/effective_resources_helper.rb', line 20 def number_to_duration(duration) duration = duration.to_i value = duration.abs [ ('-' if duration < 0), ("#{value / 60}h " if value >= 60), ("#{'%0.2d' % (value % 60)}m" if value > 0), ('0m' if value == 0), ].compact.join end |
#ok_icon_to(path, options = {}) ⇒ Object
50 51 52 |
# File 'app/helpers/effective_resources_helper.rb', line 50 def ok_icon_to(path, = {}) glyphicon_to('ok', path, {title: 'OK'}.merge()) end |
#remove_icon_to(path, options = {}) ⇒ Object
58 59 60 |
# File 'app/helpers/effective_resources_helper.rb', line 58 def remove_icon_to(path, = {}) glyphicon_to('remove', path, {title: 'Remove'}.merge()) end |
#settings_icon_to(path, options = {}) ⇒ Object
46 47 48 |
# File 'app/helpers/effective_resources_helper.rb', line 46 def settings_icon_to(path, = {}) glyphicon_to('cog', path, {title: 'Settings'}.merge()) end |
#show_icon_to(path, options = {}) ⇒ Object
Icon Helpers for actions_column or elsewhere
33 34 35 |
# File 'app/helpers/effective_resources_helper.rb', line 33 def show_icon_to(path, = {}) glyphicon_to('eye-open', path, {title: 'Show'}.merge()) end |
#simple_form_save(form, options = {class: 'text-right'}, &block) ⇒ Object
14 15 16 17 18 |
# File 'app/helpers/effective_resources_helper.rb', line 14 def simple_form_save(form, = {class: 'text-right'}, &block) content_tag(:p, class: [:class]) do form.(:submit, 'Save', data: { disable_with: 'Saving...' }) + (capture(&:block) if block_given?) end end |
#simple_form_submit(form, options = {class: 'text-right'}, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'app/helpers/effective_resources_helper.rb', line 3 def simple_form_submit(form, = {class: 'text-right'}, &block) content_tag(:p, class: [:class]) do [ form.(:submit, 'Save', data: { disable_with: 'Saving...' }), form.(:submit, 'Save and Continue', data: { disable_with: 'Saving...' }), form.(:submit, 'Save and Add New', data: { disable_with: 'Saving...' }), (capture(&block) if block_given?) ].compact.join(' ').html_safe end end |
#tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true) ⇒ Object
This is used by effective_orders, effective_logging, effective_trash and effective_mergery
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/effective_resources_helper.rb', line 77 def tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true) case obj when Hash if flatten && obj[:attributes].kind_of?(Hash) obj = obj[:attributes].merge(obj.except(:attributes)) end content_tag(:table, class: table.presence) do content_tag(:tbody) do obj.map do |key, value| content_tag(:tr, class: key.to_param) do content_tag((th == true ? :th : :td), key) + content_tag(:td) { tableize_hash(value, table: sub_table, th: sub_th, sub_table: sub_table, sub_th: sub_th, flatten: flatten) } end end.join.html_safe end end when Array obj.map { |value| tableize_hash(value, table: sub_table, th: sub_th, sub_table: sub_table, sub_th: sub_th, flatten: flatten) }.join('<br>') when Symbol ":#{obj}" when NilClass '-' else obj.to_s.presence || '""' end.html_safe end |