Class: CKEditor5::Rails::Context::PresetBuilder

Inherits:
Object
  • Object
show all
Includes:
Presets::Concerns::ConfigurationMethods, Presets::Concerns::PluginMethods
Defined in:
lib/ckeditor5/rails/context/preset_builder.rb

Overview

PresetBuilder provides functionality for building CKEditor 5 presets.

This class includes configuration and plugin handling methods from concerns and allows defining presets either through initialization blocks or method chaining.

Examples:

Basic preset definition

preset = PresetBuilder.new do
  version '43.3.1'
  gpl
  type :classic
  toolbar :bold, :italic
end

Cloning and modifying a preset

new_preset = preset.clone
new_preset.toolbar do
  append :underline
end

See Also:

Instance Method Summary collapse

Methods included from Presets::Concerns::PluginMethods

#external_plugin, #inline_plugin, #plugin, #plugins

Methods included from Presets::Concerns::ConfigurationMethods

#configure

Constructor Details

#initialize(&block) ⇒ PresetBuilder

Initializes a new preset builder with optional configuration block

Examples:

Initialize with block

PresetBuilder.new do
  version '43.3.1'
  toolbar :bold, :italic
end

Parameters:

  • block (Proc)

    Optional configuration block



41
42
43
44
45
46
47
48
# File 'lib/ckeditor5/rails/context/preset_builder.rb', line 41

def initialize(&block)
  @disallow_inline_plugin_compression = true
  @config = {
    plugins: []
  }

  instance_eval(&block) if block_given?
end

Instance Method Details

#initialize_copy(source) ⇒ PresetBuilder

Creates a deep copy of the preset builder

Parameters:

Returns:

  • (PresetBuilder)

    New preset instance with copied configuration



54
55
56
57
58
59
60
61
62
# File 'lib/ckeditor5/rails/context/preset_builder.rb', line 54

def initialize_copy(source)
  super

  @config = {
    plugins: source.config[:plugins].map(&:dup)
  }.merge(
    source.config.except(:plugins).deep_dup
  )
end