class CKEditor5::Rails::Presets::PresetBuilder
def apply_integration_patches
-
(void)
-
def apply_integration_patches patch_plugin Plugins::Patches::FixColorPickerRaceCondition.new end
def automatic_upgrades(enabled: true)
- Example: Enable automatic upgrades -
Parameters:
-
enabled
(Boolean
) -- Enable/disable upgrades
def automatic_upgrades(enabled: true) @automatic_upgrades = enabled end
def automatic_upgrades?
-
(Boolean)
-
def automatic_upgrades? @automatic_upgrades end
def balloon_toolbar(*items, **kwargs, &block)
- Example: Configure with block -
Example: Configure balloon toolbar items -
Returns:
-
(ToolbarBuilder)
- Toolbar configuration
Other tags:
- Yield: - Optional block for additional toolbar configuration
Options Hash:
(**kwargs)
-
:should_group_when_full
(Boolean
) -- Enable/disable toolbar item grouping
Parameters:
-
kwargs
(Hash
) -- Additional toolbar configuration options -
items
(Array
) -- Toolbar items to include
def balloon_toolbar(*items, **kwargs, &block) toolbar(*items, **kwargs, type: :balloonToolbar, &block) end
def block_toolbar(*items, **kwargs, &block)
- Example: Configure with block -
Example: Configure block toolbar items -
Returns:
-
(ToolbarBuilder)
- Toolbar configuration
Other tags:
- Yield: - Optional block for additional toolbar configuration
Options Hash:
(**kwargs)
-
:should_group_when_full
(Boolean
) -- Enable/disable toolbar item grouping
Parameters:
-
kwargs
(Hash
) -- Additional toolbar configuration options -
items
(Array
) -- Toolbar items to include
def block_toolbar(*items, **kwargs, &block) toolbar(*items, **kwargs, type: :blockToolbar, &block) end
def cdn(cdn = nil, &block)
-
(Symbol, Proc)
- Current CDN configuration
Other tags:
- Example: Custom CDN configuration -
Example: Use jsDelivr CDN -
Parameters:
-
cdn
(Symbol, nil
) -- CDN name or custom block
def cdn(cdn = nil, &block) return @cdn if cdn.nil? && block.nil? if block_given? unless block.arity == 3 raise ArgumentError, 'Block must accept exactly 3 arguments: bundle, version, path' end @cdn = block else @cdn = cdn end end
def ckbox(version = nil, theme: :lark)
- Example: Enable CKBox with custom version -
Parameters:
-
theme
(Symbol
) -- Theme name (:lark) -
version
(String, nil
) -- CKBox version
def ckbox(version = nil, theme: :lark) return @ckbox if version.nil? @ckbox = { version: version, theme: theme } end
def deconstruct_keys(keys)
def deconstruct_keys(keys) keys.index_with do |key| public_send(key) end end
def deep_copy_toolbar(toolbar)
def deep_copy_toolbar(toolbar) return toolbar.dup if toolbar.is_a?(Array) return {} if toolbar.nil? { items: toolbar[:items].dup, shouldNotGroupWhenFull: toolbar[:shouldNotGroupWhenFull] } end
def editable_height(height = nil)
-
(Integer, nil)
- Current height value
Other tags:
- Example: Set editor height to 300px -
Parameters:
-
height
(Integer, nil
) -- Height in pixels
def editable_height(height = nil) return @editable_height if height.nil? @editable_height = height end
def gpl
- Example: Enable GPL license -
def gpl license_key('GPL') premium(false) end
def gpl?
-
(Boolean)
-
def gpl? license_key == 'GPL' end
def initialize(&block)
- Example: Basic initialization -
def initialize(&block) @version = nil @premium = false @cdn = :jsdelivr @translations = [:en] @license_key = nil @type = :classic @ckbox = nil @editable_height = nil @automatic_upgrades = false @config = { plugins: [], toolbar: [] } instance_eval(&block) if block_given? end
def initialize_copy(source)
- Example: Copy preset and modify it -
def initialize_copy(source) super @translations = source.translations.dup @ckbox = source.ckbox.dup if source.ckbox @config = { plugins: source.config[:plugins].map(&:dup), toolbar: deep_copy_toolbar(source.config[:toolbar]) }.merge( source.config.except(:plugins, :toolbar).deep_dup ) end
def language(ui = nil, content: ui) # rubocop:disable Naming/MethodParameterName
-
(Hash, nil)
- Language configuration
Other tags:
- Example: Different UI and content languages -
Example: Set Polish UI and content language -
Parameters:
-
content
(Symbol
) -- Content language code -
ui
(Symbol, nil
) -- UI language code
def language(ui = nil, content: ui) # rubocop:disable Naming/MethodParameterName return config[:language] if ui.nil? # Normalize language codes, as the translation packs used to be in lowercase ui = ui.to_sym.downcase content = content.to_sym.downcase @translations << ui unless @translations.map(&:to_sym).include?(ui) config[:language] = { ui: ui, content: content } end
def language?
-
(Boolean)
-
def language? config[:language].present? end
def license_key(license_key = nil)
-
(String, nil)
- Current license key
Other tags:
- Example: Set commercial license -
Parameters:
-
license_key
(String, nil
) -- License key
def license_key(license_key = nil) return @license_key if license_key.nil? @license_key = license_key cdn(:cloud) unless gpl? end
def menubar(visible: true)
- Example: Hide menubar -
Parameters:
-
visible
(Boolean
) -- Show/hide menubar
def menubar(visible: true) config[:menuBar] = { isVisible: visible } end
def menubar?
-
(Boolean)
-
def menubar? config.dig(:menuBar, :isVisible) || false end
def merge_with_hash!(**overrides)
-
(self)
-
Parameters:
-
overrides
(Hash
) -- Configuration options to merge
def merge_with_hash!(**overrides) @version = Semver.new(overrides[:version]) if overrides.key?(:version) @premium = overrides.fetch(:premium, premium) @cdn = overrides.fetch(:cdn, cdn) @translations = overrides.fetch(:translations, translations) @license_key = overrides.fetch(:license_key, license_key) @type = overrides.fetch(:type, type) @editable_height = overrides.fetch(:editable_height, editable_height) @automatic_upgrades = overrides.fetch(:automatic_upgrades, automatic_upgrades) @ckbox = overrides.fetch(:ckbox, ckbox) if overrides.key?(:ckbox) || ckbox @config = config.merge(overrides.fetch(:config, {})) self end
def override(&block)
-
(PresetBuilder)
- New preset instance
Other tags:
- Example: Override existing preset -
def override(&block) clone.tap do |preset| preset.instance_eval(&block) end end
def premium(premium = nil)
-
(Boolean)
- Premium status
Other tags:
- Example: Enable premium features -
Parameters:
-
premium
(Boolean, nil
) -- Enable/disable premium features
def premium(premium = nil) return @premium if premium.nil? @premium = premium end
def premium?
-
(Boolean)
-
def premium? @premium end
def simple_upload_adapter(upload_url = '/uploads')
- Example: Enable upload adapter -
Parameters:
-
upload_url
(String
) -- Upload endpoint URL
def simple_upload_adapter(upload_url = '/uploads') plugins do remove(:Base64UploadAdapter) end plugin(Plugins::SimpleUploadAdapter.new) configure(:simpleUpload, { uploadUrl: upload_url }) end
def special_characters(&block)
- Example: Mixed configuration -
Example: Configuration with direct items array -
Example: Basic configuration with block -
Other tags:
- Yield: - Block for configuring special characters
def special_characters(&block) builder = SpecialCharactersBuilder.new builder.instance_eval(&block) if block_given? plugins do append(:SpecialCharacters) builder.packs_plugins.each { |pack| append(pack) } prepend(Plugins::SpecialCharactersBootstrap.new) end configure(:specialCharactersBootstrap, builder.to_h) end
def toolbar(*items, should_group_when_full: true, type: :toolbar, &block)
-
(ToolbarBuilder)
- Toolbar configuration
Other tags:
- Example: Configure with block -
Example: Configure toolbar items -
Parameters:
-
should_group_when_full
(Boolean
) -- Enable grouping -
items
(Array
) -- Toolbar items
def toolbar(*items, should_group_when_full: true, type: :toolbar, &block) if @config[type].blank? || !items.empty? @config[type] = { items: items, shouldNotGroupWhenFull: !should_group_when_full } end builder = ToolbarBuilder.new(@config[type][:items]) builder.instance_eval(&block) if block_given? builder end
def translations(*translations)
-
(Array
- Current translations)
Other tags:
- Example: Add Polish and Spanish translations -
Parameters:
-
translations
(Array
) -- Language codes
def translations(*translations) return @translations if translations.empty? @translations = translations.map { |t| t.to_sym.downcase } end
def type(type = nil)
-
(Symbol)
- Current editor type
Raises:
-
(ArgumentError)
- If invalid type provided
Other tags:
- Example: Set editor type to inline -
Parameters:
-
type
(Symbol, nil
) -- Editor type (:classic, :inline, :balloon, :decoupled)
def type(type = nil) return @type if type.nil? raise ArgumentError, "Invalid editor type: #{type}" unless Editor::Props.valid_editor_type?(type) @type = type end
def version(version = nil, apply_patches: true)
-
(String, nil)
- Current version string or nil if not set
Other tags:
- Example: Get current version -
Example: Set version without applying patches -
Example: Set specific version -
Parameters:
-
apply_patches
(Boolean
) -- Whether to apply integration patches after setting version -
version
(String, nil
) -- Editor version to set
def version(version = nil, apply_patches: true) return @version&.to_s if version.nil? if @automatic_upgrades && version detected = VersionDetector.latest_safe_version(version) @version = Semver.new(detected || version) else @version = Semver.new(version) end # If there is no license key set, and the version if newer than 44.0.0, switch to GPL # as the license key is now required in all versions gpl if license_key.nil? && @version.major >= 44 apply_integration_patches if apply_patches end
def wproofreader(version: nil, cdn: nil, **config)
- Example: Basic configuration -
Parameters:
-
config
(Hash
) -- Plugin configuration -
cdn
(String, nil
) -- CDN URL -
version
(String, nil
) -- Plugin version
def wproofreader(version: nil, cdn: nil, **config) configure :wproofreader, config plugins do prepend(Plugins::WProofreaderSync.new) append(Plugins::WProofreader.new(version: version, cdn: cdn)) end end