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.6.31 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.30 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.29 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.28 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.27 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.26 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.25 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.24 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.23 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.22 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.21 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.20 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.19 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.18 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.17 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.16 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.15 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.14 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.13 app/models/effective/form_inputs/editor.rb
effective_bootstrap-0.6.12 app/models/effective/form_inputs/editor.rb