ckeditor5 1.16.0 → 1.16.2

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +66 -12
  3. data/lib/ckeditor5/rails/assets/assets_bundle.rb +1 -1
  4. data/lib/ckeditor5/rails/assets/webcomponents/components/context.mjs +0 -23
  5. data/lib/ckeditor5/rails/assets/webcomponents/components/editor.mjs +0 -24
  6. data/lib/ckeditor5/rails/assets/webcomponents/utils.mjs +10 -33
  7. data/lib/ckeditor5/rails/cdn/ckbox_bundle.rb +4 -4
  8. data/lib/ckeditor5/rails/cdn/ckeditor_bundle.rb +6 -6
  9. data/lib/ckeditor5/rails/context/helpers.rb +9 -3
  10. data/lib/ckeditor5/rails/context/preset_builder.rb +31 -0
  11. data/lib/ckeditor5/rails/context/preset_serializer.rb +30 -0
  12. data/lib/ckeditor5/rails/editor/props.rb +3 -16
  13. data/lib/ckeditor5/rails/editor/props_inline_plugin.rb +3 -6
  14. data/lib/ckeditor5/rails/editor/props_plugin.rb +4 -6
  15. data/lib/ckeditor5/rails/plugins/simple_upload_adapter.rb +2 -2
  16. data/lib/ckeditor5/rails/presets/concerns/configuration_methods.rb +21 -0
  17. data/lib/ckeditor5/rails/presets/concerns/plugin_methods.rb +29 -0
  18. data/lib/ckeditor5/rails/presets/preset_builder.rb +12 -33
  19. data/lib/ckeditor5/rails/version.rb +1 -1
  20. data/lib/ckeditor5/rails.rb +0 -1
  21. data/spec/e2e/features/context_spec.rb +36 -0
  22. data/spec/lib/ckeditor5/rails/assets/asset_bundle_hml_serializer_spec.rb +2 -2
  23. data/spec/lib/ckeditor5/rails/assets/assets_bundle_spec.rb +9 -7
  24. data/spec/lib/ckeditor5/rails/cdn/ckbox_bundle_spec.rb +1 -1
  25. data/spec/lib/ckeditor5/rails/context/helpers_spec.rb +49 -5
  26. data/spec/lib/ckeditor5/rails/context/preset_builder_spec.rb +85 -0
  27. data/spec/lib/ckeditor5/rails/context/{props_spec.rb → preset_serializer_spec.rb} +14 -21
  28. data/spec/lib/ckeditor5/rails/editor/props_spec.rb +0 -2
  29. metadata +12 -11
  30. data/lib/ckeditor5/rails/concerns/checksum.rb +0 -15
  31. data/lib/ckeditor5/rails/context/props.rb +0 -45
  32. data/lib/ckeditor5/rails/editor/props_base_plugin.rb +0 -19
  33. data/spec/lib/ckeditor5/rails/concerns/checksum_spec.rb +0 -50
  34. data/spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb +0 -27
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'concerns/configuration_methods'
4
+ require_relative 'concerns/plugin_methods'
5
+
3
6
  module CKEditor5::Rails
4
7
  module Presets
5
8
  class PresetBuilder
6
9
  include Editor::Helpers::Config
7
-
8
- attr_reader :config
10
+ include Concerns::ConfigurationMethods
11
+ include Concerns::PluginMethods
9
12
 
10
13
  def initialize(&block)
11
14
  @version = nil
@@ -46,10 +49,6 @@ module CKEditor5::Rails
46
49
  license_key == 'GPL'
47
50
  end
48
51
 
49
- def menubar?
50
- @config.dig(:menuBar, :isVisible) || false
51
- end
52
-
53
52
  def to_h_with_overrides(**overrides)
54
53
  {
55
54
  version: overrides.fetch(:version, version),
@@ -144,16 +143,16 @@ module CKEditor5::Rails
144
143
  @type = type
145
144
  end
146
145
 
147
- def configure(key, value)
148
- @config[key] = value
149
- end
150
-
151
146
  def menubar(visible: true)
152
- @config[:menuBar] = {
147
+ config[:menuBar] = {
153
148
  isVisible: visible
154
149
  }
155
150
  end
156
151
 
152
+ def menubar?
153
+ config.dig(:menuBar, :isVisible) || false
154
+ end
155
+
157
156
  def toolbar(*items, should_group_when_full: true, &block)
158
157
  if @config[:toolbar].blank? || !items.empty?
159
158
  @config[:toolbar] = {
@@ -167,30 +166,10 @@ module CKEditor5::Rails
167
166
  builder
168
167
  end
169
168
 
170
- def inline_plugin(name, code)
171
- @config[:plugins] << Editor::PropsInlinePlugin.new(name, code)
172
- end
173
-
174
- def plugin(name, **kwargs)
175
- plugin_obj = PluginsBuilder.create_plugin(name, **kwargs)
176
- @config[:plugins] << plugin_obj
177
- plugin_obj
178
- end
179
-
180
- def plugins(*names, **kwargs, &block)
181
- @config[:plugins] ||= []
182
-
183
- names.each { |name| plugin(name, **kwargs) } unless names.empty?
184
-
185
- builder = PluginsBuilder.new(@config[:plugins])
186
- builder.instance_eval(&block) if block_given?
187
- builder
188
- end
189
-
190
169
  def language(ui = nil, content: ui) # rubocop:disable Naming/MethodParameterName
191
- return @config[:language] if ui.nil?
170
+ return config[:language] if ui.nil?
192
171
 
193
- @config[:language] = {
172
+ config[:language] = {
194
173
  ui: ui,
195
174
  content: content
196
175
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  module CKEditor5
4
4
  module Rails
5
- VERSION = '1.16.0'
5
+ VERSION = '1.16.2'
6
6
 
7
7
  DEFAULT_CKEDITOR_VERSION = '43.3.1'
8
8
  end
@@ -5,7 +5,6 @@ module CKEditor5
5
5
  require_relative 'rails/version'
6
6
  require_relative 'rails/version_detector'
7
7
  require_relative 'rails/semver'
8
- require_relative 'rails/concerns/checksum'
9
8
  require_relative 'rails/assets/assets_bundle'
10
9
  require_relative 'rails/assets/assets_bundle_html_serializer'
11
10
  require_relative 'rails/helpers'
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'e2e/spec_helper'
4
+
5
+ RSpec.describe 'CKEditor5 Context Integration', type: :feature, js: true do
6
+ before { visit 'context' }
7
+
8
+ it 'initializes context with multiple editors' do
9
+ expect(page).to have_css('.ck-editor__editable', count: 2, wait: 10)
10
+ end
11
+
12
+ it 'initializes the magic context plugin' do
13
+ eventually do
14
+ plugin_exists = page.evaluate_script('window.MagicContextPlugin !== undefined')
15
+ expect(plugin_exists).to be true
16
+ end
17
+ end
18
+
19
+ it 'allows editing content in context editors' do
20
+ editors = all('.ck-editor__editable')
21
+
22
+ # Test first editor
23
+ editors[0].click
24
+ editors[0].send_keys([[:control, 'a'], :backspace])
25
+ editors[0].send_keys('Modified Context Item 1')
26
+
27
+ # Test second editor
28
+ editors[1].click
29
+ editors[1].send_keys([[:control, 'a'], :backspace])
30
+ editors[1].send_keys('Modified Context Item 2')
31
+
32
+ # Verify content
33
+ expect(editors[0].text).to eq('Modified Context Item 1')
34
+ expect(editors[1].text).to eq('Modified Context Item 2')
35
+ end
36
+ end
@@ -19,11 +19,11 @@ RSpec.describe CKEditor5::Rails::Assets::AssetsBundleHtmlSerializer do
19
19
 
20
20
  let(:scripts) do
21
21
  [
22
- CKEditor5::Rails::Assets::JSExportsMeta.new(
22
+ CKEditor5::Rails::Assets::JSUrlImportMeta.new(
23
23
  'https://cdn.com/script1.js',
24
24
  window_name: 'CKEditor5'
25
25
  ),
26
- CKEditor5::Rails::Assets::JSExportsMeta.new(
26
+ CKEditor5::Rails::Assets::JSUrlImportMeta.new(
27
27
  'https://cdn.com/script2.js',
28
28
  import_name: '@ckeditor/script2'
29
29
  )
@@ -35,8 +35,10 @@ RSpec.describe CKEditor5::Rails::Assets::AssetsBundle do
35
35
 
36
36
  describe '#translations_scripts' do
37
37
  let(:bundle) { concrete_class.new }
38
- let(:translation_script) { instance_double(CKEditor5::Rails::Assets::JSExportsMeta, translation?: true) }
39
- let(:regular_script) { instance_double(CKEditor5::Rails::Assets::JSExportsMeta, translation?: false) }
38
+ let(:translation_script) do
39
+ instance_double(CKEditor5::Rails::Assets::JSUrlImportMeta, translation?: true)
40
+ end
41
+ let(:regular_script) { instance_double(CKEditor5::Rails::Assets::JSUrlImportMeta, translation?: false) }
40
42
 
41
43
  before do
42
44
  allow(bundle).to receive(:scripts).and_return([translation_script, regular_script])
@@ -48,8 +50,8 @@ RSpec.describe CKEditor5::Rails::Assets::AssetsBundle do
48
50
  end
49
51
 
50
52
  describe '#<<' do
51
- let(:script1) { instance_double(CKEditor5::Rails::Assets::JSExportsMeta) }
52
- let(:script2) { instance_double(CKEditor5::Rails::Assets::JSExportsMeta) }
53
+ let(:script1) { instance_double(CKEditor5::Rails::Assets::JSUrlImportMeta) }
54
+ let(:script2) { instance_double(CKEditor5::Rails::Assets::JSUrlImportMeta) }
53
55
  let(:stylesheet1) { '/path/to/style1.css' }
54
56
  let(:stylesheet2) { '/path/to/style2.css' }
55
57
 
@@ -101,8 +103,8 @@ RSpec.describe CKEditor5::Rails::Assets::AssetsBundle do
101
103
  end
102
104
 
103
105
  describe '#preloads' do
104
- let(:script1) { instance_double(CKEditor5::Rails::Assets::JSExportsMeta, url: '/js/script1.js') }
105
- let(:script2) { instance_double(CKEditor5::Rails::Assets::JSExportsMeta, url: '/js/script2.js') }
106
+ let(:script1) { instance_double(CKEditor5::Rails::Assets::JSUrlImportMeta, url: '/js/script1.js') }
107
+ let(:script2) { instance_double(CKEditor5::Rails::Assets::JSUrlImportMeta, url: '/js/script2.js') }
106
108
  let(:stylesheet1) { '/css/style1.css' }
107
109
  let(:stylesheet2) { '/css/style2.css' }
108
110
 
@@ -136,7 +138,7 @@ RSpec.describe CKEditor5::Rails::Assets::AssetsBundle do
136
138
  end
137
139
  end
138
140
 
139
- RSpec.describe CKEditor5::Rails::Assets::JSExportsMeta do
141
+ RSpec.describe CKEditor5::Rails::Assets::JSUrlImportMeta do
140
142
  let(:url) { '/path/to/script.js' }
141
143
 
142
144
  describe '#initialize' do
@@ -36,7 +36,7 @@ RSpec.describe CKEditor5::Rails::Cdn::CKBoxBundle do
36
36
 
37
37
  describe '#scripts' do
38
38
  it 'returns array with main script' do
39
- expect(bundle.scripts.first).to be_a(CKEditor5::Rails::Assets::JSExportsMeta)
39
+ expect(bundle.scripts.first).to be_a(CKEditor5::Rails::Assets::JSUrlImportMeta)
40
40
  expect(bundle.scripts.first.url).to include('ckbox.js')
41
41
  expect(bundle.scripts.first.window_name).to eq('CKBox')
42
42
  end
@@ -14,7 +14,28 @@ RSpec.describe CKEditor5::Rails::Context::Helpers do
14
14
  let(:helper) { test_class.new }
15
15
 
16
16
  describe '#ckeditor5_context' do
17
- it 'creates context component with default attributes' do
17
+ let(:empty_preset) { CKEditor5::Rails::Context::PresetBuilder.new }
18
+
19
+ let(:custom_preset) do
20
+ CKEditor5::Rails::Context::PresetBuilder.new do
21
+ configure :preset, :custom
22
+ end
23
+ end
24
+
25
+ let(:cdn_preset) do
26
+ CKEditor5::Rails::Context::PresetBuilder.new do
27
+ configure :cdn, :jsdelivr
28
+ end
29
+ end
30
+
31
+ let(:complex_preset) do
32
+ CKEditor5::Rails::Context::PresetBuilder.new do
33
+ configure :preset, :custom
34
+ configure :cdn, :jsdelivr
35
+ end
36
+ end
37
+
38
+ it 'is optional to pass a preset' do
18
39
  expect(helper.ckeditor5_context).to have_tag(
19
40
  'ckeditor-context-component',
20
41
  with: {
@@ -24,8 +45,18 @@ RSpec.describe CKEditor5::Rails::Context::Helpers do
24
45
  )
25
46
  end
26
47
 
48
+ it 'creates context component with default attributes' do
49
+ expect(helper.ckeditor5_context(empty_preset)).to have_tag(
50
+ 'ckeditor-context-component',
51
+ with: {
52
+ plugins: '[]',
53
+ config: '{}'
54
+ }
55
+ )
56
+ end
57
+
27
58
  it 'creates context component with preset configuration' do
28
- expect(helper.ckeditor5_context(preset: :custom)).to have_tag(
59
+ expect(helper.ckeditor5_context(custom_preset)).to have_tag(
29
60
  'ckeditor-context-component',
30
61
  with: {
31
62
  plugins: '[]',
@@ -35,7 +66,7 @@ RSpec.describe CKEditor5::Rails::Context::Helpers do
35
66
  end
36
67
 
37
68
  it 'creates context component with cdn configuration' do
38
- expect(helper.ckeditor5_context(cdn: :jsdelivr)).to have_tag(
69
+ expect(helper.ckeditor5_context(cdn_preset)).to have_tag(
39
70
  'ckeditor-context-component',
40
71
  with: {
41
72
  plugins: '[]',
@@ -45,7 +76,7 @@ RSpec.describe CKEditor5::Rails::Context::Helpers do
45
76
  end
46
77
 
47
78
  it 'creates context component with multiple configurations' do
48
- result = helper.ckeditor5_context(preset: :custom, cdn: :jsdelivr)
79
+ result = helper.ckeditor5_context(complex_preset)
49
80
 
50
81
  expect(result).to have_tag(
51
82
  'ckeditor-context-component',
@@ -57,11 +88,24 @@ RSpec.describe CKEditor5::Rails::Context::Helpers do
57
88
  end
58
89
 
59
90
  it 'accepts block content' do
60
- result = helper.ckeditor5_context { 'Content' }
91
+ result = helper.ckeditor5_context(empty_preset) { 'Content' }
61
92
 
62
93
  expect(result).to have_tag('ckeditor-context-component') do
63
94
  with_text 'Content'
64
95
  end
65
96
  end
66
97
  end
98
+
99
+ describe '#ckeditor5_context_preset' do
100
+ it 'creates a new preset builder' do
101
+ preset = helper.ckeditor5_context_preset do
102
+ configure :preset, :custom
103
+ end
104
+
105
+ expect(preset.config).to eq(
106
+ plugins: [],
107
+ preset: :custom
108
+ )
109
+ end
110
+ end
67
111
  end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe CKEditor5::Rails::Context::PresetBuilder do
6
+ subject(:builder) { described_class.new }
7
+
8
+ describe '#initialize' do
9
+ it 'creates empty config with plugins array' do
10
+ expect(builder.config).to eq({ plugins: [] })
11
+ end
12
+
13
+ it 'accepts configuration block' do
14
+ builder = described_class.new do
15
+ configure :language, 'en'
16
+ end
17
+
18
+ expect(builder.config[:language]).to eq('en')
19
+ end
20
+ end
21
+
22
+ describe '#initialize_copy' do
23
+ let(:original) do
24
+ described_class.new do
25
+ configure :language, 'en'
26
+ plugin 'Test'
27
+ end
28
+ end
29
+
30
+ it 'creates deep copy of config' do
31
+ copy = original.dup
32
+
33
+ expect(copy.config).not_to be(original.config)
34
+ expect(copy.config[:plugins]).not_to be(original.config[:plugins])
35
+ expect(copy.config[:plugins].first).not_to be(original.config[:plugins].first)
36
+ end
37
+ end
38
+
39
+ describe '#configure' do
40
+ it 'sets config value' do
41
+ builder.configure(:toolbar, { items: ['bold'] })
42
+ expect(builder.config[:toolbar]).to eq({ items: ['bold'] })
43
+ end
44
+ end
45
+
46
+ describe '#plugin' do
47
+ it 'adds normalized plugin to config' do
48
+ plugin = builder.plugin('Test')
49
+
50
+ expect(builder.config[:plugins]).to include(plugin)
51
+ expect(plugin).to be_a(CKEditor5::Rails::Editor::PropsPlugin)
52
+ end
53
+
54
+ it 'accepts plugin options' do
55
+ plugin = builder.plugin('Test', premium: true)
56
+
57
+ expect(plugin.js_import_meta[:import_name]).to eq('ckeditor5-premium-features')
58
+ end
59
+ end
60
+
61
+ describe '#plugins' do
62
+ it 'adds multiple plugins at once' do
63
+ builder.plugins('Test1', 'Test2')
64
+
65
+ expect(builder.config[:plugins].map(&:name)).to eq(%w[Test1 Test2])
66
+ end
67
+
68
+ it 'accepts block for complex configuration' do
69
+ builder.plugins do
70
+ append 'Test1'
71
+ append 'Test2', premium: true
72
+ end
73
+
74
+ expect(builder.config[:plugins].map(&:name)).to eq(%w[Test1 Test2])
75
+ end
76
+
77
+ it 'accepts both arguments and block' do
78
+ builder.plugins('Test1') do
79
+ append 'Test2'
80
+ end
81
+
82
+ expect(builder.config[:plugins].map(&:name)).to eq(%w[Test1 Test2])
83
+ end
84
+ end
85
+ end
@@ -2,38 +2,31 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe CKEditor5::Rails::Context::Props do
6
- let(:config) do
7
- {
8
- plugins: [
9
- CKEditor5::Rails::Editor::PropsPlugin.new('Plugin1', import_name: '@ckeditor/plugin1'),
10
- CKEditor5::Rails::Editor::PropsInlinePlugin.new('plugin2', 'export default class Plugin2 {}')
11
- ],
12
- toolbar: { items: %w[bold italic] },
13
- language: 'en'
14
- }
5
+ RSpec.describe CKEditor5::Rails::Context::PresetSerializer do
6
+ let(:preset) do
7
+ CKEditor5::Rails::Context::PresetBuilder.new do
8
+ plugin 'Plugin1', import_name: '@ckeditor/plugin1'
9
+ inline_plugin 'plugin2', 'export default class Plugin2 {}'
10
+
11
+ configure :toolbar, { items: %w[bold italic] }
12
+ configure :language, 'en'
13
+ end
15
14
  end
16
15
 
17
- subject(:props) { described_class.new(config) }
16
+ subject(:serializer) { described_class.new(preset) }
18
17
 
19
18
  describe '#initialize' do
20
- it 'accepts a config hash' do
21
- expect { described_class.new({}) }.not_to raise_error
19
+ it 'accepts a preset instance' do
20
+ expect { described_class.new(preset) }.not_to raise_error
22
21
  end
23
22
  end
24
23
 
25
24
  describe '#to_attributes' do
26
- subject(:attributes) { props.to_attributes }
27
-
28
- it 'returns integrity property' do
29
- expect(attributes[:integrity]).to eq(
30
- '24e46c3ee19f6764930b38ecdf62c0ac824a0acbe6616b46199d892afb211acb'
31
- )
32
- end
25
+ subject(:attributes) { serializer.to_attributes }
33
26
 
34
27
  it 'returns a hash with plugins and config keys' do
35
28
  expect(attributes).to be_a(Hash)
36
- expect(attributes.keys).to match_array(%i[plugins integrity config])
29
+ expect(attributes.keys).to match_array(%i[plugins config])
37
30
  end
38
31
 
39
32
  describe ':plugins key' do
@@ -28,13 +28,11 @@ RSpec.describe CKEditor5::Rails::Editor::Props do
28
28
 
29
29
  it 'includes required attributes' do
30
30
  attributes = props.to_attributes
31
-
32
31
  expect(attributes).to include(
33
32
  type: 'ClassicEditor',
34
33
  translations: String,
35
34
  plugins: String,
36
35
  config: String,
37
- integrity: '358d88b83d041f208d94ac957b2fd68135f1caab5c0d101d33cf04d5d39d81ef',
38
36
  watchdog: true
39
37
  )
40
38
  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.16.0
4
+ version: 1.16.2
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: 2024-11-22 00:00:00.000000000 Z
12
+ date: 2024-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -55,15 +55,14 @@ files:
55
55
  - lib/ckeditor5/rails/cdn/ckeditor_bundle.rb
56
56
  - lib/ckeditor5/rails/cdn/helpers.rb
57
57
  - lib/ckeditor5/rails/cdn/url_generator.rb
58
- - lib/ckeditor5/rails/concerns/checksum.rb
59
58
  - lib/ckeditor5/rails/context/helpers.rb
60
- - lib/ckeditor5/rails/context/props.rb
59
+ - lib/ckeditor5/rails/context/preset_builder.rb
60
+ - lib/ckeditor5/rails/context/preset_serializer.rb
61
61
  - lib/ckeditor5/rails/editor/editable_height_normalizer.rb
62
62
  - lib/ckeditor5/rails/editor/helpers.rb
63
63
  - lib/ckeditor5/rails/editor/helpers/config_helpers.rb
64
64
  - lib/ckeditor5/rails/editor/helpers/editor_helpers.rb
65
65
  - lib/ckeditor5/rails/editor/props.rb
66
- - lib/ckeditor5/rails/editor/props_base_plugin.rb
67
66
  - lib/ckeditor5/rails/editor/props_inline_plugin.rb
68
67
  - lib/ckeditor5/rails/editor/props_plugin.rb
69
68
  - lib/ckeditor5/rails/engine.rb
@@ -71,6 +70,8 @@ files:
71
70
  - lib/ckeditor5/rails/hooks/form.rb
72
71
  - lib/ckeditor5/rails/hooks/simple_form.rb
73
72
  - lib/ckeditor5/rails/plugins/simple_upload_adapter.rb
73
+ - lib/ckeditor5/rails/presets/concerns/configuration_methods.rb
74
+ - lib/ckeditor5/rails/presets/concerns/plugin_methods.rb
74
75
  - lib/ckeditor5/rails/presets/manager.rb
75
76
  - lib/ckeditor5/rails/presets/plugins_builder.rb
76
77
  - lib/ckeditor5/rails/presets/preset_builder.rb
@@ -78,6 +79,7 @@ files:
78
79
  - lib/ckeditor5/rails/semver.rb
79
80
  - lib/ckeditor5/rails/version.rb
80
81
  - lib/ckeditor5/rails/version_detector.rb
82
+ - spec/e2e/features/context_spec.rb
81
83
  - spec/e2e/features/editor_types_spec.rb
82
84
  - spec/e2e/features/form_integration_spec.rb
83
85
  - spec/e2e/spec_helper.rb
@@ -89,13 +91,12 @@ files:
89
91
  - spec/lib/ckeditor5/rails/cdn/ckeditor_bundle_spec.rb
90
92
  - spec/lib/ckeditor5/rails/cdn/helpers_spec.rb
91
93
  - spec/lib/ckeditor5/rails/cdn/url_generator_spec.rb
92
- - spec/lib/ckeditor5/rails/concerns/checksum_spec.rb
93
94
  - spec/lib/ckeditor5/rails/context/helpers_spec.rb
94
- - spec/lib/ckeditor5/rails/context/props_spec.rb
95
+ - spec/lib/ckeditor5/rails/context/preset_builder_spec.rb
96
+ - spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
95
97
  - spec/lib/ckeditor5/rails/editor/editable_height_normalizer_spec.rb
96
98
  - spec/lib/ckeditor5/rails/editor/helpers/config_helpers_spec.rb
97
99
  - spec/lib/ckeditor5/rails/editor/helpers/editor_helpers_spec.rb
98
- - spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb
99
100
  - spec/lib/ckeditor5/rails/editor/props_inline_plugin_spec.rb
100
101
  - spec/lib/ckeditor5/rails/editor/props_plugin_spec.rb
101
102
  - spec/lib/ckeditor5/rails/editor/props_spec.rb
@@ -135,6 +136,7 @@ signing_key:
135
136
  specification_version: 4
136
137
  summary: CKEditor 5 for Rails
137
138
  test_files:
139
+ - spec/e2e/features/context_spec.rb
138
140
  - spec/e2e/features/editor_types_spec.rb
139
141
  - spec/e2e/features/form_integration_spec.rb
140
142
  - spec/e2e/spec_helper.rb
@@ -146,13 +148,12 @@ test_files:
146
148
  - spec/lib/ckeditor5/rails/cdn/ckeditor_bundle_spec.rb
147
149
  - spec/lib/ckeditor5/rails/cdn/helpers_spec.rb
148
150
  - spec/lib/ckeditor5/rails/cdn/url_generator_spec.rb
149
- - spec/lib/ckeditor5/rails/concerns/checksum_spec.rb
150
151
  - spec/lib/ckeditor5/rails/context/helpers_spec.rb
151
- - spec/lib/ckeditor5/rails/context/props_spec.rb
152
+ - spec/lib/ckeditor5/rails/context/preset_builder_spec.rb
153
+ - spec/lib/ckeditor5/rails/context/preset_serializer_spec.rb
152
154
  - spec/lib/ckeditor5/rails/editor/editable_height_normalizer_spec.rb
153
155
  - spec/lib/ckeditor5/rails/editor/helpers/config_helpers_spec.rb
154
156
  - spec/lib/ckeditor5/rails/editor/helpers/editor_helpers_spec.rb
155
- - spec/lib/ckeditor5/rails/editor/props_base_plugin_spec.rb
156
157
  - spec/lib/ckeditor5/rails/editor/props_inline_plugin_spec.rb
157
158
  - spec/lib/ckeditor5/rails/editor/props_plugin_spec.rb
158
159
  - spec/lib/ckeditor5/rails/editor/props_spec.rb
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'digest'
4
- require 'json'
5
-
6
- module CKEditor5::Rails::Concerns
7
- module Checksum
8
- private
9
-
10
- def calculate_object_checksum(obj)
11
- json = JSON.generate(obj)
12
- Digest::SHA256.hexdigest(json)
13
- end
14
- end
15
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CKEditor5::Rails
4
- module Context
5
- class Props
6
- include CKEditor5::Rails::Concerns::Checksum
7
-
8
- def initialize(config)
9
- @config = config
10
- end
11
-
12
- def to_attributes
13
- {
14
- **serialized_attributes,
15
- integrity: integrity_checksum
16
- }
17
- end
18
-
19
- private
20
-
21
- attr_reader :config
22
-
23
- def integrity_checksum
24
- unsafe_attributes = serialized_attributes.slice(:plugins)
25
-
26
- calculate_object_checksum(unsafe_attributes)
27
- end
28
-
29
- def serialized_attributes
30
- @serialized_attributes ||= {
31
- plugins: serialize_plugins,
32
- config: serialize_config
33
- }
34
- end
35
-
36
- def serialize_plugins
37
- (config[:plugins] || []).map { |plugin| Editor::PropsPlugin.normalize(plugin).to_h }.to_json
38
- end
39
-
40
- def serialize_config
41
- config.except(:plugins).to_json
42
- end
43
- end
44
- end
45
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CKEditor5::Rails
4
- module Editor
5
- class PropsBasePlugin
6
- include Concerns::Checksum
7
-
8
- attr_reader :name
9
-
10
- def initialize(name)
11
- @name = name
12
- end
13
-
14
- def to_h
15
- raise NotImplementedError, 'This method must be implemented in a subclass'
16
- end
17
- end
18
- end
19
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe CKEditor5::Rails::Concerns::Checksum do
6
- let(:dummy_class) do
7
- Class.new do
8
- include CKEditor5::Rails::Concerns::Checksum
9
-
10
- public :calculate_object_checksum
11
- end
12
- end
13
-
14
- subject(:instance) { dummy_class.new }
15
-
16
- describe '#calculate_object_checksum' do
17
- it 'returns a 16-character string' do
18
- result = instance.calculate_object_checksum({ test: 'value' })
19
- expect(result).to eq(
20
- 'f98be16ebfa861cb39a61faff9e52b33f5bcc16bb6ae72e728d226dc07093932'
21
- )
22
- end
23
-
24
- it 'returns consistent checksums for the same input' do
25
- input = { name: 'test', value: 123 }
26
- first_result = instance.calculate_object_checksum(input)
27
- second_result = instance.calculate_object_checksum(input)
28
- expect(first_result).to eq(second_result)
29
- end
30
-
31
- it 'returns different checksums for different inputs' do
32
- result1 = instance.calculate_object_checksum({ a: 1 })
33
- result2 = instance.calculate_object_checksum({ a: 2 })
34
- expect(result1).not_to eq(result2)
35
- end
36
-
37
- it 'handles arrays' do
38
- result = instance.calculate_object_checksum([1, 2, 3])
39
- expect(result).to eq(
40
- 'a615eeaee21de5179de080de8c3052c8da901138406ba71c38c032845f7d54f4'
41
- )
42
- end
43
-
44
- it 'is order dependent for hashes' do
45
- result1 = instance.calculate_object_checksum({ a: 1, b: 2 })
46
- result2 = instance.calculate_object_checksum({ b: 2, a: 1 })
47
- expect(result1).not_to eq(result2)
48
- end
49
- end
50
- end