module Bootsy::FormHelper

Public: Module to include Bootsy in `ActionView::Base`.

Public Instance Methods

bootsy_area(object_name, method, options = {}) click to toggle source

Public: Return a textarea element with proper attributes to be loaded as a WYSIWYG editor.

object_name - The String or Symbol identifier of the object assigned

to the template.

method - The Symbol attribute name on the object assigned to the

form builder that will tailor the editor.

options - The Hash of options used to enable/disable features of

the editor (default: {}):
:container      - The `Bootsy::Container` instance model
                  that will be referenced by the editor's
                  image gallery. Defaults to the object
                  assigned to the template, if it is a
                  `Container`.
:uploader       - The Boolean value used to enable/disable
                  the image upload feature. Default: true,
                  if a`Container` is found, false otherwise.
:editor_options - The Hash of options with Boolean values
                  usedto enable/disable features of the
                  editor. Available options are described ib
                  the Bootsyinitializer file (which is the
                  default for this argument).
# File lib/bootsy/form_helper.rb, line 29
def bootsy_area(object_name, method, options = {})
  container = options[:container] || options[:object]

  set_gallery_id(container, options)

  text_area(object_name, method, text_area_options(options)) +
    modal(options, container) +
    gallery_id_param(object_name, container, options)
end

Private Instance Methods

bootsy_options(options) click to toggle source
# File lib/bootsy/form_helper.rb, line 74
def bootsy_options(options)
  Bootsy.editor_options.merge(options[:editor_options] || {})
        .merge(uploader: enable_uploader?(options))
end
data_options(options) click to toggle source
# File lib/bootsy/form_helper.rb, line 66
def data_options(options)
  (options[:data] || {}).deep_merge(
    Hash[bootsy_options(options).map do |key, value|
      ["bootsy-#{key}", value]
    end]
  )
end
enable_uploader?(options) click to toggle source
# File lib/bootsy/form_helper.rb, line 41
def enable_uploader?(options)
  if options[:uploader] == false
    false
  elsif options[:container].is_a?(Container)
    true
  elsif options[:container].blank? && options[:object].is_a?(Container)
    true
  else
    false
  end
end
modal(options, container) click to toggle source
tag_class(options) click to toggle source
# File lib/bootsy/form_helper.rb, line 53
def tag_class(options)
  classes =
    if options[:class].blank?
      []
    elsif options[:class].is_a?(Array)
      options[:class]
    else
      [options[:class]]
    end

  classes << 'bootsy_text_area'
end
text_area_options(options) click to toggle source
# File lib/bootsy/form_helper.rb, line 79
def text_area_options(options)
  options.except(
    :container,
    :uploader,
    :editor_options
  ).merge(
    data: data_options(options),
    class: tag_class(options)
  )
end