Module: CKEditor5::Rails::Context::Helpers

Included in:
Helpers
Defined in:
lib/ckeditor5/rails/context/helpers.rb

Instance Method Summary collapse

Instance Method Details

#ckeditor5_context(preset = nil) { ... } ⇒ Object

Creates a CKEditor context component that can be shared between multiple editors. This allows you to define common plugins that will be available to all editors within the context.

Examples:

Basic usage with shared plugins

<% preset = ckeditor5_context_preset do
  plugins :Mention, :Emoji  # These plugins will be shared across all editors
end %>

<%= ckeditor5_context(preset) do %>
  <%= ckeditor5_editor preset: :content %>
  <%= ckeditor5_editor preset: :description %>
<% end %>

Parameters:

  • preset (PresetBuilder) (defaults to: nil)

    The preset object containing shared plugins configuration

Yields:

  • The block where editor instances should be defined



24
25
26
27
28
29
# File 'lib/ckeditor5/rails/context/helpers.rb', line 24

def ckeditor5_context(preset = nil, &block)
  preset ||= PresetBuilder.new
  context_props = PresetSerializer.new(preset)

  tag.public_send(:'ckeditor-context-component', **context_props.to_attributes, &block)
end

#ckeditor5_context_preset { ... } ⇒ PresetBuilder

Creates a new preset builder object for use with ckeditor5_context. Used to define shared plugins that will be available to all editors within the context. Note: Only plugins configuration is relevant for context, other settings like toolbar should be configured at the editor level.

Examples:

Creating a context with shared plugins

<% preset = ckeditor5_context_preset do
  plugins :Comments, :TrackChanges, :Collaboration  # Shared functionality plugins
end %>

Yields:

  • Block for configuring the shared plugins

Returns:



43
44
45
# File 'lib/ckeditor5/rails/context/helpers.rb', line 43

def ckeditor5_context_preset(&block)
  PresetBuilder.new(&block)
end