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

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

Overview

Builder class for configuring special characters groups

Examples:

Basic group configuration

group = Group.new('Emoji', label: 'Emoticons')
group.item('smiley', '😊')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, label: nil) ⇒ Group

Initialize a new special characters group

Parameters:

  • name (String)

    Name of the group

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

    Optional display label for the group



30
31
32
33
34
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 30

def initialize(name, label: nil)
  @name = name
  @label = label
  @items = []
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



23
24
25
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 23

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 23

def name
  @name
end

Instance Method Details

#add_characters(items) ⇒ Object

Add multiple characters to the group

Parameters:

  • items (Array<Hash>)

    Array of character definitions



63
64
65
66
67
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 63

def add_characters(items)
  items.each do |item|
    @items << item.slice(:title, :character)
  end
end

#add_items(collection) ⇒ Object

Add multiple characters to the group at once

Examples:

Add multiple items

add_items [
  { title: 'star', character: '' },
  { title: 'heart', character: '❤️' }
]

Parameters:

  • collection (Array<Hash>)

    Array of character definitions



54
55
56
57
58
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 54

def add_items(collection)
  collection.each do |item|
    @items << item.slice(:title, :character)
  end
end

#item(title, character) ⇒ Object

Add a single character to the group

Examples:

Add smiley face

item 'smiley face', '😊'

Parameters:

  • title (String)

    Character title/description

  • character (String)

    The special character



42
43
44
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 42

def item(title, character)
  @items << { title: title, character: character }
end

#to_hHash

Convert group configuration to hash

Returns:

  • (Hash)

    Group configuration hash



72
73
74
75
76
77
78
# File 'lib/ckeditor5/rails/presets/special_characters_builder.rb', line 72

def to_h
  {
    name: @name,
    items: @items,
    options: label ? { label: label } : {}
  }
end