ckeditor5 1.24.9 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +65 -1
- data/lib/ckeditor5/rails/editor/props_plugin.rb +13 -9
- data/lib/ckeditor5/rails/engine.rb +1 -0
- data/lib/ckeditor5/rails/plugins/simple_upload_adapter.rb +2 -0
- data/lib/ckeditor5/rails/plugins/special_characters_bootstrap.rb +58 -0
- data/lib/ckeditor5/rails/plugins/wproofreader.rb +1 -0
- data/lib/ckeditor5/rails/presets/preset_builder.rb +41 -0
- data/lib/ckeditor5/rails/presets/special_characters_builder.rb +150 -0
- data/lib/ckeditor5/rails/version.rb +1 -1
- data/spec/e2e/features/editor_types_spec.rb +9 -0
- data/spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb +75 -2
- data/spec/lib/ckeditor5/rails/presets/special_characters_builder_spec.rb +157 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51c0f877edf5aa0ddc0c6b2333f5b631f1ce04144a84eb20c4555bfe63d3206b
|
4
|
+
data.tar.gz: 5d477a6bdf0d8fd05fc3bfedfe34f33398a1c58a015a5de8f6871afd1f38f4bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 401eb14e4e732e5ac3bd1d249372234b0d134277ad934e1cf38968a121824004266acf00ec71699ef3325288a28346fa42254735480207bc3d3a1c901b4b49d9
|
7
|
+
data.tar.gz: 21679ec808b05ff0c052fe419799e47a44b6587b66119cc43d2092c969f0634f52ee8f34c2a8a93eb5300e50c2c7e258cb3d8a4d073898b86ca07d4f1070839b
|
data/README.md
CHANGED
@@ -139,6 +139,7 @@ For extending CKEditor's functionality, refer to the [plugins directory](https:/
|
|
139
139
|
- [`inline_plugin(name, code)` method](#inline_pluginname-code-method)
|
140
140
|
- [`external_plugin(name, script:, import_as: nil, window_name: nil, stylesheets: [])` method](#external_pluginname-script-import_as-nil-window_name-nil-stylesheets--method)
|
141
141
|
- [`simple_upload_adapter(url)` method](#simple_upload_adapterurl-method)
|
142
|
+
- [`special_characters(&block)` method](#special_charactersblock-method)
|
142
143
|
- [`wproofreader(version: nil, cdn: nil, **config)` method](#wproofreaderversion-nil-cdn-nil-config-method)
|
143
144
|
- [Controller / View helpers 📦](#controller--view-helpers-)
|
144
145
|
- [`ckeditor5_element_ref(selector)` method](#ckeditor5_element_refselector-method)
|
@@ -794,6 +795,23 @@ CKEditor5::Rails.configure do
|
|
794
795
|
plugin :YourPlugin, window_name: 'YourPlugin'
|
795
796
|
end
|
796
797
|
```
|
798
|
+
|
799
|
+
If there is no `window.YourPlugin` object, the plugin will dispatch window event to load. To handle this event, you can use the `window.addEventListener` method:
|
800
|
+
|
801
|
+
```js
|
802
|
+
window.addEventListener('ckeditor:request-cjs-plugin:YourPlugin', () => {
|
803
|
+
window.YourPlugin = (async () => {
|
804
|
+
const { Plugin } = await import('ckeditor5');
|
805
|
+
|
806
|
+
return class YourPlugin extends Plugin {
|
807
|
+
// Your plugin code
|
808
|
+
};
|
809
|
+
})();
|
810
|
+
});
|
811
|
+
```
|
812
|
+
|
813
|
+
⚠️ The event handler must be attached before the plugin is requested. If the plugin is requested before the event handler is attached, the plugin will not be loaded.
|
814
|
+
|
797
815
|
</details>
|
798
816
|
|
799
817
|
#### `plugins(*names, **kwargs)` method
|
@@ -984,6 +1002,52 @@ end
|
|
984
1002
|
```
|
985
1003
|
</details>
|
986
1004
|
|
1005
|
+
#### `special_characters(&block)` method
|
1006
|
+
|
1007
|
+
<details>
|
1008
|
+
<summary>Configure special characters plugin</summary>
|
1009
|
+
|
1010
|
+
<br />
|
1011
|
+
|
1012
|
+
Defines the special characters plugin to be included in the editor. The example below shows how to include the special characters plugin:
|
1013
|
+
|
1014
|
+
```rb
|
1015
|
+
# config/initializers/ckeditor5.rb
|
1016
|
+
|
1017
|
+
CKEditor5::Rails.configure do
|
1018
|
+
# ... other configuration
|
1019
|
+
|
1020
|
+
special_characters do
|
1021
|
+
# Enable built-in packs using symbols
|
1022
|
+
packs :Text, :Essentials, :Currency, :Mathematical, :Latin
|
1023
|
+
|
1024
|
+
# Custom groups
|
1025
|
+
group 'Emoji', label: 'Emoticons' do
|
1026
|
+
item 'smiley', '😊'
|
1027
|
+
item 'heart', '❤️'
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
group 'Arrows',
|
1031
|
+
items: [
|
1032
|
+
{ title: 'right arrow', character: '→' },
|
1033
|
+
{ title: 'left arrow', character: '←' }
|
1034
|
+
]
|
1035
|
+
|
1036
|
+
group 'Mixed',
|
1037
|
+
items: [{ title: 'star', character: '⭐' }],
|
1038
|
+
label: 'Mixed Characters' do
|
1039
|
+
item 'heart', '❤️'
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
order :Text, :Currency, :Mathematical, :Latin, :Emoji, :Arrows, :Mixed
|
1043
|
+
end
|
1044
|
+
end
|
1045
|
+
```
|
1046
|
+
|
1047
|
+
For more info about the special characters plugin, check the [official documentation](https://ckeditor.com/docs/ckeditor5/latest/features/special-characters.html).
|
1048
|
+
|
1049
|
+
</details>
|
1050
|
+
|
987
1051
|
#### `wproofreader(version: nil, cdn: nil, **config)` method
|
988
1052
|
|
989
1053
|
<details>
|
@@ -1865,7 +1929,7 @@ end
|
|
1865
1929
|
|
1866
1930
|
```js
|
1867
1931
|
// app/javascript/custom_plugins/highlight.js
|
1868
|
-
|
1932
|
+
const { Plugin, Command, ButtonView } = await import('ckeditor5');
|
1869
1933
|
|
1870
1934
|
return class MyCustomPlugin extends Plugin {
|
1871
1935
|
static get pluginName() {
|
@@ -7,16 +7,20 @@ module CKEditor5::Rails::Editor
|
|
7
7
|
def initialize(name, premium: false, **js_import_meta_attrs)
|
8
8
|
super(name)
|
9
9
|
|
10
|
-
js_import_meta_attrs[:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
if js_import_meta_attrs[:window_name]
|
11
|
+
@js_import_meta = ::CKEditor5::Rails::Assets::JSImportMeta.new(**js_import_meta_attrs)
|
12
|
+
else
|
13
|
+
js_import_meta_attrs[:import_name] ||= if premium
|
14
|
+
'ckeditor5-premium-features'
|
15
|
+
else
|
16
|
+
'ckeditor5'
|
17
|
+
end
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
@js_import_meta = ::CKEditor5::Rails::Assets::JSImportMeta.new(
|
20
|
+
import_as: name,
|
21
|
+
**js_import_meta_attrs
|
22
|
+
)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
# Compress a little bit default plugins to make output smaller
|
@@ -5,6 +5,7 @@ require 'rails/engine'
|
|
5
5
|
require_relative 'presets/manager'
|
6
6
|
require_relative 'plugins/simple_upload_adapter'
|
7
7
|
require_relative 'plugins/wproofreader'
|
8
|
+
require_relative 'plugins/special_characters_bootstrap'
|
8
9
|
|
9
10
|
module CKEditor5::Rails
|
10
11
|
class PresetNotFoundError < ArgumentError; end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../editor/props_inline_plugin'
|
4
|
+
|
5
|
+
module CKEditor5::Rails::Plugins
|
6
|
+
class SpecialCharactersBootstrap < CKEditor5::Rails::Editor::PropsInlinePlugin
|
7
|
+
PLUGIN_CODE = <<~JS
|
8
|
+
const { Plugin } = await import( 'ckeditor5' );
|
9
|
+
|
10
|
+
return class SpecialCharactersBootstrap extends Plugin {
|
11
|
+
static get pluginName() {
|
12
|
+
return 'SpecialCharactersBootstrap';
|
13
|
+
}
|
14
|
+
|
15
|
+
get bootstrapConfig() {
|
16
|
+
return this.editor.config.get('specialCharactersBootstrap');
|
17
|
+
}
|
18
|
+
|
19
|
+
async init() {
|
20
|
+
const { editor, bootstrapConfig } = this;
|
21
|
+
const currentConfig = editor.config.get('specialCharacters');
|
22
|
+
|
23
|
+
if (!bootstrapConfig) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
|
27
|
+
editor.config.define('specialCharacters', {
|
28
|
+
...currentConfig,
|
29
|
+
order: bootstrapConfig.order || currentConfig.order,
|
30
|
+
} );
|
31
|
+
}
|
32
|
+
|
33
|
+
async afterInit() {
|
34
|
+
const { editor, bootstrapConfig } = this;
|
35
|
+
const specialCharacters = editor.plugins.get('SpecialCharacters');
|
36
|
+
|
37
|
+
if (!specialCharacters || !bootstrapConfig) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
const groups = bootstrapConfig.groups || [];
|
42
|
+
|
43
|
+
for (const { name, items, options } of groups) {
|
44
|
+
specialCharacters.addItems(name, items, {
|
45
|
+
label: name,
|
46
|
+
...options
|
47
|
+
});
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
JS
|
52
|
+
|
53
|
+
def initialize
|
54
|
+
super(:SpecialCharactersBootstrap, PLUGIN_CODE)
|
55
|
+
compress!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'concerns/configuration_methods'
|
4
4
|
require_relative 'concerns/plugin_methods'
|
5
|
+
require_relative 'special_characters_builder'
|
5
6
|
|
6
7
|
module CKEditor5::Rails
|
7
8
|
module Presets
|
@@ -368,6 +369,46 @@ module CKEditor5::Rails
|
|
368
369
|
end
|
369
370
|
end
|
370
371
|
|
372
|
+
# Configure special characters plugin
|
373
|
+
#
|
374
|
+
# @yield Block for configuring special characters
|
375
|
+
# @example Basic configuration with block
|
376
|
+
# special_characters do
|
377
|
+
# group 'Emoji', label: 'Emoticons' do
|
378
|
+
# item 'smiley', '😊'
|
379
|
+
# item 'heart', '❤️'
|
380
|
+
# end
|
381
|
+
# order :Text, :Emoji
|
382
|
+
# end
|
383
|
+
# @example Configuration with direct items array
|
384
|
+
# special_characters do
|
385
|
+
# group 'Arrows',
|
386
|
+
# items: [
|
387
|
+
# { title: 'right', character: '→' },
|
388
|
+
# { title: 'left', character: '←' }
|
389
|
+
# ]
|
390
|
+
# end
|
391
|
+
# @example Mixed configuration
|
392
|
+
# special_characters do
|
393
|
+
# group 'Mixed',
|
394
|
+
# items: [{ title: 'star', character: '⭐' }],
|
395
|
+
# label: 'Mixed Characters' do
|
396
|
+
# item 'heart', '❤️'
|
397
|
+
# end
|
398
|
+
# end
|
399
|
+
def special_characters(&block)
|
400
|
+
builder = SpecialCharactersBuilder.new
|
401
|
+
builder.instance_eval(&block) if block_given?
|
402
|
+
|
403
|
+
plugins do
|
404
|
+
append(:SpecialCharacters)
|
405
|
+
builder.packs_plugins.each { |pack| append(pack) }
|
406
|
+
prepend(Plugins::SpecialCharactersBootstrap.new)
|
407
|
+
end
|
408
|
+
|
409
|
+
configure(:specialCharactersBootstrap, builder.to_h)
|
410
|
+
end
|
411
|
+
|
371
412
|
private
|
372
413
|
|
373
414
|
def deep_copy_toolbar(toolbar)
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CKEditor5::Rails::Presets
|
4
|
+
# Builder class for configuring special characters in CKEditor5
|
5
|
+
#
|
6
|
+
# @example Basic configuration
|
7
|
+
# special_characters do
|
8
|
+
# group 'Emoji', label: 'Emoticons' do
|
9
|
+
# item 'smiley', '😊'
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# order :Text, :Mathematical, :Emoji
|
13
|
+
# end
|
14
|
+
class SpecialCharactersBuilder
|
15
|
+
attr_reader :packs_plugins
|
16
|
+
|
17
|
+
# Builder class for configuring special characters groups
|
18
|
+
#
|
19
|
+
# @example Basic group configuration
|
20
|
+
# group = Group.new('Emoji', label: 'Emoticons')
|
21
|
+
# group.item('smiley', '😊')
|
22
|
+
class Group
|
23
|
+
attr_reader :name, :label
|
24
|
+
private attr_reader :items
|
25
|
+
|
26
|
+
# Initialize a new special characters group
|
27
|
+
#
|
28
|
+
# @param name [String] Name of the group
|
29
|
+
# @param label [String, nil] Optional display label for the group
|
30
|
+
def initialize(name, label: nil)
|
31
|
+
@name = name
|
32
|
+
@label = label
|
33
|
+
@items = []
|
34
|
+
end
|
35
|
+
|
36
|
+
# Add a single character to the group
|
37
|
+
#
|
38
|
+
# @param title [String] Character title/description
|
39
|
+
# @param character [String] The special character
|
40
|
+
# @example Add smiley face
|
41
|
+
# item 'smiley face', '😊'
|
42
|
+
def item(title, character)
|
43
|
+
@items << { title: title, character: character }
|
44
|
+
end
|
45
|
+
|
46
|
+
# Add multiple characters to the group at once
|
47
|
+
#
|
48
|
+
# @param collection [Array<Hash>] Array of character definitions
|
49
|
+
# @example Add multiple items
|
50
|
+
# add_items [
|
51
|
+
# { title: 'star', character: '⭐' },
|
52
|
+
# { title: 'heart', character: '❤️' }
|
53
|
+
# ]
|
54
|
+
def add_items(collection)
|
55
|
+
collection.each do |item|
|
56
|
+
@items << item.slice(:title, :character)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Add multiple characters to the group
|
61
|
+
#
|
62
|
+
# @param items [Array<Hash>] Array of character definitions
|
63
|
+
def add_characters(items)
|
64
|
+
items.each do |item|
|
65
|
+
@items << item.slice(:title, :character)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Convert group configuration to hash
|
70
|
+
#
|
71
|
+
# @return [Hash] Group configuration hash
|
72
|
+
def to_h
|
73
|
+
{
|
74
|
+
name: @name,
|
75
|
+
items: @items,
|
76
|
+
options: label ? { label: label } : {}
|
77
|
+
}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Initialize a new special characters builder
|
82
|
+
#
|
83
|
+
# @example Create new builder
|
84
|
+
# SpecialCharactersBuilder.new
|
85
|
+
def initialize
|
86
|
+
@groups = []
|
87
|
+
@order = []
|
88
|
+
@packs_plugins = []
|
89
|
+
end
|
90
|
+
|
91
|
+
# Define a new special characters group
|
92
|
+
#
|
93
|
+
# @param name [String] Name of the group
|
94
|
+
# @param items [Array<Hash>] Optional array of character items
|
95
|
+
# @param label [String, nil] Optional display label
|
96
|
+
# @yield Group configuration block
|
97
|
+
# @return [Group] Created group instance
|
98
|
+
# @example Define group with items array
|
99
|
+
# group 'Emoji',
|
100
|
+
# items: [
|
101
|
+
# { title: 'smiley', character: '😊' },
|
102
|
+
# { title: 'heart', character: '❤️' }
|
103
|
+
# ],
|
104
|
+
# label: 'Emoticons'
|
105
|
+
# @example Define group with block
|
106
|
+
# group 'Emoji', label: 'Emoticons' do
|
107
|
+
# item 'smiley', '😊'
|
108
|
+
# item 'heart', '❤️'
|
109
|
+
# end
|
110
|
+
def group(name, items: [], label: nil, &block)
|
111
|
+
group = Group.new(name, label: label)
|
112
|
+
group.add_characters(items) if items.any?
|
113
|
+
group.instance_eval(&block) if block_given?
|
114
|
+
@groups << group
|
115
|
+
group
|
116
|
+
end
|
117
|
+
|
118
|
+
# Enable special characters packs
|
119
|
+
#
|
120
|
+
# @param names [Array<Symbol, String>] Pack names to enable
|
121
|
+
# @example Enable essential and extended characters
|
122
|
+
# packs :Text, :Currency, :Mathematical
|
123
|
+
def packs(*names)
|
124
|
+
names.each do |name|
|
125
|
+
plugin_name = "SpecialCharacters#{name.to_s.capitalize}"
|
126
|
+
@packs_plugins << plugin_name
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Set the display order of character groups
|
131
|
+
#
|
132
|
+
# @param categories [Array<Symbol, String>] Category names in desired order
|
133
|
+
# @example Set display order
|
134
|
+
# order :Text, :Mathematical, 'Currency', :Emoji
|
135
|
+
def order(*categories)
|
136
|
+
@order = categories.map(&:to_s)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Convert builder configuration to hash
|
140
|
+
#
|
141
|
+
# @return [Hash] Complete special characters configuration
|
142
|
+
def to_h
|
143
|
+
{
|
144
|
+
groups: @groups.map(&:to_h),
|
145
|
+
order: @order,
|
146
|
+
packs: @packs_plugins
|
147
|
+
}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -96,6 +96,15 @@ RSpec.describe 'CKEditor5 Types Integration', type: :feature, js: true do
|
|
96
96
|
expect(plugin_exists).to be true
|
97
97
|
end
|
98
98
|
end
|
99
|
+
|
100
|
+
it 'initializes the window plugin' do
|
101
|
+
visit 'classic'
|
102
|
+
|
103
|
+
eventually do
|
104
|
+
plugin_exists = page.evaluate_script('window.__customWindowPlugin !== undefined')
|
105
|
+
expect(plugin_exists).to be true
|
106
|
+
end
|
107
|
+
end
|
99
108
|
end
|
100
109
|
|
101
110
|
describe 'Decoupled Editor' do
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require_relative './plugins_builder_spec'
|
5
|
-
require_relative './toolbar_builder_spec'
|
6
4
|
|
7
5
|
RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
8
6
|
let(:builder) { described_class.new }
|
@@ -520,4 +518,79 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do
|
|
520
518
|
expect(builder.config[:wproofreader]).to eq({ language: 'en' })
|
521
519
|
end
|
522
520
|
end
|
521
|
+
|
522
|
+
describe '#special_characters' do
|
523
|
+
it 'configures special characters with groups and items' do # rubocop:disable Metrics/BlockLength
|
524
|
+
builder.special_characters do
|
525
|
+
group 'Emoji', label: 'Emoticons' do
|
526
|
+
item 'smiley', '😊'
|
527
|
+
item 'heart', '❤️'
|
528
|
+
end
|
529
|
+
|
530
|
+
group 'Arrows',
|
531
|
+
items: [
|
532
|
+
{ title: 'right', character: '→' },
|
533
|
+
{ title: 'left', character: '←' }
|
534
|
+
]
|
535
|
+
|
536
|
+
group 'Mixed',
|
537
|
+
items: [{ title: 'star', character: '⭐' }],
|
538
|
+
label: 'Mixed Characters' do
|
539
|
+
item 'heart', '❤️'
|
540
|
+
end
|
541
|
+
|
542
|
+
order :Text, :Arrows, :Emoji, :Mixed
|
543
|
+
end
|
544
|
+
|
545
|
+
expect(builder.config[:specialCharactersBootstrap]).to eq({
|
546
|
+
groups: [
|
547
|
+
{
|
548
|
+
name: 'Emoji',
|
549
|
+
items: [
|
550
|
+
{ title: 'smiley', character: '😊' },
|
551
|
+
{ title: 'heart', character: '❤️' }
|
552
|
+
],
|
553
|
+
options: { label: 'Emoticons' }
|
554
|
+
},
|
555
|
+
{
|
556
|
+
name: 'Arrows',
|
557
|
+
items: [
|
558
|
+
{ title: 'right', character: '→' },
|
559
|
+
{ title: 'left', character: '←' }
|
560
|
+
],
|
561
|
+
options: {}
|
562
|
+
},
|
563
|
+
{
|
564
|
+
name: 'Mixed',
|
565
|
+
items: [
|
566
|
+
{ title: 'star', character: '⭐' },
|
567
|
+
{ title: 'heart', character: '❤️' }
|
568
|
+
],
|
569
|
+
options: { label: 'Mixed Characters' }
|
570
|
+
}
|
571
|
+
],
|
572
|
+
order: %w[Text Arrows Emoji Mixed],
|
573
|
+
packs: []
|
574
|
+
})
|
575
|
+
|
576
|
+
plugin_names = builder.config[:plugins].map(&:name)
|
577
|
+
expect(plugin_names).to include(:SpecialCharacters)
|
578
|
+
expect(plugin_names).to include(:SpecialCharactersBootstrap)
|
579
|
+
end
|
580
|
+
|
581
|
+
it 'enables special characters packs' do
|
582
|
+
builder.special_characters do
|
583
|
+
packs :Text, :Mathematical, :Currency
|
584
|
+
end
|
585
|
+
|
586
|
+
plugin_names = builder.config[:plugins].map(&:name)
|
587
|
+
expect(plugin_names).to include(
|
588
|
+
:SpecialCharactersBootstrap,
|
589
|
+
:SpecialCharacters,
|
590
|
+
'SpecialCharactersText',
|
591
|
+
'SpecialCharactersMathematical',
|
592
|
+
'SpecialCharactersCurrency'
|
593
|
+
)
|
594
|
+
end
|
595
|
+
end
|
523
596
|
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe CKEditor5::Rails::Presets::SpecialCharactersBuilder do
|
6
|
+
subject(:builder) { described_class.new }
|
7
|
+
|
8
|
+
describe '#group' do
|
9
|
+
it 'creates a group with items array' do
|
10
|
+
group = builder.group('Arrows', items: [
|
11
|
+
{ title: 'right', character: '→' },
|
12
|
+
{ title: 'left', character: '←' }
|
13
|
+
])
|
14
|
+
|
15
|
+
expect(group.to_h).to eq({
|
16
|
+
name: 'Arrows',
|
17
|
+
items: [
|
18
|
+
{ title: 'right', character: '→' },
|
19
|
+
{ title: 'left', character: '←' }
|
20
|
+
],
|
21
|
+
options: {}
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'creates a group with block syntax' do
|
26
|
+
group = builder.group('Emoji', label: 'Emoticons') do
|
27
|
+
item 'smiley', '😊'
|
28
|
+
item 'heart', '❤️'
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(group.to_h).to eq({
|
32
|
+
name: 'Emoji',
|
33
|
+
items: [
|
34
|
+
{ title: 'smiley', character: '😊' },
|
35
|
+
{ title: 'heart', 'character': '❤️' }
|
36
|
+
],
|
37
|
+
options: { label: 'Emoticons' }
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'creates a group with mixed configuration' do
|
42
|
+
group = builder.group('Mixed',
|
43
|
+
items: [{ title: 'star', character: '⭐' }],
|
44
|
+
label: 'Mixed Characters') do
|
45
|
+
item 'heart', '❤️'
|
46
|
+
end
|
47
|
+
|
48
|
+
expect(group.to_h).to eq({
|
49
|
+
name: 'Mixed',
|
50
|
+
items: [
|
51
|
+
{ title: 'star', character: '⭐' },
|
52
|
+
{ title: 'heart', 'character': '❤️' }
|
53
|
+
],
|
54
|
+
options: { label: 'Mixed Characters' }
|
55
|
+
})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#packs' do
|
60
|
+
it 'registers special characters plugins' do
|
61
|
+
builder.packs(:Text, :Mathematical, :Currency)
|
62
|
+
|
63
|
+
expect(builder.packs_plugins).to eq(%w[
|
64
|
+
SpecialCharactersText
|
65
|
+
SpecialCharactersMathematical
|
66
|
+
SpecialCharactersCurrency
|
67
|
+
])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#order' do
|
72
|
+
it 'sets the display order of character groups' do
|
73
|
+
builder.order(:Text, :Mathematical, 'Currency', :Emoji)
|
74
|
+
|
75
|
+
expect(builder.to_h[:order]).to eq(%w[Text Mathematical Currency Emoji])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#to_h' do
|
80
|
+
it 'returns complete configuration' do
|
81
|
+
builder.group('Emoji', label: 'Emoticons') do
|
82
|
+
item 'smiley', '😊'
|
83
|
+
end
|
84
|
+
|
85
|
+
builder.packs(:Text, :Mathematical)
|
86
|
+
builder.order(:Text, :Mathematical, :Emoji)
|
87
|
+
|
88
|
+
expect(builder.to_h).to eq({
|
89
|
+
groups: [{
|
90
|
+
name: 'Emoji',
|
91
|
+
items: [{ title: 'smiley', character: '😊' }],
|
92
|
+
options: { label: 'Emoticons' }
|
93
|
+
}],
|
94
|
+
order: %w[Text Mathematical Emoji],
|
95
|
+
packs: %w[SpecialCharactersText SpecialCharactersMathematical]
|
96
|
+
})
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe CKEditor5::Rails::Presets::SpecialCharactersBuilder::Group do
|
101
|
+
subject(:group) { described_class.new('Test', label: 'Test Group') }
|
102
|
+
|
103
|
+
describe '#item' do
|
104
|
+
it 'adds a single character' do
|
105
|
+
group.item('test', '*')
|
106
|
+
expect(group.to_h[:items]).to eq([{ title: 'test', character: '*' }])
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#add_items' do
|
111
|
+
it 'adds multiple characters' do
|
112
|
+
group.add_items([
|
113
|
+
{ title: 'star', character: '⭐' },
|
114
|
+
{ title: 'heart', 'character': '❤️' }
|
115
|
+
])
|
116
|
+
|
117
|
+
expect(group.to_h[:items]).to eq([
|
118
|
+
{ title: 'star', character: '⭐' },
|
119
|
+
{ title: 'heart', 'character': '❤️' }
|
120
|
+
])
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'filters out invalid keys' do
|
124
|
+
group.add_items([
|
125
|
+
{ title: 'star', character: '⭐', invalid: 'key' }
|
126
|
+
])
|
127
|
+
|
128
|
+
expect(group.to_h[:items]).to eq([
|
129
|
+
{ title: 'star', character: '⭐' }
|
130
|
+
])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#to_h' do
|
135
|
+
it 'includes group name, items and options' do
|
136
|
+
group.item('test', '*')
|
137
|
+
|
138
|
+
expect(group.to_h).to eq({
|
139
|
+
name: 'Test',
|
140
|
+
items: [{ title: 'test', character: '*' }],
|
141
|
+
options: { label: 'Test Group' }
|
142
|
+
})
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'omits empty options' do
|
146
|
+
group = described_class.new('Test')
|
147
|
+
group.item('test', '*')
|
148
|
+
|
149
|
+
expect(group.to_h).to eq({
|
150
|
+
name: 'Test',
|
151
|
+
items: [{ title: 'test', character: '*' }],
|
152
|
+
options: {}
|
153
|
+
})
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ckeditor5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Bagiński
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-
|
12
|
+
date: 2025-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -89,12 +89,14 @@ files:
|
|
89
89
|
- lib/ckeditor5/rails/hooks/importmap.rb
|
90
90
|
- lib/ckeditor5/rails/hooks/simple_form.rb
|
91
91
|
- lib/ckeditor5/rails/plugins/simple_upload_adapter.rb
|
92
|
+
- lib/ckeditor5/rails/plugins/special_characters_bootstrap.rb
|
92
93
|
- lib/ckeditor5/rails/plugins/wproofreader.rb
|
93
94
|
- lib/ckeditor5/rails/presets/concerns/configuration_methods.rb
|
94
95
|
- lib/ckeditor5/rails/presets/concerns/plugin_methods.rb
|
95
96
|
- lib/ckeditor5/rails/presets/manager.rb
|
96
97
|
- lib/ckeditor5/rails/presets/plugins_builder.rb
|
97
98
|
- lib/ckeditor5/rails/presets/preset_builder.rb
|
99
|
+
- lib/ckeditor5/rails/presets/special_characters_builder.rb
|
98
100
|
- lib/ckeditor5/rails/presets/toolbar_builder.rb
|
99
101
|
- lib/ckeditor5/rails/semver.rb
|
100
102
|
- lib/ckeditor5/rails/version.rb
|
@@ -133,6 +135,7 @@ files:
|
|
133
135
|
- spec/lib/ckeditor5/rails/presets/manager_spec.rb
|
134
136
|
- spec/lib/ckeditor5/rails/presets/plugins_builder_spec.rb
|
135
137
|
- spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb
|
138
|
+
- spec/lib/ckeditor5/rails/presets/special_characters_builder_spec.rb
|
136
139
|
- spec/lib/ckeditor5/rails/presets/toolbar_builder_spec.rb
|
137
140
|
- spec/lib/ckeditor5/rails/semver_spec.rb
|
138
141
|
- spec/lib/ckeditor5/rails/version_detector_spec.rb
|
@@ -201,6 +204,7 @@ test_files:
|
|
201
204
|
- spec/lib/ckeditor5/rails/presets/manager_spec.rb
|
202
205
|
- spec/lib/ckeditor5/rails/presets/plugins_builder_spec.rb
|
203
206
|
- spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb
|
207
|
+
- spec/lib/ckeditor5/rails/presets/special_characters_builder_spec.rb
|
204
208
|
- spec/lib/ckeditor5/rails/presets/toolbar_builder_spec.rb
|
205
209
|
- spec/lib/ckeditor5/rails/semver_spec.rb
|
206
210
|
- spec/lib/ckeditor5/rails/version_detector_spec.rb
|