Sha256: dfb0b81a7b7f2c747575f7ae0f48a328a568a0ea4f0920afc61a66a91ba7071b

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require 'paperclip'

module ActionView
  module Helpers
    module FormHelper
      def wysihat_editor(object_name, method, options = {})
        InstanceTag.new(object_name, method, self, options.delete(:object)).to_wysihat_editor_tag(options)
      end
    end

    class InstanceTag #:nodoc:
      def to_wysihat_editor_tag(options = {})
        options = DEFAULT_TEXT_AREA_OPTIONS.merge(options.stringify_keys)
        add_default_name_and_id(options)

        size = options.delete("size")
        options["cols"], options["rows"] = size.split("x") if size && size.respond_to?(:split)

        if options['buttons'] == nil || options['buttons'] == :all
          buttons = [:bold, :italic, :underline, :strikethrough, :h1, :h2, :h3, :p, :justify_left, :justify_center, :justify_right, :insert_ordered_list, :insert_unordered_list, :undo, :redo, :link, :html, :image, :paste]
        else
          buttons = options['buttons']
        end

        javascript = "Event.observe(window, 'load', function() {" <<
        "wysiHatify('#{tag_id}', ['#{buttons.join('\', \'')}']);" <<
        "});"

        content_tag(:script, javascript, :type => 'text/javascript') <<
        content_tag(:textarea, html_escape(options.delete('value') || value_before_type_cast(object)), options.merge(:class => 'wysihat_editor'))
      end
    end

    class FormBuilder #:nodoc:
      def wysihat_editor(method, options = {})
        @template.wysihat_editor(@object_name, method, options)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wysihat-engine-0.1.13 lib/wysihat-engine.rb
wysihat-engine-0.1.12 lib/wysihat-engine.rb
wysihat-engine-0.1.11 lib/wysihat-engine.rb