-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathview.rb
More file actions
63 lines (57 loc) · 2.73 KB
/
view.rb
File metadata and controls
63 lines (57 loc) · 2.73 KB
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
# frozen_string_literal: true
module MarkdownEditorComponent
class View < ViewComponent::Base
include GOVUKDesignSystemFormBuilder::BuilderHelper
attr_reader :attribute_name, :f, :render_preview_path, :preview_html, :form_model, :label, :hint, :allow_headings
def initialize(attribute_name,
preview_html:,
form_model:,
form_builder: nil,
label: nil,
hint: nil,
render_preview_path: nil,
allow_headings: true,
local_translations: {})
super
@attribute_name = attribute_name
@f = form_builder
@render_preview_path = render_preview_path
@preview_html = preview_html
@form_model = form_model
@label = label
@hint = hint
@allow_headings = allow_headings
@local_translations = local_translations
end
def form_field_id
govuk_field_id(form_model, attribute_name)
end
def allowed_formats
[ "links", *(%w[headings] if allow_headings), "bulleted_lists", "numbered_lists" ]
end
def preview_button_translation
form_model.public_send(attribute_name).blank? ? translations[:preview_markdown] : translations[:update_preview]
end
def translations
{
preview_description: @local_translations[:preview_description] || I18n.t("markdown_editor.preview.description"),
preview_heading: @local_translations[:preview_heading] || I18n.t("markdown_editor.preview.heading"),
preview_markdown: @local_translations[:preview_markdown] || I18n.t("markdown_editor.preview_markdown"),
preview_tab_text: @local_translations[:preview_tab_text] || I18n.t("markdown_editor.preview_tab_text"),
update_preview: @local_translations[:update_preview] || I18n.t("markdown_editor.update_preview"),
write_tab_text: @local_translations[:write_tab_text] || I18n.t("markdown_editor.write_tab_text"),
preview_loading: @local_translations[:preview_loading] || I18n.t("markdown_editor.preview_loading"),
preview_error: @local_translations[:preview_error] || I18n.t("markdown_editor.preview_error"),
edit_markdown_link: @local_translations[:edit_markdown_link] || I18n.t("markdown_editor.edit_markdown_link"),
preview_area_label: @local_translations[:preview_area_label] || I18n.t("markdown_editor.preview_area_label"),
toolbar: {
h2: I18n.t("markdown_editor.toolbar.h2"),
h3: I18n.t("markdown_editor.toolbar.h3"),
link: I18n.t("markdown_editor.toolbar.link"),
bullet_list: I18n.t("markdown_editor.toolbar.bullet_list"),
numbered_list: I18n.t("markdown_editor.toolbar.numbered_list"),
},
}
end
end
end