Class: ActionView::Helpers::InstanceTag

Inherits:
Object
  • Object
show all
Defined in:
lib/wysihat-engine.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#to_wysihat_editor_tag(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wysihat-engine.rb', line 12

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, :justify_left, :justify_center, :justify_right, :insert_ordered_list, :insert_unordered_list, :undo, :redo, :link, :html, :image, :file]
  end
  
  javascript = "Event.observe(window, 'load', function() {" <<
  "wysiHatify('#{tag_id}', ['#{buttons.join('\', \'')}']);" <<
  "});"
  
  (:script, javascript, :type => 'text/javascript') <<
  (:textarea, html_escape(options.delete('value') || value_before_type_cast(object)), options.merge(:class => 'wysihat_editor'))
end