ckeditor5 1.2.0 → 1.3.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: '028a09c0049e3eb489434b0447796369924801d0f5273a400e9783dbd3a8a70c'
4
- data.tar.gz: e9a3c65f03a85b1361b612c85b00c5cb9d1d8385eeca716c5cea4f0e5817474b
3
+ metadata.gz: c7b18841155e113a731b8b81c953fd13547a9ed25f3d5be662786297fc6a985a
4
+ data.tar.gz: 8894ffe8876faad795fab39bdae58c03fdfb4dd014337c30c6573e20c881b74b
5
5
  SHA512:
6
- metadata.gz: 5bf454b35f45aca3a44a2463d007cea579714c835d82edf7e6ed351db3c93a94aff59489bab7cea69cd78853acf50473ad9f7cf64819ee5c3c5bc5c0ef2d20a8
7
- data.tar.gz: e394db6e299f6a48c88f50a306500bcae7c87c0eae6092bdf44c7f62e4a179da542f7299448db18045c086047da16a5818f3915416d9b10bb00747bda9e431ce
6
+ metadata.gz: f2abcac7b7c28c763b095b83078ce25b6d081b59120a8a8e40f48a1711334d9ac59828bd047bb3d727bc85c2e2ce2325a263c18941485f1c062fa98ddb789b22
7
+ data.tar.gz: e7d0c636c623904202bb3c6a18e5196c90f5c39bffd18f9a24749e764e338032a7ba8f2c2d0367e24e337b8ea03c616fb2a8308b95deae5f2a81f37ca0199ba8
data/README.md CHANGED
@@ -39,11 +39,9 @@ In your view:
39
39
 
40
40
  <% content_for :head do %>
41
41
  <%= ckeditor5_assets %>
42
- <!-- or using inline config: ckeditor5_assets version: '43.3.0', premium: false -->
43
42
  <% end %>
44
43
 
45
- <%= ckeditor5_editor style: 'width: 600px', initial_data: '<YOUR DATA>' %>
46
- <!-- or using inline config: ckeditor5_editor type: :classic, config: { toolbar: [:Bold, :Italic] }, ... -->
44
+ <%= ckeditor5_editor %>
47
45
  ```
48
46
 
49
47
  Voilà! You have CKEditor 5 integrated with your Rails application. 🎉
@@ -55,6 +53,7 @@ Voilà! You have CKEditor 5 integrated with your Rails application. 🎉
55
53
  - [Table of Contents 📚](#table-of-contents-)
56
54
  - [Presets 🎨](#presets-)
57
55
  - [Available Configuration Methods ⚙️](#available-configuration-methods-️)
56
+ - [`cdn(cdn = nil, &block)` method](#cdncdn--nil-block-method)
58
57
  - [`version(version)` method](#versionversion-method)
59
58
  - [`gpl` method](#gpl-method)
60
59
  - [`license_key(key)` method](#license_keykey-method)
@@ -142,21 +141,48 @@ CKEditor5::Rails.configure do |config|
142
141
 
143
142
  toolbar do
144
143
  remove :underline, :heading
145
-
146
- # prepend :underline
147
- # append :heading
148
144
  end
149
145
  end
150
146
  end
151
147
  ```
152
148
 
153
- Configuration of the editor can be complex, and it's recommended to use the CKEditor 5 [online builder](https://ckeditor.com/ckeditor-5/online-builder/) to generate the configuration. It allows you to select the features you want to include and generate the configuration code in JavaScript format. Keep in mind that you need to convert the JavaScript configuration to Ruby format before using it in this gem.
149
+ Configuration of the editor can be complex, and it's recommended to use the [CKEditor 5 online builder](https://ckeditor.com/ckeditor-5/online-builder/) to generate the configuration. It allows you to select the features you want to include and generate the configuration code in JavaScript format. Keep in mind that you need to convert the JavaScript configuration to Ruby format before using it in this gem.
154
150
 
155
151
  ### Available Configuration Methods ⚙️
156
152
 
157
153
  <details>
158
154
  <summary>Expand to show available methods 📖</summary>
159
155
 
156
+ #### `cdn(cdn = nil, &block)` method
157
+
158
+ Defines the CDN to be used for CKEditor 5 assets. The example below shows how to set the CDN to `:jsdelivr`:
159
+
160
+ ```rb
161
+ # config/initializers/ckeditor5.rb
162
+
163
+ config.presets.define :custom do
164
+ # ... other configuration
165
+
166
+ cdn :jsdelivr
167
+ end
168
+ ```
169
+
170
+ It also allows you to define a custom CDN by passing a block with the bundle, version, and path arguments. The example below shows how to define it for the `jsdelivr` CDN:
171
+
172
+ ```rb
173
+ # config/initializers/ckeditor5.rb
174
+
175
+ config.presets.define :custom do
176
+ # ... other configuration
177
+
178
+ cdn do |bundle, version, path|
179
+ base_url = "https://cdn.jsdelivr.net/npm/#{bundle}@#{version}/dist"
180
+
181
+ "#{base_url}/#{path.start_with?('translations/') ? '' : 'browser/'}#{path}"
182
+ end
183
+ end
184
+ ```
185
+
160
186
  #### `version(version)` method
161
187
 
162
188
  Defines the version of CKEditor 5 to be used. The example below shows how to set the version to `43.2.0`:
@@ -878,34 +904,25 @@ The example below shows how to define a custom plugin that allows toggling the h
878
904
  config.presets.define :custom do
879
905
  # ... other configuration
880
906
 
881
- # 1. You can define it inline like below or in a separate file.
882
-
883
- # In case if plugin is located in external file (recommended), you can simply import it:
884
-
885
- # inline_plugin :MyCustomPlugin, <<~JS
886
- # import MyPlugin from 'app/javascript/custom_plugins/highlight.js';
887
- # export default MyPlugin;
888
- # JS
889
-
890
- # 2. You can also use "window_name" option to import plugin from window object:
907
+ # 1. You can also use "window_name" option to import plugin from window object:
891
908
 
892
909
  # plugin :MyPlugin, window_name: 'MyPlugin'
893
910
 
894
- # 3. Create JavaScript file in app/javascript/custom_plugins/highlight.js:
895
- # You can also use "plugin" to import plugin from file using 'import_name' option.
896
- # Your `my-custom-plugin` must be present in import map.
911
+ # 2. Create JavaScript file in app/javascript/custom_plugins/highlight.js,
912
+ # add it to import map and then load it in initializer:
897
913
 
898
914
  # plugin :MyCustomPlugin, import_name: 'my-custom-plugin'
899
915
 
900
- # 4 Create JavaScript file in app/javascript/custom_plugins/highlight.js:
916
+ # 3 Create JavaScript file in app/javascript/custom_plugins/highlight.js
917
+ # and then load it in initializer:
901
918
 
902
919
  # In Ruby initializer you can also load plugin code directly from file:
903
- plugin :MyCustomPlugin, File.read(
920
+ inline_plugin :MyCustomPlugin, File.read(
904
921
  Rails.root.join('app/javascript/custom_plugins/highlight.js')
905
922
  )
906
923
 
907
- # 5. Or even define it inline:
908
- # plugin :MyCustomPlugin, <<~JS
924
+ # 4. Or even define it inline:
925
+ # inline_plugin :MyCustomPlugin, <<~JS
909
926
  # import { Plugin } from 'ckeditor5';
910
927
  #
911
928
  # export default class MyCustomPlugin extends Plugin {
@@ -19,8 +19,11 @@ module CKEditor5::Rails::Cdn
19
19
  }.freeze
20
20
 
21
21
  CDN_COMMERCIAL_GENERATORS = {
22
- cloud: ->(bundle, version, path) { "https://cdn.ckeditor.com/#{bundle}/#{version}/#{path}" },
23
- ckbox: ->(bundle, version, path) { "https://cdn.ckbox.io/#{bundle}/#{version}/#{path}" }
22
+ cloud: lambda { |bundle, version, path|
23
+ domain = bundle == 'ckbox' ? 'ckbox.io' : 'ckeditor.com'
24
+
25
+ "https://cdn.#{domain}/#{bundle}/#{version}/#{path}"
26
+ }
24
27
  }.freeze
25
28
 
26
29
  included do
@@ -28,7 +31,7 @@ module CKEditor5::Rails::Cdn
28
31
  end
29
32
 
30
33
  def create_cdn_url(bundle, version, path)
31
- generator = CDN_THIRD_PARTY_GENERATORS[cdn] || CDN_COMMERCIAL_GENERATORS[cdn]
34
+ generator = CDN_THIRD_PARTY_GENERATORS[cdn] || CDN_COMMERCIAL_GENERATORS[cdn] || cdn
32
35
 
33
36
  raise ArgumentError, "Unknown provider: #{cdn}" unless generator
34
37
 
@@ -67,10 +67,19 @@ module CKEditor5::Rails
67
67
  @version = Semver.new(version)
68
68
  end
69
69
 
70
- def cdn(cdn = nil)
71
- return @cdn if cdn.nil?
72
-
73
- @cdn = cdn
70
+ def cdn(cdn = nil, &block)
71
+ return @cdn if cdn.nil? && block.nil?
72
+
73
+ if block_given?
74
+ unless block.arity == 3
75
+ raise ArgumentError,
76
+ 'Block must accept exactly 3 arguments: bundle, version, path'
77
+ end
78
+
79
+ @cdn = block
80
+ else
81
+ @cdn = cdn
82
+ end
74
83
  end
75
84
 
76
85
  def type(type = nil)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CKEditor5::Rails
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  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.2.0
4
+ version: 1.3.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: 2024-11-01 00:00:00.000000000 Z
12
+ date: 2024-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails