-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmarkdown_form_builder.rb
43 lines (35 loc) · 1.17 KB
/
markdown_form_builder.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
# frozen_string_literal: true
class MarkdownFormBuilder < ActionView::Helpers::FormBuilder
def markdown(method, args = {})
# Adopt simple form builder to work with form_for
@attribute_name = method
@input_html_options = args[:input_html]
@template.capture do
@template.concat form_textarea
@template.concat toast_ui_editor
end
end
private
def form_textarea
@template.text_area @object_name, @attribute_name,
**(@input_html_options || {}),
id: label_target,
class: 'd-none'
end
def toast_ui_editor
@template.tag.div(class: 'markdown-editor__wrapper') do
@template.concat @template.tag.div(class: 'markdown-editor', data: {behavior: 'markdown-editor-widget', id: label_target})
@template.concat resize_btn
end
end
def resize_btn
@template.tag.button(class: 'markdown-editor__resize-btn fa-solid', type: 'button', id: "#{label_target}-resize",
title: I18n.t(:'application.markdown_editor.expand'), aria_label: I18n.t(:'application.markdown_editor.expand'))
end
def base_id
options[:markdown_id_suffix] || @attribute_name
end
def label_target
"markdown-input-#{base_id}"
end
end