Class: CKEditor5::Rails::Presets::SpecialCharactersBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ckeditor5/rails/presets/special_characters_builder.rb

Overview

Builder class for configuring special characters in CKEditor5

Examples:

Basic configuration

special_characters do
  group 'Emoji', label: 'Emoticons' do
    item 'smiley', '😊'
  end

  order :Text, :Mathematical, :Emoji
end

Defined Under Namespace

Classes: Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpecialCharactersBuilder

Initialize a new special characters builder

Examples:

Create new builder

SpecialCharactersBuilder.new


85
86
87
88
89
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 85

def initialize
  @groups = []
  @order = []
  @packs_plugins = []
end

Instance Attribute Details

#packs_pluginsObject (readonly)

Returns the value of attribute packs_plugins.



15
16
17
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 15

def packs_plugins
  @packs_plugins
end

Instance Method Details

#group(name, items: [], label: nil) { ... } ⇒ Group

Define a new special characters group

Examples:

Define group with items array

group 'Emoji',
      items: [
        { title: 'smiley', character: '😊' },
        { title: 'heart', character: '❤️' }
      ],
      label: 'Emoticons'

Define group with block

group 'Emoji', label: 'Emoticons' do
  item 'smiley', '😊'
  item 'heart', '❤️'
end

Parameters:

  • name (String)

    Name of the group

  • items (Array<Hash>) (defaults to: [])

    Optional array of character items

  • label (String, nil) (defaults to: nil)

    Optional display label

Yields:

  • Group configuration block

Returns:

  • (Group)

    Created group instance



110
111
112
113
114
115
116
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 110

def group(name, items: [], label: nil, &block)
  group = Group.new(name, label: label)
  group.add_characters(items) if items.any?
  group.instance_eval(&block) if block_given?
  @groups << group
  group
end

#order(*categories) ⇒ Object

Set the display order of character groups

Examples:

Set display order

order :Text, :Mathematical, 'Currency', :Emoji

Parameters:

  • categories (Array<Symbol, String>)

    Category names in desired order



135
136
137
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 135

def order(*categories)
  @order = categories.map(&:to_s)
end

#packs(*names) ⇒ Object

Enable special characters packs

Examples:

Enable essential and extended characters

packs :Text, :Currency, :Mathematical

Parameters:

  • names (Array<Symbol, String>)

    Pack names to enable



123
124
125
126
127
128
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 123

def packs(*names)
  names.each do |name|
    plugin_name = "SpecialCharacters#{name.to_s.capitalize}"
    @packs_plugins << plugin_name
  end
end

#to_hHash

Convert builder configuration to hash

Returns:

  • (Hash)

    Complete special characters configuration



142
143
144
145
146
147
148
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 142

def to_h
  {
    groups: @groups.map(&:to_h),
    order: @order,
    packs: @packs_plugins
  }
end