-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustom_form_helpers.rb
70 lines (58 loc) · 1.68 KB
/
custom_form_helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module CustomFormHelpers
delegate :params, :hidden_field_tag, to: :template
attr_reader :template
def continue_button(continue: :continue)
submit_button(continue)
end
# Used to customise captions above the page heading
def i18n_caption
I18n.t(
object.conviction_subtype, scope: scope_for_locale(:caption)
)
end
# Used to customise legends when reusing the same view
def i18n_legend
I18n.t(
object.i18n_attribute, scope: scope_for_locale(:legend), default: :default
)
end
def i18n_date_hint(lead_text = i18n_lead_text)
safe_join([
content_tag(:p, lead_text),
I18n.t("helpers/dictionary.date_hint_text").html_safe,
])
end
# Used to customise hints when reusing the same view
# Hints support markup so ensure locale keys ends with `_html`
def i18n_hint
I18n.t(
"#{object.i18n_attribute}_html", scope: scope_for_locale(:hint), default: :default_html
).html_safe
end
# Used to customise lead text when reusing the same view
def i18n_lead_text
I18n.t(
object.i18n_attribute, scope: scope_for_locale(:lead_text), default: :default
)
end
private
def submit_button(i18n_key, opts = {}, &block)
safe_join(
[
next_step_if_present,
govuk_submit(I18n.t("helpers.buttons.#{i18n_key}"), **opts, &block),
],
)
end
# Do not blindly trust the param, always check
def next_step_if_present
next_step = case params[:next_step]
when "cya"
"/steps/check/check_your_answers"
end
hidden_field_tag(:next_step, next_step) if next_step
end
def scope_for_locale(context)
[:helpers, context, object_name]
end
end