Sha256: ff7c46cc806d5a0e67605afd76ad223540139a413224ab987e151f65e00e74ba

Contents?: true

Size: 1.53 KB

Versions: 31

Compression:

Stored size: 1.53 KB

Contents

require 'active_support'
require 'action_view/helpers/tag_helper'
require 'action_view/helpers/form_tag_helper'

module Ckeditor
  class TextArea
    include ActionView::Helpers::TagHelper
    include ActionView::Helpers::FormTagHelper
    include ActionView::Helpers::JavaScriptHelper

    attr_reader :template, :options, :ck_options

    def initialize(template, options)
      @template = template
      @options = options.stringify_keys
      @ck_options = (@options.delete('ckeditor') || {}).stringify_keys
    end

    def render_instance_tag(object_name, method)
      tag = build_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
    end

    def render_tag(name, content)
      options['id'] = sanitize_to_id(options['id'] || name)

      render text_area_tag(name, content, options)
    end

    protected

      def render(input)
        output_buffer << input
        output_buffer << javascript_tag(Utils.js_replace(options['id'], ck_options))
        output_buffer
      end

      def output_buffer
        @output_buffer ||= ActiveSupport::SafeBuffer.new
      end

      def build_tag(object_name, method)
        if defined?(ActionView::Base::Tags::TextArea)
          ActionView::Base::Tags::TextArea.new(object_name, method, template, options.symbolize_keys)
        else
          ActionView::Base::InstanceTag.new(object_name, method, template, options.delete('object'))
        end
      end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
ckeditor-4.1.5 lib/ckeditor/text_area.rb
ckeditor-4.1.4 lib/ckeditor/text_area.rb
ckeditor-4.1.3 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.7.4 lib/ckeditor/text_area.rb
ckeditor-4.1.2 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.7.3 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.7.2 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.7.1 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.7 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.6 lib/ckeditor/text_area.rb
ckeditor-4.1.1 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.3.4 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.3.3 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.3.2 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.3.1 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.4.3.0 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.3.2.6 lib/ckeditor/text_area.rb
ckeditor-4.1.0 lib/ckeditor/text_area.rb
glebtv-ckeditor-4.3.2.5 lib/ckeditor/text_area.rb
ckeditor-4.0.11 lib/ckeditor/text_area.rb