Module: DesignSystemHelper
- Includes:
- ActionView::Helpers::FormHelper
- Defined in:
- app/helpers/design_system_helper.rb
Overview
The helpers for the design system
Instance Method Summary collapse
- #brand ⇒ Object
- #ds_alert(message) ⇒ Object
- #ds_button_tag(content_or_options = nil, options = nil) ⇒ Object
- #ds_callout(label, body) ⇒ Object
-
#ds_fixed_elements ⇒ Object
This method provides access to the current design system adapter.
- #ds_form_builder ⇒ Object
- #ds_form_with(model: nil, scope: nil, url: nil, format: nil, **options) ⇒ Object
- #ds_heading(text, level: 2, **options) ⇒ Object
- #ds_link_to(name = nil, options = nil, html_options = nil) ⇒ Object
- #ds_notice(message) ⇒ Object
- #ds_pagination(collection = nil, options = {}) ⇒ Object
- #ds_panel(title, body) ⇒ Object
- #ds_render_template(design_system_layout = 'application') ⇒ Object
- #ds_start_button(text, href = '#', options = {}) ⇒ Object
- #ds_summary_list ⇒ Object
- #ds_tab ⇒ Object
- #ds_table(options = {}) ⇒ Object
- #ds_timeago(date, refresh_interval: 60_000, format: :long) ⇒ Object
Instance Method Details
#brand ⇒ Object
7 8 9 |
# File 'app/helpers/design_system_helper.rb', line 7 def brand controller.send(:brand) end |
#ds_alert(message) ⇒ Object
77 78 79 |
# File 'app/helpers/design_system_helper.rb', line 77 def ds_alert() DesignSystem::Registry.builder(brand, 'notification', self).render_alert() end |
#ds_button_tag(content_or_options = nil, options = nil) ⇒ Object
59 60 61 |
# File 'app/helpers/design_system_helper.rb', line 59 def ( = nil, = nil, &) DesignSystem::Registry.builder(brand, 'button', self).(, , &) end |
#ds_callout(label, body) ⇒ Object
108 109 110 |
# File 'app/helpers/design_system_helper.rb', line 108 def ds_callout(label, body) DesignSystem::Registry.builder(brand, 'callout', self).render_callout(label, body) end |
#ds_fixed_elements ⇒ Object
This method provides access to the current design system adapter
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/design_system_helper.rb', line 12 def ds_fixed_elements instance = DesignSystem::Registry.builder(brand, 'fixed_elements', self) if block_given? yield instance instance.render else instance end end |
#ds_form_builder ⇒ Object
24 25 26 |
# File 'app/helpers/design_system_helper.rb', line 24 def ds_form_builder DesignSystem::Registry.form_builder(brand) end |
#ds_form_with(model: nil, scope: nil, url: nil, format: nil, **options) ⇒ Object
28 29 30 |
# File 'app/helpers/design_system_helper.rb', line 28 def ds_form_with(model: nil, scope: nil, url: nil, format: nil, **, &) form_with(model:, scope:, url:, format:, builder: ds_form_builder, **, &) end |
#ds_heading(text, level: 2, **options) ⇒ Object
85 86 87 |
# File 'app/helpers/design_system_helper.rb', line 85 def ds_heading(text, level: 2, **) DesignSystem::Registry.builder(brand, 'heading', self).render_heading(text, level:, **) end |
#ds_link_to(name = nil, options = nil, html_options = nil) ⇒ Object
63 64 65 |
# File 'app/helpers/design_system_helper.rb', line 63 def ds_link_to(name = nil, = nil, = nil, &) DesignSystem::Registry.builder(brand, 'link', self).render_link_to(name, , , &) end |
#ds_notice(message) ⇒ Object
81 82 83 |
# File 'app/helpers/design_system_helper.rb', line 81 def ds_notice() DesignSystem::Registry.builder(brand, 'notification', self).render_notice() end |
#ds_pagination(collection = nil, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'app/helpers/design_system_helper.rb', line 67 def ds_pagination(collection = nil, = {}) defaults = { renderer: DesignSystem::Registry.builder(brand, 'pagination_renderer', self), previous_label: '« Previous', next_label: 'Next »' } will_paginate(collection, defaults.merge!()) end |
#ds_panel(title, body) ⇒ Object
104 105 106 |
# File 'app/helpers/design_system_helper.rb', line 104 def ds_panel(title, body) DesignSystem::Registry.builder(brand, 'panel', self).render_panel(title, body) end |
#ds_render_template(design_system_layout = 'application') ⇒ Object
32 33 34 35 |
# File 'app/helpers/design_system_helper.rb', line 32 def ds_render_template(design_system_layout = 'application') @design_system_layout = design_system_layout render(template: "layouts/#{brand}/#{design_system_layout}") end |
#ds_start_button(text, href = '#', options = {}) ⇒ Object
55 56 57 |
# File 'app/helpers/design_system_helper.rb', line 55 def (text, href = '#', = {}) DesignSystem::Registry.builder(brand, 'button', self).(text, href, ) end |
#ds_summary_list ⇒ Object
43 44 45 46 47 |
# File 'app/helpers/design_system_helper.rb', line 43 def ds_summary_list(&) raise ArgumentError unless block_given? DesignSystem::Registry.builder(brand, 'summary_list', self).render_summary_list(&) end |
#ds_tab ⇒ Object
49 50 51 52 53 |
# File 'app/helpers/design_system_helper.rb', line 49 def ds_tab(&) raise ArgumentError unless block_given? DesignSystem::Registry.builder(brand, 'tab', self).render_tabs(&) end |
#ds_table(options = {}) ⇒ Object
37 38 39 40 41 |
# File 'app/helpers/design_system_helper.rb', line 37 def ds_table( = {}, &) raise ArgumentError unless block_given? DesignSystem::Registry.builder(brand, 'table', self).render_table(, &) end |
#ds_timeago(date, refresh_interval: 60_000, format: :long) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/design_system_helper.rb', line 89 def ds_timeago(date, refresh_interval: 60_000, format: :long) return if date.blank? content = I18n.l(date, format:) tag.time(content, title: content, data: { controller: 'timeago', timeago_datetime_value: date.iso8601, timeago_refresh_interval_value: refresh_interval, timeago_add_suffix_value: true }) end |