Class: CKEditor5::Rails::Presets::SpecialCharactersBuilder
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Presets::SpecialCharactersBuilder
- Defined in:
- lib/ckeditor5/rails/presets/special_characters_builder.rb
Overview
Builder class for configuring special characters in CKEditor5
Defined Under Namespace
Classes: Group
Instance Attribute Summary collapse
-
#packs_plugins ⇒ Object
readonly
Returns the value of attribute packs_plugins.
Instance Method Summary collapse
-
#group(name, items: [], label: nil) { ... } ⇒ Group
Define a new special characters group.
-
#initialize ⇒ SpecialCharactersBuilder
constructor
Initialize a new special characters builder.
-
#order(*categories) ⇒ Object
Set the display order of character groups.
-
#packs(*names) ⇒ Object
Enable special characters packs.
-
#to_h ⇒ Hash
Convert builder configuration to hash.
Constructor Details
#initialize ⇒ SpecialCharactersBuilder
Initialize a new special characters builder
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_plugins ⇒ Object (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
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
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
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_h ⇒ Hash
Convert builder configuration to hash
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 |