Module: GovukLinkHelper

Defined in:
app/helpers/govuk_link_helper.rb

Constant Summary collapse

{
  inverse:          "govuk-link--inverse",
  muted:            "govuk-link--muted",
  no_underline:     "govuk-link--no-underline",
  no_visited_state: "govuk-link--no-visited-state",
  text_colour:      "govuk-link--text-colour",
}.freeze
BUTTON_STYLES =
{
  disabled:  "govuk-button--disabled",
  secondary: "govuk-button--secondary",
  warning:   "govuk-button--warning",
}.freeze
NEW_TAB_ATTRIBUTES =
{
  target: "_blank",
  rel: "noreferrer noopener"
}.freeze

Instance Method Summary collapse

Instance Method Details



86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/govuk_link_helper.rb', line 86

def govuk_breadcrumb_link_to(name = nil, options = nil, extra_options = {}, &block)
  extra_options = options if block_given?
  html_options = build_html_options(extra_options, style: :breadcrumb)

  if block_given?
    link_to(name, html_options, &block)
  else
    link_to(name, options, html_options)
  end
end

#govuk_button_classes(*styles, default_class: 'govuk-button') ⇒ Object



33
34
35
36
37
38
39
# File 'app/helpers/govuk_link_helper.rb', line 33

def govuk_button_classes(*styles, default_class: 'govuk-button')
  if (invalid_styles = (styles - BUTTON_STYLES.keys)) && invalid_styles.any?
    fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{BUTTON_STYLES.keys.to_sentence}")
  end

  [default_class] + BUTTON_STYLES.values_at(*styles).compact
end


74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/govuk_link_helper.rb', line 74

def govuk_button_link_to(name = nil, options = nil, extra_options = {}, new_tab: false, &block)
  extra_options = options if block_given?
  html_options = GovukComponent::StartButtonComponent::LINK_ATTRIBUTES
    .merge build_html_options(extra_options, style: :button, new_tab: new_tab)

  if block_given?
    link_to(name, html_options, &block)
  else
    link_to(prepare_link_text(name, new_tab), options, html_options)
  end
end

#govuk_button_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/govuk_link_helper.rb', line 63

def govuk_button_to(name = nil, options = nil, extra_options = {}, &block)
  extra_options = options if block_given?
  html_options = build_html_options(extra_options, style: :button)

  if block_given?
    button_to(options, html_options, &block)
  else
    button_to(name, options, html_options)
  end
end


25
26
27
28
29
30
31
# File 'app/helpers/govuk_link_helper.rb', line 25

def govuk_link_classes(*styles, default_class: 'govuk-link')
  if (invalid_styles = (styles - LINK_STYLES.keys)) && invalid_styles.any?
    fail(ArgumentError, "invalid styles #{invalid_styles.to_sentence}. Valid styles are #{LINK_STYLES.keys.to_sentence}")
  end

  [default_class] + LINK_STYLES.values_at(*styles).compact
end


41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/govuk_link_helper.rb', line 41

def govuk_link_to(name = nil, options = nil, extra_options = {}, new_tab: false, &block)
  extra_options = options if block_given?
  html_options = build_html_options(extra_options, new_tab: new_tab)

  if block_given?
    link_to(name, html_options, &block)
  else
    link_to(prepare_link_text(name, new_tab), options, html_options)
  end
end

#govuk_mail_to(email_address, name = nil, extra_options = {}, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/govuk_link_helper.rb', line 52

def govuk_mail_to(email_address, name = nil, extra_options = {}, &block)
  extra_options = name if block_given?
  html_options = build_html_options(extra_options)

  if block_given?
    mail_to(email_address, html_options, &block)
  else
    mail_to(email_address, name, html_options)
  end
end