-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move code from component into a helper
- Loading branch information
1 parent
a2a0684
commit 2d2e237
Showing
3 changed files
with
71 additions
and
30 deletions.
There are no files selected for viewing
43 changes: 13 additions & 30 deletions
43
app/views/govuk_publishing_components/components/_subscription-links.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
lib/govuk_publishing_components/presenters/subscription_links_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module GovukPublishingComponents | ||
module Presenters | ||
class SubscriptionLinksHelper | ||
def initialize(local_assigns) | ||
@local_assigns = local_assigns | ||
@feed_box_id = "feed-reader-#{SecureRandom.hex(2)}" | ||
end | ||
|
||
def email_signup_link | ||
@local_assigns[:email_signup_link] | ||
end | ||
|
||
def email_signup_link_data_attributes | ||
@local_assigns[:email_signup_link_data_attributes] | ||
end | ||
|
||
def feed_link_box_value | ||
@local_assigns[:feed_link_box_value] | ||
end | ||
|
||
def feed_box_id | ||
@feed_box_id | ||
end | ||
|
||
def email_signup_link_text | ||
return @local_assigns[:email_signup_link_text] if @local_assigns[:email_signup_link_text] | ||
I18n.t("govuk_component.subscription_links.email_signup_link_text", default: "Get email alerts") | ||
end | ||
|
||
def feed_link_text | ||
return @local_assigns[:feed_link_text] if @local_assigns[:feed_link_text] | ||
I18n.t("govuk_component.subscription_links.feed_link_text", default: "Subscribe to feed") | ||
end | ||
|
||
def component_data_is_valid? | ||
email_signup_link.present? || feed_link.present? || feed_link_box_value.present? | ||
end | ||
|
||
def tracking_is_present? | ||
@local_assigns[:email_signup_link_data_attributes].present? || @local_assigns[:feed_link_data_attributes].present? | ||
end | ||
|
||
def feed_link | ||
return "#" if feed_link_box_value | ||
@local_assigns[:feed_link] | ||
end | ||
|
||
def feed_link_data_attributes | ||
data = @local_assigns[:feed_link_data_attributes] || {} | ||
data[:controls] = feed_box_id | ||
data[:expanded] = "false" | ||
data | ||
end | ||
|
||
end | ||
end | ||
end |