diff --git a/app/helpers/govuk_link_helper.rb b/app/helpers/govuk_link_helper.rb index f7d4666a..357c2a4d 100644 --- a/app/helpers/govuk_link_helper.rb +++ b/app/helpers/govuk_link_helper.rb @@ -3,6 +3,35 @@ module GovukLinkHelper using HTMLAttributesUtils + def govuk_link_classes(inverse: false, muted: false, no_underline: false, no_visited_state: false, text_colour: false) + if [text_colour, inverse, muted].count(true) > 1 + fail("links can be either text_colour, inverse or muted - not combinations of the three") + end + + class_names( + "govuk-link", + "govuk-link--inverse" => inverse, + "govuk-link--muted" => muted, + "govuk-link--no-underline" => no_underline, + "govuk-link--no-visited-state" => no_visited_state, + "govuk-link--text-colour" => text_colour, + ) + end + + def govuk_button_classes(disabled: false, inverse: false, secondary: false, warning: false) + if [inverse, secondary, warning].count(true) > 1 + fail("buttons can be either inverse, secondary or warning - not combinations of the three") + end + + class_names( + "govuk-button", + "govuk-button--disabled" => disabled, + "govuk-button--inverse" => inverse, + "govuk-button--secondary" => secondary, + "govuk-button--warning" => warning, + ) + end + def govuk_link_to(name, href = nil, new_tab: false, inverse: false, muted: false, no_underline: false, no_visited_state: false, text_colour: false, **kwargs, &block) link_args = extract_link_args(new_tab: new_tab, inverse: inverse, muted: muted, no_underline: no_underline, no_visited_state: no_visited_state, text_colour: text_colour, **kwargs) @@ -23,23 +52,23 @@ def govuk_mail_to(email_address, name = nil, new_tab: false, inverse: false, mut end end - def govuk_button_link_to(name, href = nil, new_tab: false, disabled: false, inverse: false, secondary: false, warning: false, **kwargs, &block) - button_args = extract_button_args(new_tab: new_tab, disabled: disabled, inverse: inverse, secondary: secondary, warning: warning, **kwargs) + def govuk_button_to(name, href = nil, disabled: false, inverse: false, secondary: false, warning: false, **kwargs, &block) + button_args = extract_button_args(new_tab: false, disabled: disabled, inverse: inverse, secondary: secondary, warning: warning, **kwargs) if block_given? - link_to(block.call, href, **button_args) + button_to(block.call, href, **button_args) else - link_to(name, href, **button_args) + button_to(name, href, **button_args) end end - def govuk_button_to(name, href = nil, disabled: false, inverse: false, secondary: false, warning: false, **kwargs, &block) - button_args = extract_button_args(new_tab: false, disabled: disabled, inverse: inverse, secondary: secondary, warning: warning, **kwargs) + def govuk_button_link_to(name, href = nil, new_tab: false, disabled: false, inverse: false, secondary: false, warning: false, **kwargs, &block) + button_args = extract_button_args(new_tab: new_tab, disabled: disabled, inverse: inverse, secondary: secondary, warning: warning, **kwargs) if block_given? - button_to(block.call, href, **button_args) + link_to(block.call, href, **button_args) else - button_to(name, href, **button_args) + link_to(name, href, **button_args) end end @@ -53,35 +82,6 @@ def govuk_breadcrumb_link_to(name, href = nil, **kwargs, &block) end end - def govuk_link_classes(inverse: false, muted: false, no_underline: false, no_visited_state: false, text_colour: false) - if [text_colour, inverse, muted].count(true) > 1 - fail("links can be either text_colour, inverse or muted - not combinations of the three") - end - - class_names( - "govuk-link", - "govuk-link--inverse" => inverse, - "govuk-link--muted" => muted, - "govuk-link--no-underline" => no_underline, - "govuk-link--no-visited-state" => no_visited_state, - "govuk-link--text-colour" => text_colour, - ) - end - - def govuk_button_classes(disabled: false, inverse: false, secondary: false, warning: false) - if [inverse, secondary, warning].count(true) > 1 - fail("buttons can be either inverse, secondary or warning - not combinations of the three") - end - - class_names( - "govuk-button", - "govuk-button--disabled" => disabled, - "govuk-button--inverse" => inverse, - "govuk-button--secondary" => secondary, - "govuk-button--warning" => warning, - ) - end - private def new_tab_args(new_tab)