Sha256: ec0210518077265896ad3a29c265f4f019634ebd992dc19f3c4b6f6f5eb66fc6
Contents?: true
Size: 1.7 KB
Versions: 3
Compression:
Stored size: 1.7 KB
Contents
module Rich module ViewHelper include ActionView::Helpers def rich_textarea(object, field, options = {}) options = options.dup.symbolize_keys var = options.delete(:object) if options.key?(:object) var ||= @template.instance_variable_get("@#{object}") value = var.send(field.to_sym) if var value ||= options.delete(:value) || "" element_id = options.delete(:id) || editor_element_id(object, field, options.delete(:index)) width = options.delete(:width) || '76%' height = options.delete(:height) || '200px' textarea_options = { :id => element_id } textarea_options[:cols] = (options.delete(:cols) || 70).to_i textarea_options[:rows] = (options.delete(:rows) || 20).to_i textarea_options[:class] = (options.delete(:class) || 'editor').to_s textarea_options[:style] = "width:#{width};height:#{height}" # merge options with Rich.ckeditor editor_options = Rich.editor.merge(options[:editor] || {}) editor_options[:width] = width; editor_options[:height] = height; output_buffer = ActiveSupport::SafeBuffer.new output_buffer << ActionView::Base::InstanceTag.new(object, field, self, var).to_text_area_tag(textarea_options.merge(options)) # lookin' like wealth. output_buffer << javascript_tag("$(function(){$('##{element_id}').ckeditor(function() { }, #{editor_options.to_json} );});") output_buffer end protected # construct a unique ID def editor_element_id(object, field, index = nil) index.blank? ? "#{object}_#{field}_editor" : "#{object}_#{index}_#{field}_editor" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rich-0.0.3 | lib/rich/view_helper.rb |
rich-0.0.2 | lib/rich/view_helper.rb |
rich-0.0.1 | lib/rich/view_helper.rb |