ckeditor5 1.11.0 โ†’ 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbd754782a22b999b5843eedf90b499ba82f44dfac2ceb51f3c46898800482e2
4
- data.tar.gz: c7945b1c9efeb3579a70ac0aaa832bac46147c512b9de98dff3dbf5a3187afad
3
+ metadata.gz: c39a460f498306970334acf87d4bd8c66a24ddaf79ad0dd9f461ed5d9772de11
4
+ data.tar.gz: b5a221dbe9dd9d47c649d1b8d78eda335fdeebe4fde6190db9f03cf3f3fe4aca
5
5
  SHA512:
6
- metadata.gz: e1263373ca9e36adf9d63b8ff23d88933231cdacb8378cedc9f17819ae59924064e04bec14731e3907808af138ecd2afc4cd80cb2db9b943f221d1b8d9ccdf43
7
- data.tar.gz: a8c822abfc9f0f191785d2cea17d5eb7d5d9696c2d3337c9fbdd4ff302f9ef1bf2b46fca90cc9b221f00c1a37c0d124c92fb74dde125dc5e8cd2aaf9b683f8bc
6
+ metadata.gz: a7368d44b2ed0ce7416c8a4ed0052c9c15b343bf012e39fa24abd5761a61173c4ae95925061dce751c0b6419b19e1a69f2d98266f316b99d1c06479b1cad9b1c
7
+ data.tar.gz: b0c6f01ac1d2efbc70f11a12997b6d48567293c13689e203ba29f9034dc233d25851e6d0c6bde29f382fbfafcb6f8630e4e51eb47db15922928eb20a199e3274
data/Gemfile CHANGED
@@ -8,7 +8,9 @@ group :development do
8
8
  gem 'brakeman', '~> 6.1', '>= 6.1.1', require: false
9
9
  gem 'guard', '~> 2.19', '>= 2.19.0'
10
10
  gem 'guard-process', '~> 1.2'
11
+ gem 'guard-rspec', '~> 4.7', '>= 4.7.3'
11
12
  gem 'pry', '~> 0.15', '>= 0.15.0'
13
+ gem 'pry-rails', '~> 0.3', '>= 0.3.11'
12
14
  gem 'rails', '~> 7.0', '>= 7.0.0'
13
15
  gem 'rake', '~> 13.2', '>= 13.2.1'
14
16
  gem 'rspec', '~> 3.13'
@@ -17,6 +19,8 @@ group :development do
17
19
  gem 'rubocop', '~> 1.66', require: false
18
20
  gem 'rubocop-rails', '~> 2.26', '>= 2.26.2', require: false
19
21
  gem 'rubocop-rails-omakase', '~> 1.0.0', require: false
22
+ gem 'simplecov', '~> 0.21', '>= 0.21.2', require: false
23
+ gem 'simplecov_json_formatter', '~> 0.1.4', require: false
20
24
  gem 'simple_form', '~> 5.3', '>= 5.3.0'
21
25
  gem 'slim', '~> 5.2', '>= 5.2.0'
22
26
  gem 'sprockets-rails', '~> 3.2', '>= 3.2.2'
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![License: GPL v2](https://img.shields.io/badge/License-GPL_v2-blue.svg?style=flat-square)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
4
4
  ![Gem Version](https://img.shields.io/gem/v/ckeditor5?style=flat-square)
5
5
  ![Gem Total Downloads](https://img.shields.io/gem/dt/ckeditor5?style=flat-square&color=orange)
6
+ [![Coverage](https://img.shields.io/codecov/c/github/mati365/ckeditor5-rails?style=flat-square)](https://codecov.io/gh/mati365/ckeditor5-rails)
6
7
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg?style=flat-square)](http://makeapullrequest.com)
7
8
  ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/mati365/ckeditor5-rails?style=flat-square)
8
9
  [![GitHub issues](https://img.shields.io/github/issues/mati365/ckeditor5-rails?style=flat-square)](https://github.com/Mati365/ckeditor5-rails/issues)
@@ -84,7 +85,9 @@ Voilร ! You have CKEditor 5 integrated with your Rails application. ๐ŸŽ‰
84
85
  - [`plugin(name, premium:, import_name:)` method](#pluginname-premium-import_name-method)
85
86
  - [`plugins(*names, **kwargs)` method](#pluginsnames-kwargs-method)
86
87
  - [`inline_plugin(name, code)` method](#inline_pluginname-code-method)
88
+ - [Controller / View helpers ๐Ÿ“ฆ](#controller--view-helpers-)
87
89
  - [`ckeditor5_element_ref(selector)` method](#ckeditor5_element_refselector-method)
90
+ - [`ckeditor5_preset(&block)` method](#ckeditor5_presetblock-method)
88
91
  - [Including CKEditor 5 assets ๐Ÿ“ฆ](#including-ckeditor-5-assets-)
89
92
  - [Format ๐Ÿ“](#format-)
90
93
  - [Using default preset](#using-default-preset)
@@ -118,6 +121,7 @@ Voilร ! You have CKEditor 5 integrated with your Rails application. ๐ŸŽ‰
118
121
  - [`editor-change` event](#editor-change-event)
119
122
  - [Inline event handling](#inline-event-handling)
120
123
  - [Gem Development ๐Ÿ› ](#gem-development-)
124
+ - [Running tests ๐Ÿงช](#running-tests-)
121
125
  - [Trademarks ๐Ÿ“œ](#trademarks-)
122
126
  - [License ๐Ÿ“œ](#license-)
123
127
 
@@ -327,7 +331,7 @@ Defines the CKBox plugin to be included in the editor. The example below shows h
327
331
  CKEditor5::Rails.configure do
328
332
  # ... other configuration
329
333
 
330
- ckbox '2.5.4', theme: :lark
334
+ ckbox '2.6.0', theme: :lark
331
335
  end
332
336
  ```
333
337
 
@@ -556,6 +560,8 @@ CKEditor5::Rails.configure do
556
560
  end
557
561
  ```
558
562
 
563
+ ### Controller / View helpers ๐Ÿ“ฆ
564
+
559
565
  #### `ckeditor5_element_ref(selector)` method
560
566
 
561
567
  Defines a reference to a CKEditor 5 element. In other words, it allows you to reference DOM elements that will be used by the editor's features. It's particularly useful for features that need to check element presence or operate on specific DOM elements. The primary example is the `presence list` feature that requires a reference to the element that will be used to display the list.
@@ -572,6 +578,43 @@ CKEditor5::Rails.configure do
572
578
  end
573
579
  ```
574
580
 
581
+ ### `ckeditor5_preset(&block)` method
582
+
583
+ The `ckeditor5_preset` method allows you to define a custom preset in your application controller. It may be useful when you want to define a preset based on the current user or request.
584
+
585
+ ```rb
586
+ # app/controllers/application_controller.rb
587
+
588
+ class ApplicationController < ActionController::Base
589
+ def show
590
+ @preset = ckeditor5_preset do
591
+ version '43.3.0'
592
+
593
+ toolbar :sourceEditing, :|, :bold, :italic, :underline, :strikethrough,
594
+ :subscript, :superscript, :removeFormat, :|, :bulletedList, :numberedList,
595
+ :fontFamily, :fontSize, :|, :link, :anchor, :|,
596
+ :fontColor, :fontBackgroundColor
597
+
598
+ plugins :Essentials, :Paragraph, :Bold, :Italic, :Underline, :Strikethrough,
599
+ :Subscript, :Superscript, :RemoveFormat, :List, :Link, :Font,
600
+ :FontFamily, :FontSize, :FontColor, :FontBackgroundColor, :SourceEditing, :Essentials, :Paragraph
601
+ end
602
+ end
603
+ end
604
+ ```
605
+
606
+ In order to use the preset in the view, you can pass it to the `ckeditor5_assets` helper method:
607
+
608
+ ```erb
609
+ <!-- app/views/demos/index.html.erb -->
610
+
611
+ <% content_for :head do %>
612
+ <%= ckeditor5_assets preset: @preset %>
613
+ <% end %>
614
+
615
+ <%= ckeditor5_editor %>
616
+ ```
617
+
575
618
  ## Including CKEditor 5 assets ๐Ÿ“ฆ
576
619
 
577
620
  To include CKEditor 5 assets in your application, you can use the `ckeditor5_assets` helper method. This method takes the version of CKEditor 5 as an argument and includes the necessary resources of the editor. Depending on the specified configuration, it includes the JS and CSS assets from the official CKEditor 5 CDN or one of the popular CDNs.
@@ -1329,7 +1372,21 @@ If you want to contribute to the gem, you can clone the repository and run the f
1329
1372
  ```sh
1330
1373
  gem install bundler -v 2.5.22
1331
1374
  bundle install
1332
- bundle exec guard
1375
+ bundle exec guard -g rails
1376
+ ```
1377
+
1378
+ ### Running tests ๐Ÿงช
1379
+
1380
+ You can run the tests using the following command:
1381
+
1382
+ ```sh
1383
+ bundle exec rspec
1384
+ ```
1385
+
1386
+ If you want to watch the tests, you can use the following command:
1387
+
1388
+ ```sh
1389
+ bundle exec guard -g rspec
1333
1390
  ```
1334
1391
 
1335
1392
  ## Trademarks ๐Ÿ“œ
@@ -43,7 +43,7 @@ module CKEditor5::Rails::Assets
43
43
 
44
44
  def window_scripts_tags
45
45
  @window_scripts_tags ||= safe_join(bundle.scripts.filter_map do |script|
46
- tag.script(src: script.url, nonce: true, async: true, crossorigin: 'anonymous') if script.window?
46
+ tag.script(src: script.url, nonce: true, crossorigin: 'anonymous') if script.window?
47
47
  end)
48
48
  end
49
49
 
@@ -39,7 +39,7 @@ module CKEditor5::Rails
39
39
  private
40
40
 
41
41
  def merge_with_editor_preset(preset, **kwargs)
42
- found_preset = Engine.base.presets[preset]
42
+ found_preset = Engine.find_preset(preset)
43
43
 
44
44
  if found_preset.blank?
45
45
  raise ArgumentError,
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CKEditor5::Rails
4
+ module Editor::Helpers::Config
5
+ def ckeditor5_element_ref(selector)
6
+ { '$element': selector }
7
+ end
8
+
9
+ def ckeditor5_preset(name = nil, &block)
10
+ return Engine.find_preset(name) if name
11
+
12
+ raise ArgumentError, 'Configuration block is required for preset definition' unless block_given?
13
+
14
+ CKEditor5::Rails::Presets::PresetBuilder.new(&block)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'config_helpers'
4
+
5
+ module CKEditor5::Rails
6
+ module Editor::Helpers::Editor
7
+ include Editor::Helpers::Config
8
+
9
+ class EditorContextError < StandardError; end
10
+ class PresetNotFoundError < ArgumentError; end
11
+ class InvalidEditableHeightError < ArgumentError; end
12
+
13
+ # Creates a CKEditor 5 editor instance
14
+ #
15
+ # @param preset [Symbol] High-level configuration preset that defines base editor setup,
16
+ # including editor type, plugins, and default configuration
17
+ # @param config [Hash] Editor-specific configuration that overrides preset defaults
18
+ # @param extra_config [Hash] Additional configuration to be merged with the base config
19
+ # @param type [Symbol] Editor type (:classic, :inline, :balloon, :decoupled, :multiroot),
20
+ # defaults to preset's type if not specified
21
+ # @param initial_data [String] Initial content for the editor
22
+ # @param watchdog [Boolean] Whether to enable the CKEditor watchdog feature
23
+ # @param editable_height [String, Integer] Height of the editable area (Classic editor only)
24
+ # @param html_attributes [Hash] Additional HTML attributes for the editor element
25
+ def ckeditor5_editor( # rubocop:disable Metrics/ParameterLists
26
+ preset: nil,
27
+ config: nil, extra_config: {}, type: nil,
28
+ initial_data: nil, watchdog: true,
29
+ editable_height: nil,
30
+ **html_attributes, &block
31
+ )
32
+ validate_editor_input!(initial_data, block)
33
+
34
+ controller_context = validate_and_get_editor_context!
35
+
36
+ preset = find_preset(preset || controller_context[:preset] || :default)
37
+ config = build_editor_config(preset, config, extra_config, initial_data)
38
+ type ||= preset.type
39
+
40
+ editor_props = Editor::Props.new(
41
+ controller_context, type, config,
42
+ watchdog: watchdog,
43
+ editable_height: editable_height
44
+ )
45
+
46
+ tag_attributes = html_attributes.merge(editor_props.to_attributes)
47
+
48
+ tag.send(:'ckeditor-component', **tag_attributes, &block)
49
+ end
50
+
51
+ def ckeditor5_editable(name = nil, **kwargs, &block)
52
+ tag.send(:'ckeditor-editable-component', name: name, **kwargs, &block)
53
+ end
54
+
55
+ def ckeditor5_ui_part(name, **kwargs, &block)
56
+ tag.send(:'ckeditor-ui-part-component', name: name, **kwargs, &block)
57
+ end
58
+
59
+ def ckeditor5_toolbar(**kwargs)
60
+ ckeditor5_ui_part('toolbar', **kwargs)
61
+ end
62
+
63
+ def ckeditor5_menubar(**kwargs)
64
+ ckeditor5_ui_part('menuBarView', **kwargs)
65
+ end
66
+
67
+ private
68
+
69
+ def validate_editor_input!(initial_data, block)
70
+ return unless initial_data && block
71
+
72
+ raise ArgumentError, 'Cannot pass initial data and block at the same time.'
73
+ end
74
+
75
+ def build_editor_config(preset, config, extra_config, initial_data)
76
+ editor_config = config || preset.config
77
+ editor_config = editor_config.deep_merge(extra_config)
78
+ editor_config[:initialData] = initial_data if initial_data
79
+ editor_config
80
+ end
81
+
82
+ def validate_and_get_editor_context!
83
+ unless defined?(@__ckeditor_context)
84
+ raise EditorContextError,
85
+ 'CKEditor installation context is not defined. ' \
86
+ 'Ensure ckeditor5_assets is called in the head section.'
87
+ end
88
+
89
+ @__ckeditor_context
90
+ end
91
+
92
+ def find_preset(preset)
93
+ Engine.find_preset(preset) or
94
+ raise PresetNotFoundError, "Preset #{preset} is not defined."
95
+ end
96
+ end
97
+ end
@@ -3,107 +3,9 @@
3
3
  require_relative 'props_plugin'
4
4
  require_relative 'props_inline_plugin'
5
5
  require_relative 'props'
6
- require_relative 'config_helpers'
7
6
 
8
- module CKEditor5::Rails
9
- module Editor::Helpers
10
- include Editor::ConfigHelpers
11
-
12
- class EditorContextError < StandardError; end
13
- class PresetNotFoundError < ArgumentError; end
14
- class InvalidEditableHeightError < ArgumentError; end
15
-
16
- def ckeditor5_editor( # rubocop:disable Metrics/ParameterLists
17
- config: nil, extra_config: {},
18
- type: nil, preset: nil,
19
- initial_data: nil, watchdog: true,
20
- editable_height: nil,
21
- **html_attributes, &block
22
- )
23
- validate_editor_input!(initial_data, block)
24
-
25
- controller_context = validate_and_get_editor_context!
26
-
27
- preset = resolve_editor_preset(preset || controller_context[:preset])
28
- config = build_editor_config(preset, config, extra_config, initial_data)
29
- type ||= preset.type
30
-
31
- validated_height = validate_editable_height(type, editable_height) || preset.editable_height
32
- editor_props = Editor::Props.new(controller_context, type, config, watchdog: watchdog)
33
-
34
- tag_attributes = html_attributes
35
- .merge(editor_props.to_attributes)
36
- .merge(validated_height ? { 'editable-height' => validated_height } : {})
37
-
38
- tag.send(:'ckeditor-component', **tag_attributes, &block)
39
- end
40
-
41
- def ckeditor5_editable(name = nil, **kwargs, &block)
42
- tag.send(:'ckeditor-editable-component', name: name, **kwargs, &block)
43
- end
44
-
45
- def ckeditor5_ui_part(name, **kwargs, &block)
46
- tag.send(:'ckeditor-ui-part-component', name: name, **kwargs, &block)
47
- end
48
-
49
- def ckeditor5_toolbar(**kwargs)
50
- ckeditor5_ui_part('toolbar', **kwargs)
51
- end
52
-
53
- def ckeditor5_menubar(**kwargs)
54
- ckeditor5_ui_part('menuBarView', **kwargs)
55
- end
56
-
57
- private
58
-
59
- def validate_editor_input!(initial_data, block)
60
- return unless initial_data && block
61
-
62
- raise ArgumentError, 'Cannot pass initial data and block at the same time.'
63
- end
64
-
65
- def resolve_editor_preset(preset_name)
66
- fetch_editor_preset(preset_name || :default)
67
- end
68
-
69
- def build_editor_config(preset, config, extra_config, initial_data)
70
- editor_config = config || preset.config
71
- editor_config = editor_config.deep_merge(extra_config)
72
- editor_config[:initialData] = initial_data if initial_data
73
- editor_config
74
- end
75
-
76
- def validate_and_get_editor_context!
77
- unless defined?(@__ckeditor_context)
78
- raise EditorContextError,
79
- 'CKEditor installation context is not defined. ' \
80
- 'Ensure ckeditor5_assets is called in the head section.'
81
- end
82
-
83
- @__ckeditor_context
84
- end
85
-
86
- def fetch_editor_preset(preset)
87
- Engine.base.presets[preset] or
88
- raise PresetNotFoundError, "Preset #{preset} is not defined."
89
- end
90
-
91
- def validate_editable_height(type, height)
92
- return nil if height.nil?
93
-
94
- unless type == :classic
95
- raise InvalidEditableHeightError,
96
- 'editable_height can be used only with ClassicEditor'
97
- end
98
-
99
- case height
100
- when String, /^\d+px$/ then height
101
- when Integer, /^\d+$/ then "#{height}px"
102
- else
103
- raise InvalidEditableHeightError,
104
- "editable_height must be an integer representing pixels or string ending with 'px'\n" \
105
- "(e.g. 500 or '500px'). Got: #{height.inspect}"
106
- end
107
- end
108
- end
7
+ module CKEditor5::Rails::Editor::Helpers
109
8
  end
9
+
10
+ require_relative 'helpers/config_helpers'
11
+ require_relative 'helpers/editor_helpers'
@@ -12,13 +12,14 @@ module CKEditor5::Rails::Editor
12
12
  multiroot: 'MultiRootEditor'
13
13
  }.freeze
14
14
 
15
- def initialize(controller_context, type, config, watchdog: true)
15
+ def initialize(controller_context, type, config, watchdog: true, editable_height: nil)
16
16
  raise ArgumentError, "Invalid editor type: #{type}" unless Props.valid_editor_type?(type)
17
17
 
18
18
  @controller_context = controller_context
19
19
  @watchdog = watchdog
20
20
  @type = type
21
21
  @config = config
22
+ @editable_height = normalize_editable_height(editable_height)
22
23
  end
23
24
 
24
25
  def to_attributes
@@ -34,7 +35,7 @@ module CKEditor5::Rails::Editor
34
35
 
35
36
  private
36
37
 
37
- attr_reader :controller_context, :watchdog, :type, :config
38
+ attr_reader :controller_context, :watchdog, :type, :config, :editable_height
38
39
 
39
40
  def serialized_attributes
40
41
  {
@@ -43,6 +44,7 @@ module CKEditor5::Rails::Editor
43
44
  config: serialize_config,
44
45
  watchdog: watchdog
45
46
  }
47
+ .merge(editable_height ? { 'editable-height' => editable_height } : {})
46
48
  end
47
49
 
48
50
  def serialize_translations
@@ -59,5 +61,23 @@ module CKEditor5::Rails::Editor
59
61
  .tap { |cfg| cfg[:licenseKey] = controller_context[:license_key] if controller_context[:license_key] }
60
62
  .to_json
61
63
  end
64
+
65
+ def normalize_editable_height(editable_height)
66
+ return nil if editable_height.nil?
67
+
68
+ unless type == :classic
69
+ raise InvalidEditableHeightError,
70
+ 'editable_height can be used only with ClassicEditor'
71
+ end
72
+
73
+ case editable_height
74
+ when String, /^\d+px$/ then editable_height
75
+ when Integer, /^\d+$/ then "#{editable_height}px"
76
+ else
77
+ raise InvalidEditableHeightError,
78
+ "editable_height must be an integer representing pixels or string ending with 'px'\n" \
79
+ "(e.g. 500 or '500px'). Got: #{editable_height.inspect}"
80
+ end
81
+ end
62
82
  end
63
83
  end
@@ -12,6 +12,7 @@ module CKEditor5::Rails
12
12
 
13
13
  initializer 'helper' do
14
14
  ActiveSupport.on_load(:action_view) { include Helpers }
15
+ ActiveSupport.on_load(:action_controller) { include Helpers }
15
16
  end
16
17
 
17
18
  initializer 'ckeditor5.simple_form', after: :load_config_initializers do
@@ -39,6 +40,12 @@ module CKEditor5::Rails
39
40
  proxy = ConfigurationProxy.new(config.ckeditor5)
40
41
  proxy.instance_eval(&block)
41
42
  end
43
+
44
+ def find_preset(preset)
45
+ return preset if preset.is_a?(CKEditor5::Rails::Presets::PresetBuilder)
46
+
47
+ Engine.base.presets[preset]
48
+ end
42
49
  end
43
50
 
44
51
  class ConfigurationProxy
@@ -7,7 +7,8 @@ require_relative 'context/helpers'
7
7
  module CKEditor5::Rails
8
8
  module Helpers
9
9
  include Cdn::Helpers
10
- include Editor::Helpers
10
+ include Editor::Helpers::Config
11
+ include Editor::Helpers::Editor
11
12
  include Context::Helpers
12
13
  end
13
14
  end
@@ -3,15 +3,15 @@
3
3
  module CKEditor5::Rails
4
4
  module Presets
5
5
  class PresetBuilder
6
- include Editor::ConfigHelpers
6
+ include Editor::Helpers::Config
7
7
 
8
8
  attr_reader :config
9
9
 
10
- def initialize
10
+ def initialize(&block)
11
11
  @version = nil
12
12
  @premium = false
13
13
  @cdn = :jsdelivr
14
- @translations = []
14
+ @translations = [:en]
15
15
  @license_key = nil
16
16
  @type = :classic
17
17
  @ckbox = nil
@@ -20,6 +20,8 @@ module CKEditor5::Rails
20
20
  plugins: [],
21
21
  toolbar: []
22
22
  }
23
+
24
+ instance_eval(&block) if block_given?
23
25
  end
24
26
 
25
27
  def premium?
@@ -13,7 +13,6 @@ class CKEditor5::Rails::Semver
13
13
  private
14
14
 
15
15
  def validate!
16
- raise ArgumentError, 'version must be a string' unless version.is_a?(String)
17
16
  raise ArgumentError, 'invalid version format' unless version.match?(/\A\d+\.\d+\.\d+\z/)
18
17
  end
19
18
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CKEditor5
4
4
  module Rails
5
- VERSION = '1.11.0'
5
+ VERSION = '1.12.0'
6
6
  end
7
7
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe CKEditor5::Rails::Cdn::UrlGenerator do
6
+ let(:test_class) do
7
+ Class.new do
8
+ include CKEditor5::Rails::Cdn::UrlGenerator
9
+
10
+ attr_writer :cdn
11
+ end
12
+ end
13
+
14
+ let(:instance) { test_class.new }
15
+
16
+ shared_examples 'a CDN provider' do |cdn, url_pattern|
17
+ before { instance.cdn = cdn }
18
+
19
+ it 'generates correct URL' do
20
+ expect(instance.create_cdn_url('ckeditor5', '34.1.0', 'ckeditor.js'))
21
+ .to eq(format(url_pattern, version: '34.1.0'))
22
+ end
23
+ end
24
+
25
+ describe '#create_cdn_url' do
26
+ context 'with open-source CDNs' do
27
+ it_behaves_like 'a CDN provider', :jsdelivr,
28
+ 'https://cdn.jsdelivr.net/npm/ckeditor5@%<version>s/dist/browser/ckeditor.js'
29
+
30
+ it_behaves_like 'a CDN provider', :unpkg,
31
+ 'https://unpkg.com/ckeditor5@%<version>s/dist/browser/ckeditor.js'
32
+
33
+ context 'with translations' do
34
+ it 'handles translation paths correctly for jsdelivr' do
35
+ instance.cdn = :jsdelivr
36
+ expect(instance.create_cdn_url('ckeditor5', '34.1.0', 'translations/pl.js'))
37
+ .to eq('https://cdn.jsdelivr.net/npm/ckeditor5@34.1.0/dist/translations/pl.js')
38
+ end
39
+
40
+ it 'handles translation paths correctly for unpkg' do
41
+ instance.cdn = :unpkg
42
+ expect(instance.create_cdn_url('ckeditor5', '34.1.0', 'translations/pl.js'))
43
+ .to eq('https://unpkg.com/ckeditor5@34.1.0/dist/translations/pl.js')
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'with commercial CDNs' do
49
+ it_behaves_like 'a CDN provider', :cloud,
50
+ 'https://cdn.ckeditor.com/ckeditor5/%<version>s/ckeditor.js'
51
+
52
+ it 'generates correct CKBox URL' do
53
+ instance.cdn = :ckbox
54
+ expect(instance.create_cdn_url('ckbox', '34.1.0', 'ckeditor.js'))
55
+ .to eq('https://cdn.ckbox.io/ckbox/34.1.0/ckeditor.js')
56
+ end
57
+ end
58
+
59
+ context 'with invalid configuration' do
60
+ it 'raises ArgumentError for unknown CDN provider' do
61
+ instance.cdn = :invalid_cdn
62
+ expect { instance.create_cdn_url('ckeditor5', '34.1.0', 'ckeditor.js') }
63
+ .to raise_error(ArgumentError, 'Unknown provider: invalid_cdn')
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe CKEditor5::Rails::Semver do
6
+ describe '#initialize' do
7
+ context 'with valid version string' do
8
+ it 'accepts version in x.y.z format' do
9
+ expect { described_class.new('1.2.3') }.not_to raise_error
10
+ end
11
+ end
12
+
13
+ context 'with invalid version' do
14
+ it 'raises error for numeric input' do
15
+ expect { described_class.new(123) }
16
+ .to raise_error(ArgumentError, 'invalid version format')
17
+ end
18
+
19
+ it 'raises error for invalid string format' do
20
+ invalid_versions = ['1', '1.2', '1.2.3.4', 'x.y.z', '1.2.x', '1.a.3']
21
+
22
+ invalid_versions.each do |version|
23
+ expect { described_class.new(version) }
24
+ .to raise_error(ArgumentError, 'invalid version format')
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#to_s' do
31
+ it 'returns the version string' do
32
+ version = '1.2.3'
33
+ semver = described_class.new(version)
34
+ expect(semver.to_s).to eq(version)
35
+ end
36
+ end
37
+
38
+ describe '#version' do
39
+ it 'returns the version string' do
40
+ version = '1.2.3'
41
+ semver = described_class.new(version)
42
+ expect(semver.version).to eq(version)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ require 'simplecov_json_formatter'
5
+
6
+ SimpleCov.start do
7
+ enable_coverage :branch
8
+ enable_coverage :line
9
+
10
+ add_filter 'sandbox/'
11
+ add_group 'Library', 'lib/'
12
+
13
+ track_files 'lib/**/*.rb'
14
+
15
+ # minimum_coverage 90
16
+ # minimum_coverage_by_file 80
17
+
18
+ formatters = [
19
+ SimpleCov::Formatter::HTMLFormatter,
20
+ SimpleCov::Formatter::JSONFormatter
21
+ ]
22
+
23
+ formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
24
+ end
25
+
26
+ ENV['RAILS_ENV'] ||= 'test'
27
+
28
+ require File.expand_path('../sandbox/config/application', __dir__)
29
+
30
+ require 'pry'
31
+ require 'spec_helper'
32
+ require 'rspec/rails'
33
+ require 'rspec/expectations'
34
+
35
+ Rails.application.initialize!
36
+
37
+ RSpec.configure do |config|
38
+ config.expect_with :rspec do |expectations|
39
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
40
+ end
41
+
42
+ config.mock_with :rspec do |mocks|
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ config.shared_context_metadata_behavior = :apply_to_host_groups
47
+ config.filter_run_when_matching :focus
48
+ config.disable_monkey_patching!
49
+
50
+ config.default_formatter = 'doc' if config.files_to_run.one?
51
+ config.profile_examples = 10
52
+
53
+ config.order = :random
54
+
55
+ Kernel.rand config.seed
56
+
57
+ config.before(:each) do
58
+ Rails.application.load_seed
59
+ end
60
+ 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.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiล„ski
@@ -57,8 +57,9 @@ files:
57
57
  - lib/ckeditor5/rails/cdn/url_generator.rb
58
58
  - lib/ckeditor5/rails/context/helpers.rb
59
59
  - lib/ckeditor5/rails/context/props.rb
60
- - lib/ckeditor5/rails/editor/config_helpers.rb
61
60
  - lib/ckeditor5/rails/editor/helpers.rb
61
+ - lib/ckeditor5/rails/editor/helpers/config_helpers.rb
62
+ - lib/ckeditor5/rails/editor/helpers/editor_helpers.rb
62
63
  - lib/ckeditor5/rails/editor/props.rb
63
64
  - lib/ckeditor5/rails/editor/props_inline_plugin.rb
64
65
  - lib/ckeditor5/rails/editor/props_plugin.rb
@@ -71,6 +72,9 @@ files:
71
72
  - lib/ckeditor5/rails/presets/toolbar_builder.rb
72
73
  - lib/ckeditor5/rails/semver.rb
73
74
  - lib/ckeditor5/rails/version.rb
75
+ - spec/lib/ckeditor5/rails/cdn/url_generator_spec.rb
76
+ - spec/lib/ckeditor5/rails/semver_spec.rb
77
+ - spec/spec_helper.rb
74
78
  homepage: https://github.com/Mati365/ckeditor5-rails
75
79
  licenses:
76
80
  - GPL-2.0
@@ -94,4 +98,7 @@ rubygems_version: 3.5.22
94
98
  signing_key:
95
99
  specification_version: 4
96
100
  summary: CKEditor 5 for Rails
97
- test_files: []
101
+ test_files:
102
+ - spec/lib/ckeditor5/rails/cdn/url_generator_spec.rb
103
+ - spec/lib/ckeditor5/rails/semver_spec.rb
104
+ - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CKEditor5::Rails
4
- module Editor::ConfigHelpers
5
- def ckeditor5_element_ref(selector)
6
- { '$element': selector }
7
- end
8
- end
9
- end