Module: WangeditorRails::Helper
- Defined in:
- lib/wangeditor_rails/helper.rb
Instance Method Summary collapse
- #create_scripts(id) ⇒ Object
- #display_area(id, content) ⇒ Object
- #hidden_area(id, content, name) ⇒ Object
- #wangeditor(name, method, options = {}) ⇒ Object
Instance Method Details
#create_scripts(id) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/wangeditor_rails/helper.rb', line 26 def create_scripts(id) "var E = window.wangEditor var editor = new E('##{id}_editor') editor.customConfig.onchange = function (content) { document.getElementById('#{id}').value = content } editor.create()" end |
#display_area(id, content) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/wangeditor_rails/helper.rb', line 19 def display_area(id, content) unless content.nil? content = sanitize content end content_tag(:div, content, id: "#{id}_editor") end |
#hidden_area(id, content, name) ⇒ Object
15 16 17 |
# File 'lib/wangeditor_rails/helper.rb', line 15 def hidden_area(id, content, name) content_tag :div, text_area_tag(id, content, name: name), style: 'display: none;' end |
#wangeditor(name, method, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/wangeditor_rails/helper.rb', line 3 def wangeditor(name, method, = {}) content = [:object][method] id = [:id] || "#{name}_#{method}" name = "#{name}[#{method}]" #puts options output_buffer = ActiveSupport::SafeBuffer.new output_buffer << hidden_area(id, content, name) output_buffer << display_area(id, content) output_buffer << javascript_tag(create_scripts(id)) end |