Module: Releaf::Builders::FormBuilder::RichtextFields

Included in:
Fields
Defined in:
app/builders/releaf/builders/form_builder/richtext_fields.rb

Instance Method Summary collapse

Instance Method Details

#releaf_richtext_field(name, input: {}, label: {}, field: {}, options: {}, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'app/builders/releaf/builders/form_builder/richtext_fields.rb', line 2

def releaf_richtext_field(name, input: {}, label: {}, field: {}, options: {}, &block)
  attributes = richtext_input_attributes(name)
    .merge(value: object.send(name))
    .merge(input)
  attributes = input_attributes(name, attributes, options)

  options = richtext_options(name, options)
  content = text_area(name, attributes)

  input_wrapper_with_label(name, content, label: label, field: field, options: options, &block)
end

#richtext_input_attributes(_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/builders/releaf/builders/form_builder/richtext_fields.rb', line 14

def richtext_input_attributes(_name)
  {
    rows: 5,
    cols: 50,
    class: "richtext",
    data: {
      "attachment-upload-url" => (controller.respond_to?(:releaf_richtext_attachment_upload_url) ? controller.releaf_richtext_attachment_upload_url : '')
    },
  }
end

#richtext_options(name, options) ⇒ Object



25
26
27
# File 'app/builders/releaf/builders/form_builder/richtext_fields.rb', line 25

def richtext_options(name, options)
  {field: {type: "richtext"}, label: {translation_key: name.to_s.sub(/_html$/, '').to_s }}.deep_merge(options)
end