Skip to content

Commit

Permalink
Reorder the link helpers to make review easier
Browse files Browse the repository at this point in the history
  • Loading branch information
peteryates committed Jun 12, 2023
1 parent b0f9d4e commit 640125c
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions app/helpers/govuk_link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 640125c

Please sign in to comment.