class NewCkeditor::Editor

Attributes

options[R]
template[R]

Public Class Methods

new(template, options) click to toggle source
# File lib/new_ckeditor/editor.rb, line 14
def initialize(template, options)
  @template = template
  options.delete(:required) # to avoid bug of validating empty textarea
  @options = options.deep_stringify_keys!
end

Public Instance Methods

render_instance_tag(object_name, method) click to toggle source
# File lib/new_ckeditor/editor.rb, line 20
def render_instance_tag(object_name, method)
  tag = build_instance_tag(object_name, method)
  tag.send(:add_default_name_and_id, options) if options['id'].blank?
  render(tag.respond_to?(:to_text_area_tag) ? tag.to_text_area_tag(options) : tag.render, options)
end
render_tag(name, content) click to toggle source
# File lib/new_ckeditor/editor.rb, line 26
def render_tag(name, content)
  options['id'] = sanitize_to_id(options['id'] || name)
  tag = build_tag(name, content, options)
  render(tag, options)
end

Protected Instance Methods

build_instance_tag(object_name, method) click to toggle source
# File lib/new_ckeditor/editor.rb, line 49
def build_instance_tag(object_name, method)
  if editor_type.to_s == "classic"
    ActionView::Base::Tags::TextArea.new(object_name, method, template, options.symbolize_keys)
  else
    ActionView::Base::Tags::HiddenField.new(object_name, method, template, options.symbolize_keys)
  end
end
build_tag(name, content, options) click to toggle source
# File lib/new_ckeditor/editor.rb, line 57
def build_tag(name, content, options)
  if editor_type.to_s == "classic"
    text_area_tag(name, content, options)
  else
    hidden_field_tag(name, content, options)
  end
end
editor_template() click to toggle source
# File lib/new_ckeditor/editor.rb, line 45
def editor_template
  options.dig("editor", "template") || "classic"
end
editor_type() click to toggle source
# File lib/new_ckeditor/editor.rb, line 41
def editor_type
  options.dig("editor", "type") || "classic"
end
render(input, options) click to toggle source
# File lib/new_ckeditor/editor.rb, line 34
def render(input, options)
  result = ActiveSupport::SafeBuffer.new
  result << input
  result << @template.render("/new_ckeditor/shared/#{editor_template}", id: options["id"], options: options)
  result
end