Module: DesignSystemHelper

Includes:
ActionView::Helpers::FormHelper
Included in:
DesignSystem::Govuk::TestHelpers::FormBuilderTestable
Defined in:
app/helpers/design_system_helper.rb

Overview

The helpers for the design system

Instance Method Summary collapse

Instance Method Details

#brandObject



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(message)
  DesignSystem::Registry.builder(brand, 'notification', self).render_alert(message)
end

#ds_button_tag(content_or_options = nil, options = nil) ⇒ Object



59
60
61
# File 'app/helpers/design_system_helper.rb', line 59

def ds_button_tag(content_or_options = nil, options = nil, &)
  DesignSystem::Registry.builder(brand, 'button', self).render_button(content_or_options, options, &)
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_elementsObject

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_builderObject



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, **options, &)
  form_with(model:, scope:, url:, format:, builder: ds_form_builder, **options, &)
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, **options)
  DesignSystem::Registry.builder(brand, 'heading', self).render_heading(text, level:, **options)
end


63
64
65
# File 'app/helpers/design_system_helper.rb', line 63

def ds_link_to(name = nil, options = nil, html_options = nil, &)
  DesignSystem::Registry.builder(brand, 'link', self).render_link_to(name, options, html_options, &)
end

#ds_notice(message) ⇒ Object



81
82
83
# File 'app/helpers/design_system_helper.rb', line 81

def ds_notice(message)
  DesignSystem::Registry.builder(brand, 'notification', self).render_notice(message)
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, options = {})
  defaults = {
    renderer: DesignSystem::Registry.builder(brand, 'pagination_renderer', self),
    previous_label: '« Previous',
    next_label: 'Next »'
  }

  will_paginate(collection, defaults.merge!(options))
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 ds_start_button(text, href = '#', options = {})
  DesignSystem::Registry.builder(brand, 'button', self).render_start_button(text, href, options)
end

#ds_summary_listObject

Raises:

  • (ArgumentError)


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_tabObject

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


37
38
39
40
41
# File 'app/helpers/design_system_helper.rb', line 37

def ds_table(options = {}, &)
  raise ArgumentError unless block_given?

  DesignSystem::Registry.builder(brand, 'table', self).render_table(options, &)
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