Class: CKEditor5::Rails::Presets::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/ckeditor5/rails/presets/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Initializes a new Manager instance and sets up the default preset



14
15
16
17
# File 'lib/ckeditor5/rails/presets/manager.rb', line 14

def initialize
  @presets = {}
  define_default_preset
end

Instance Attribute Details

#presetsObject (readonly) Also known as: to_h

Returns the value of attribute presets.



9
10
11
# File 'lib/ckeditor5/rails/presets/manager.rb', line 9

def presets
  @presets
end

Instance Method Details

#[](name) ⇒ PresetBuilder?

Get a preset by name

Parameters:

  • name (Symbol)

    Name of the preset

Returns:



71
72
73
# File 'lib/ckeditor5/rails/presets/manager.rb', line 71

def [](name)
  @presets[name]
end

#defaultPresetBuilder?

Get the default preset configuration

Returns:



64
65
66
# File 'lib/ckeditor5/rails/presets/manager.rb', line 64

def default
  @presets[:default]
end

#define(name, inherit: true, &block) ⇒ PresetBuilder

Define a new preset configuration

Examples:

Define custom preset inheriting from default

presets.define :custom do
  menubar visible: false
  toolbar :bold, :italic
end

Define preset from scratch

presets.define :blank, inherit: false do
  version '43.3.1'
  gpl
  type :classic
end

Parameters:

  • name (Symbol)

    Name of the preset

  • inherit (Boolean) (defaults to: true)

    Whether to inherit from default preset

Returns:



35
36
37
38
39
40
41
42
43
44
# File 'lib/ckeditor5/rails/presets/manager.rb', line 35

def define(name, inherit: true, &block)
  preset = if inherit && default.present?
             default.clone
           else
             PresetBuilder.new
           end

  preset.instance_eval(&block)
  @presets[name] = preset
end

#override(name, &block) ⇒ Object Also known as: extend

Override existing preset configuration

Examples:

Override existing preset

presets.override :custom do
  menubar visible: false
  toolbar do
    remove :underline, :heading
  end
end

Parameters:

  • name (Symbol)

    Name of the preset to override



56
57
58
# File 'lib/ckeditor5/rails/presets/manager.rb', line 56

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