Module: CoreTableHelper
- Defined in:
- app/helpers/core_table_helper.rb
Overview
Methods useful for building out tables
Instance Method Summary collapse
- #card_table_header_actions_tag(clazz, path, classes: [], icon_name: :add, title: 'Add') ⇒ Object
-
#table_data_boolean(value, show_false: true) ⇒ String
abstract
-
The HTML for the cell.
-
-
#table_header_actions_tag(name: :actions, classes: %w[actions],, priority: 2, visible: true) ⇒ Object
Format the table header.
-
#table_header_tag(name, classes: [], priority: 1, visible: true, icon_name: nil) ⇒ Object
Format the table header.
-
#table_header_text(name) ⇒ Object
First look to see if a localized string was passed in, then try to look in table.headers.…
Instance Method Details
#card_table_header_actions_tag(clazz, path, classes: [], icon_name: :add, title: 'Add') ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/core_table_helper.rb', line 7 def card_table_header_actions_tag(clazz, path, classes: [], icon_name: :add, title: 'Add') return unless can?(:create, clazz) classes << 'btn' content_tag(:a, class: classes.join(' '), href: path) do concat(svg_icon(icon_name)) concat(content_tag(:span, title)) end end |
#table_data_boolean(value, show_false: true) ⇒ String
This method is abstract.
Return a table data cell with a boolean value
Returns - The HTML for the cell.
75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/core_table_helper.rb', line 75 def table_data_boolean(value, show_false: true) content_tag(:td, class: 'text-center', data: { order: value ? 0 : 1 }) do if value svg_icon(:check, color: :green) else svg_icon(:x, color: :red) if show_false end end end |
#table_header_actions_tag(name: :actions, classes: %w[actions],, priority: 2, visible: true) ⇒ Object
Format the table header
24 25 26 27 28 |
# File 'app/helpers/core_table_helper.rb', line 24 def table_header_actions_tag(name: :actions, classes: %w[actions], priority: 2, visible: true) return unless visible table_header_tag(name, classes: classes, priority: priority, visible: visible, icon_name: :menu) end |
#table_header_tag(name, classes: [], priority: 1, visible: true, icon_name: nil) ⇒ Object
Format the table header
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/core_table_helper.rb', line 37 def table_header_tag(name, classes: [], priority: 1, visible: true, icon_name: nil) return unless visible = { data: { priority: priority } } [:class] = classes if classes.present? content_tag(:th, ) do if icon_name.present? concat(svg_icon(icon_name)) concat(content_tag(:span, class: 'ms-2 d-sm-none d-lg-inline') { table_header_text(name) }) else table_header_text(name) end end end |
#table_header_text(name) ⇒ Object
First look to see if a localized string was passed in, then try to look in table.headers.… lastly return the titleized string
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/core_table_helper.rb', line 58 def table_header_text(name) if I18n.exists?(name) t(name) elsif I18n.exists?("table.headers.#{name}") t("table.headers.#{name}") elsif I18n.exists?("core_table.headers.#{name}") t("core_table.headers.#{name}") else name.to_s.titleize end rescue StandardError name end |