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



12
13
14
15
# File 'lib/ckeditor5/rails/presets/manager.rb', line 12

def initialize
  @presets = {}
  define_default_preset
end

Instance Attribute Details

#presetsObject (readonly)

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:



69
70
71
# File 'lib/ckeditor5/rails/presets/manager.rb', line 69

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

#defaultPresetBuilder?

Get the default preset configuration

Returns:



62
63
64
# File 'lib/ckeditor5/rails/presets/manager.rb', line 62

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:



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

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



54
55
56
# File 'lib/ckeditor5/rails/presets/manager.rb', line 54

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