Sha256: f9a8f0aac7dc484dc2a7683de4d3a31eaf9960e5b77b1425e209ffc3f86351d8

Contents?: true

Size: 1.85 KB

Versions: 4

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require_relative 'preset_builder'
require_relative 'toolbar_builder'

module CKEditor5::Rails::Presets
  class Manager
    attr_reader :presets

    def initialize
      @presets = {}
      define_default_preset
    end

    def define(name, &block)
      preset = PresetBuilder.new
      preset.instance_eval(&block)
      @presets[name] = preset
    end

    def override(name, &block)
      @presets[name].instance_eval(&block)
    end

    def default
      @presets[:default] || {}
    end

    def [](name)
      @presets[name] || {}
    end

    private

    def define_default_preset # rubocop:disable Metrics/MethodLength
      define :default do
        gpl
        type :classic
        menubar

        toolbar :undo, :redo, :|, :heading, :|, :bold, :italic, :underline, :|,
                :link, :insertImage, :mediaEmbed, :insertTable, :blockQuote, :|,
                :bulletedList, :numberedList, :todoList, :outdent, :indent

        plugins :AccessibilityHelp, :Autoformat, :AutoImage, :Autosave,
                :BlockQuote, :Bold, :CloudServices,
                :Essentials, :Heading, :ImageBlock, :ImageCaption, :ImageInline,
                :ImageInsert, :ImageInsertViaUrl, :ImageResize, :ImageStyle,
                :ImageTextAlternative, :ImageToolbar, :ImageUpload, :Indent,
                :IndentBlock, :Italic, :Link, :LinkImage, :List, :ListProperties,
                :MediaEmbed, :Paragraph, :PasteFromOffice, :PictureEditing,
                :SelectAll, :Table, :TableCaption, :TableCellProperties,
                :TableColumnResize, :TableProperties, :TableToolbar,
                :TextTransformation, :TodoList, :Underline, :Undo, :Base64UploadAdapter

        configure :image, {
          toolbar: ['imageTextAlternative', 'imageStyle:inline', 'imageStyle:block', 'imageStyle:side']
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ckeditor5-1.4.0 lib/ckeditor5/rails/presets/manager.rb
ckeditor5-1.3.0 lib/ckeditor5/rails/presets/manager.rb
ckeditor5-1.2.0 lib/ckeditor5/rails/presets/manager.rb
ckeditor5-1.1.7 lib/ckeditor5/rails/presets/manager.rb