Module: GovukLinkHelper
- Defined in:
- app/helpers/govuk_link_helper.rb
Constant Summary collapse
- LINK_STYLES =
{ 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", inverse: "govuk-button--inverse", }.freeze
Instance Method Summary collapse
- #govuk_breadcrumb_link_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
- #govuk_button_classes(*styles, default_class: 'govuk-button') ⇒ Object
- #govuk_button_link_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
- #govuk_button_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
- #govuk_link_classes(*styles, default_class: 'govuk-link') ⇒ Object
- #govuk_link_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
- #govuk_mail_to(email_address, name = nil, extra_options = {}, &block) ⇒ Object
Instance Method Details
#govuk_breadcrumb_link_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/govuk_link_helper.rb', line 82 def (name = nil, = nil, = {}, &block) = if block_given? = (, style: :breadcrumb) if block_given? link_to(name, , &block) else link_to(name, , ) end end |
#govuk_button_classes(*styles, default_class: 'govuk-button') ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/helpers/govuk_link_helper.rb', line 29 def (*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 |
#govuk_button_link_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/govuk_link_helper.rb', line 70 def (name = nil, = nil, = {}, &block) = if block_given? = GovukComponent::StartButtonComponent::LINK_ATTRIBUTES .merge (, style: :button) if block_given? link_to(name, , &block) else link_to(name, , ) end end |
#govuk_button_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/govuk_link_helper.rb', line 59 def (name = nil, = nil, = {}, &block) = if block_given? = (, style: :button) if block_given? (, , &block) else (name, , ) end end |
#govuk_link_classes(*styles, default_class: 'govuk-link') ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/helpers/govuk_link_helper.rb', line 21 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 |
#govuk_link_to(name = nil, options = nil, extra_options = {}, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/govuk_link_helper.rb', line 37 def govuk_link_to(name = nil, = nil, = {}, &block) = if block_given? = () if block_given? link_to(name, , &block) else link_to(name, , ) end end |
#govuk_mail_to(email_address, name = nil, extra_options = {}, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/govuk_link_helper.rb', line 48 def govuk_mail_to(email_address, name = nil, = {}, &block) = name if block_given? = () if block_given? mail_to(email_address, , &block) else mail_to(email_address, name, ) end end |