Sha256: 62c7ca196f3630f5d1d72119050c0a72329db2e6e9947db5cdf2d47250dca088
Contents?: true
Size: 1.53 KB
Versions: 6
Compression:
Stored size: 1.53 KB
Contents
module TrixEditorHelper cattr_accessor(:id, instance_accessor: false) { 0 } def trix_editor_tag(name, value = nil, options = {}) options.symbolize_keys! attributes = { class: "formatted_content #{options[:class]}".squish } attributes[:autofocus] = true if options[:autofocus] attributes[:placeholder] = options[:placeholder] if options[:placeholder] attributes[:input] = options[:input] || "trix_input_#{TrixEditorHelper.id += 1}" attributes[:toolbar] = options[:toolbar] if options[:toolbar] editor_tag = content_tag('trix-editor', '', attributes) input_tag = hidden_field_tag(name, value, id: attributes[:input]) editor_tag + input_tag end end module ActionView module Helpers include TrixEditorHelper module Tags class TrixEditor < Base include TrixEditorHelper delegate :dom_id, to: ActionView::RecordIdentifier def render options = @options.stringify_keys add_default_name_and_id(options) options['input'] ||= dom_id(object, [options['id'], :trix_input].compact.join('_')) trix_editor_tag(options.delete('name'), value_before_type_cast(object), options) end end end module FormHelper def trix_editor(object_name, method, options = {}) Tags::TrixEditor.new(object_name, method, self, options).render end end class FormBuilder def trix_editor(method, options = {}) @template.trix_editor(@object_name, method, objectify_options(options)) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
trix-0.9.5 | lib/trix/form.rb |
trix-0.9.4 | lib/trix/form.rb |
trix-0.9.3 | lib/trix/form.rb |
trix-0.9.2 | lib/trix/form.rb |
trix-0.9.1 | lib/trix/form.rb |
trix-0.9.0 | lib/trix/form.rb |