Sha256: 64269e58950cd675bb13091eae81e7e681760ac521a5e3f4e85036328c39f74e

Contents?: true

Size: 1.51 KB

Versions: 75

Compression:

Stored size: 1.51 KB

Contents

module Effective
  module FormInputs
    class Editor < Effective::FormInput

      def build_input(&block)
        content = value.presence || (capture(&block) if block_given?)

        @builder.super_text_area(name, (options[:input] || {}).merge(autocomplete: 'off')) +
        content_tag(:div, '', class: 'ql-effective', id: unique_id + '_editor')
      end

      def input_html_options
        { class: 'effective_editor form-control', id: unique_id }
      end

      def input_js_options
        {
          modules: { toolbar: toolbar, syntax: (content_mode == :code) },
          theme: 'snow',
          placeholder: "Add #{name.to_s.pluralize}...",
          content_mode: content_mode
        }
      end

      # Commented out 'Full' toolbar options because currently we don't want headers / source / code options
      def toolbar
        return false if content_mode == :code

        [
          # [{'header': [1, 2, 3, 4, false] }],
          ['bold', 'italic', 'underline'],
          ['link', 'image', 'video'], # also 'code-block'
          [{'list': 'ordered'}, {'list': 'bullet'}, 'blockquote'],
          [{'align': [] }, 'clean']
        ]
      end

      def content_mode # default false
        return @content_mode unless @content_mode.nil?

        @content_mode = (
          if options.delete(:delta)
            :delta
          elsif options.delete(:html)
            :html
          elsif options.delete(:code)
            :code
          else
            :delta
          end
        )
      end

    end
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
effective_bootstrap-0.5.12 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.11 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.10 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.9 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.8 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.7 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.6 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.5 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.4 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.3 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.2 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.1 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.5.0 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.4.8 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.4.7 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.4.6 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.4.5 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.4.4 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.4.3 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.4.2 app/models/effective/form_inputs/editor.rb