module CKEditor5::Rails::Editor::Helpers::Editor

def build_editor_config(preset, config, extra_config, initial_data)

Returns:
  • (Hash) - The merged configuration hash

Parameters:
  • initial_data (String) -- Initial content for the editor
  • extra_config (Hash) -- Additional configuration to merge
  • config (Hash) -- Custom configuration that overrides preset config
  • preset (PresetBuilder) -- The preset configuration object
def build_editor_config(preset, config, extra_config, initial_data)
  editor_config = config || preset.config
  editor_config = editor_config.deep_merge(extra_config)
  editor_config[:initialData] = initial_data if initial_data
  if preset.automatic_upgrades? && editor_config[:version].present?
    detected_version = VersionDetector.latest_safe_version(editor_config[:version])
    editor_config[:version] = detected_version if detected_version
  end
  editor_config
end

def ckeditor5_context_or_fallback(preset)

Returns:
  • (Hash) - Context hash containing bundle and preset information

Parameters:
  • preset (Symbol, PresetBuilder) -- The preset name or object
def ckeditor5_context_or_fallback(preset)
  return @__ckeditor_context if @__ckeditor_context.present?
  if preset.present?
    found_preset = Engine.find_preset(preset)
    return {
      bundle: create_preset_bundle(found_preset),
      preset: found_preset
    }
  end
  {
    bundle: nil,
    preset: Engine.default_preset
  }
end

def ckeditor5_editable(name = nil, **kwargs, &block)

Other tags:
    Example: Creating a named editable area in multiroot editor -

Parameters:
  • kwargs (Hash) -- HTML attributes for the editable element
  • name (String) -- Identifier for the editable area
def ckeditor5_editable(name = nil, **kwargs, &block)
  tag.public_send(:'ckeditor-editable-component', name: name, **kwargs, &block)
end

def ckeditor5_editor( # rubocop:disable Metrics/ParameterLists

Other tags:
    Example: Form integration -
    Example: Editor with event handlers -
    Example: Decoupled editor with custom UI layout -
    Example: Multiroot editor with multiple editable areas -
    Example: Inline editor with custom styling -
    Example: Custom preset with specific height and initial content -
    Example: Basic usage with default preset -

Parameters:
  • html_attributes (Hash) -- Additional HTML attributes for editor element
  • language (Symbol) -- Set editor UI language (e.g. :pl, :es)
  • editable_height (Integer) -- Set fixed height for editor in pixels
  • watchdog (Boolean) -- Enable/disable the editor crash recovery (default: true)
  • initial_data (String) -- Initial HTML content for the editor
  • type (Symbol) -- Editor type (:classic, :inline, :balloon, :decoupled, :multiroot)
  • extra_config (Hash) -- Additional configuration to merge with preset/custom config
  • config (Hash) -- Custom editor configuration that overrides preset configuration
  • preset (Symbol, PresetBuilder) -- The name of the preset or a PresetBuilder object
def ckeditor5_editor( # rubocop:disable Metrics/ParameterLists
  preset: nil,
  config: nil, extra_config: {}, type: nil,
  initial_data: nil, watchdog: true,
  editable_height: nil, language: nil,
  **html_attributes, &block
)
  validate_editor_input!(initial_data, block)
  context = ckeditor5_context_or_fallback(preset)
  preset = Engine.find_preset!(preset || context[:preset] || :default)
  config = build_editor_config(preset, config, extra_config, initial_data)
  type ||= preset.type
  # Add some fallbacks
  config[:licenseKey] ||= context[:license_key]
  config[:language] = { ui: language } if language
  editor_props = Editor::Props.new(
    type, config,
    bundle: context[:bundle],
    watchdog: watchdog,
    editable_height: editable_height || preset.editable_height
  )
  tag_attributes = html_attributes.merge(editor_props.to_attributes)
  tag.public_send(:'ckeditor-component', **tag_attributes, &block)
end

def ckeditor5_menubar(**kwargs)

Other tags:
    Example: Creating a menubar with custom styling -

Parameters:
  • kwargs (Hash) -- HTML attributes for the menubar element
def ckeditor5_menubar(**kwargs)
  ckeditor5_ui_part('menuBarView', **kwargs)
end

def ckeditor5_toolbar(**kwargs)

Other tags:
    Example: Creating a toolbar with custom class -

Parameters:
  • kwargs (Hash) -- HTML attributes for the toolbar element
def ckeditor5_toolbar(**kwargs)
  ckeditor5_ui_part('toolbar', **kwargs)
end

def ckeditor5_ui_part(name, **kwargs, &block)

Other tags:
    Example: Creating a toolbar component -

Parameters:
  • kwargs (Hash) -- HTML attributes for the UI component
  • name (String) -- Name of the UI component ('toolbar', 'menuBarView')
def ckeditor5_ui_part(name, **kwargs, &block)
  tag.public_send(:'ckeditor-ui-part-component', name: name, **kwargs, &block)
end

def validate_editor_input!(initial_data, block)

Raises:
  • (ArgumentError) - If both initial_data and block are provided

Parameters:
  • block (Proc) -- Block containing nested components
  • initial_data (String) -- Initial content for the editor
def validate_editor_input!(initial_data, block)
  return unless initial_data && block
  raise ArgumentError, 'Cannot pass initial data and block at the same time.'
end