Module: GovukRailsCompatibleLinkHelper

Defined in:
app/helpers/govuk_rails_compatible_link_helper.rb

Instance Method Summary collapse

Instance Method Details



79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/govuk_rails_compatible_link_helper.rb', line 79

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: "#{brand}-button") ⇒ Object



14
15
16
17
18
19
20
# File 'app/helpers/govuk_rails_compatible_link_helper.rb', line 14

def govuk_button_classes(*styles, default_class: "#{brand}-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


64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/govuk_rails_compatible_link_helper.rb', line 64

def govuk_button_link_to(name = nil, options = nil, extra_options = {}, &block)
  extra_options = options if block_given?
  html_options = {
    data: { module: "#{brand}-button" },
    draggable: 'false',
    role: 'button',
  }.merge build_html_options(extra_options, style: :button)

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

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/govuk_rails_compatible_link_helper.rb', line 44

def govuk_button_to(name = nil, options = nil, extra_options = {}, &block)
  extra_options = options if block_given?
  html_options = {
    data: { module: "#{brand}-button" }
  }

  if extra_options && extra_options[:prevent_double_click]
    html_options[:data]["prevent-double-click"] = "true"
    extra_options = extra_options.except(:prevent_double_click)
  end

  html_options.merge! 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


6
7
8
9
10
11
12
# File 'app/helpers/govuk_rails_compatible_link_helper.rb', line 6

def govuk_link_classes(*styles, default_class: "#{brand}-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


22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/govuk_rails_compatible_link_helper.rb', line 22

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

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

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



33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/govuk_rails_compatible_link_helper.rb', line 33

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