Module: RedCloth::Rails::Helpers::FormHelper
- Defined in:
- lib/redcloth-rails/helpers/form_helper.rb
Instance Method Summary collapse
-
#textile_editor(object_name, method, options = {}) ⇒ Object
Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by
method
) on an object assigned to the template (identified byobject
). -
#textile_editor_button(text, options = {}) ⇒ Object
Registers a further button on the TextileEditor toolbar.
-
#textile_editor_button_separator(options = {}) ⇒ Object
Registers a separator on the TextileEditor toolbar.
-
#textile_editor_initialize(*dom_ids) ⇒ Object
Initialize the TextileEditor.
- #textile_extract_dom_ids(*dom_ids) ⇒ Object
Instance Method Details
#textile_editor(object_name, method, options = {}) ⇒ Object
Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by method
) on an object assigned to the template (identified by object
). Additional options on the input tag can be passed as a hash with options
and places the textile toolbar above it
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/redcloth-rails/helpers/form_helper.rb', line 35 def textile_editor(object_name, method, = {}) editor_id = [:id] || '%s_%s' % [object_name, method] mode = .delete(:simple) ? 'simple' : 'extended' (@textile_editor_ids ||= []) << [editor_id.to_s, mode.to_s] if ActionPack::VERSION::MAJOR > 3 ActionView::Helpers::Tags::TextArea.new(object_name, method, self, ).render else ActionView::Helpers::InstanceTag.new(object_name, method, self, .delete(:object)).to_text_area_tag() end end |
#textile_editor_button(text, options = {}) ⇒ Object
Registers a further button on the TextileEditor toolbar. Must be called before the TextileEditor gets initialized.
58 59 60 61 62 63 64 |
# File 'lib/redcloth-rails/helpers/form_helper.rb', line 58 def (text, ={}) return if text == :separator = content_tag(:button, text, ) = "TextileEditor.addButton(\"%s\");" % escape_javascript() (@textile_editor_buttons ||= []) << return nil end |
#textile_editor_button_separator(options = {}) ⇒ Object
Registers a separator on the TextileEditor toolbar. Must be called before the TextileEditor gets initialized.
71 72 73 74 75 |
# File 'lib/redcloth-rails/helpers/form_helper.rb', line 71 def (={}) = "TextileEditor.addButton(new TextileEditorButtonSeparator('%s'));" % ([:simple] || '') (@textile_editor_buttons ||= []) << return nil end |
#textile_editor_initialize(*dom_ids) ⇒ Object
Initialize the TextileEditor. after the DOM was loaded.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/redcloth-rails/helpers/form_helper.rb', line 96 def textile_editor_initialize(*dom_ids) = {} # extract options from last argument if it's a hash if dom_ids.last.is_a?(Hash) hash = dom_ids.last.dup .merge! hash end editor_ids = (@textile_editor_ids || []) + textile_extract_dom_ids(*dom_ids) = (@textile_editor_buttons || []) output = [] output << '<script type="text/javascript">' output << '/* <![CDATA[ */' unless request.xhr? output << %{jQuery(document).ready(function($) \{} end output << .join("\n") if .any? editor_ids.each do |editor_id, mode| output << %q{new TextileEditor('%s', '%s');} % [editor_id, mode || 'extended'] end unless request.xhr? output << '});' end output << '/* ]]> */' output << '</script>' output.join("\n").html_safe end |
#textile_extract_dom_ids(*dom_ids) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/redcloth-rails/helpers/form_helper.rb', line 131 def textile_extract_dom_ids(*dom_ids) hash = dom_ids.last.is_a?(Hash) ? dom_ids.pop : {} hash.inject(dom_ids) do |ids, (object, fields)| ids + Array(fields).map { |field| "%s_%s" % [object, field] } end end |