ckeditor5 1.5.4 → 1.6.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: 482179142a7c42597ead0126fe8eedb8c2ca1ae5e33427e7c2438feea952cc40
4
- data.tar.gz: 7fa425d5018e6a804e05780958a040cc03b946853f84fe666e1d0fe6df8b0512
3
+ metadata.gz: 4936a08e0bc4d84574d2f692c6efe59e683cac2be8d87cc2ef51cdd2ad7846e8
4
+ data.tar.gz: d1a65da5eb7795fcd85bb258a067afb6990c6f6f7ea6fe5359e11cc767883139
5
5
  SHA512:
6
- metadata.gz: 5922019eda63b05842228e06acc45d016d4489a568b5f023a756b5fc6c7355ff58f02523101b44b9066f077fe820d336ca9314a8404ad6282763d71dde4b99af
7
- data.tar.gz: a91192a64da0d0c20f8ee8e5125e2c1b3a6e1e44c58a6fad76bc1dc9e1ef60a5e91b023f6cac551d4a615ae692cf6ced42ebf966e9ddbaae6caf64002a505361
6
+ metadata.gz: 9590a33cd9a2caf0c191255d7efa154a7bbbde8857ee8b40bf19cf9ae03411220230cbc5cf1f608aabf1ba3dcb8a49cb9ceb768553a8655efd139c0e9e98c110
7
+ data.tar.gz: 2d2c6853bf4a09e01da3fb83f44ed711b8ee96de4bd9e2bf0e47c1519b04169507e56e403f012731dd6c402c3e7b8196b3e42cc833d6689c3bc6dbe2e6c5abfc
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
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
+ ![Gem Total Downloads](https://img.shields.io/gem/dt/ckeditor5?style=flat-square&color=orange)
5
6
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg?style=flat-square)](http://makeapullrequest.com)
6
7
  ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/mati365/ckeditor5-rails?style=flat-square)
7
8
  [![GitHub issues](https://img.shields.io/github/issues/mati365/ckeditor5-rails?style=flat-square)](https://github.com/Mati365/ckeditor5-rails/issues)
@@ -566,6 +567,9 @@ To specify a custom preset, you need to pass the `preset` keyword argument with
566
567
  <% content_for :head do %>
567
568
  <%= ckeditor5_assets preset: :custom %>
568
569
  <% end %>
570
+
571
+ <%-# This editor will use `custom` preset defined in `ckeditor5_assets` above %>
572
+ <%= ckeditor5_editor %>
569
573
  ```
570
574
 
571
575
  In order to define such preset, you can use the following configuration:
@@ -584,6 +588,18 @@ CKEditor5::Rails.configure do
584
588
  end
585
589
  ```
586
590
 
591
+ :warning: Keep in mind that all `ckeditor5_editor` helpers will use the configuration from the preset defined in the `ckeditor5_assets`. If you want to use a different preset for a specific editor, you can pass the `preset` keyword argument to the `ckeditor5_editor` helper.
592
+
593
+ ```erb
594
+ <!-- app/views/demos/index.html.erb -->
595
+
596
+ <% content_for :head do %>
597
+ <%= ckeditor5_assets preset: :custom %>
598
+ <% end %>
599
+
600
+ <%= ckeditor5_editor preset: :default %>
601
+ ```
602
+
587
603
  #### Inline preset definition
588
604
 
589
605
  It's possible to define the preset directly in the `ckeditor5_assets` helper method. It allows you to dynamically specify version, cdn provider or even translations in the view. The example below inherits the default preset and adds Polish translations and other options:
@@ -23,7 +23,8 @@ module CKEditor5::Rails
23
23
 
24
24
  @__ckeditor_context = {
25
25
  license_key: license_key,
26
- bundle: bundle
26
+ bundle: bundle,
27
+ preset: preset
27
28
  }
28
29
 
29
30
  Assets::AssetsBundleHtmlSerializer.new(bundle).to_html
@@ -9,23 +9,19 @@ module CKEditor5::Rails
9
9
  class EditorContextError < StandardError; end
10
10
  class PresetNotFoundError < ArgumentError; end
11
11
 
12
- def ckeditor5_editor( # rubocop:disable Metrics/ParameterLists
12
+ def ckeditor5_editor(
13
13
  config: nil, extra_config: {},
14
- type: nil, preset: :default,
14
+ type: nil, preset: nil,
15
15
  initial_data: nil, watchdog: true,
16
16
  **html_attributes, &block
17
17
  )
18
+ validate_editor_input!(initial_data, block)
18
19
  controller_context = validate_and_get_editor_context!
19
- preset = fetch_editor_preset(preset)
20
20
 
21
- config ||= preset.config
21
+ preset = resolve_editor_preset(preset || controller_context[:preset])
22
+ config = build_editor_config(preset, config, extra_config, initial_data)
22
23
  type ||= preset.type
23
24
 
24
- config = config.deep_merge(extra_config)
25
- config[:initialData] = initial_data if initial_data
26
-
27
- raise ArgumentError, 'Cannot pass initial data and block at the same time.' if initial_data && block
28
-
29
25
  editor_props = Editor::Props.new(
30
26
  controller_context, type, config,
31
27
  watchdog: watchdog
@@ -52,6 +48,23 @@ module CKEditor5::Rails
52
48
 
53
49
  private
54
50
 
51
+ def validate_editor_input!(initial_data, block)
52
+ return unless initial_data && block
53
+
54
+ raise ArgumentError, 'Cannot pass initial data and block at the same time.'
55
+ end
56
+
57
+ def resolve_editor_preset(preset_name)
58
+ fetch_editor_preset(preset_name || :default)
59
+ end
60
+
61
+ def build_editor_config(preset, config, extra_config, initial_data)
62
+ editor_config = config || preset.config
63
+ editor_config = editor_config.deep_merge(extra_config)
64
+ editor_config[:initialData] = initial_data if initial_data
65
+ editor_config
66
+ end
67
+
55
68
  def validate_and_get_editor_context!
56
69
  unless defined?(@__ckeditor_context)
57
70
  raise EditorContextError,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CKEditor5
4
4
  module Rails
5
- VERSION = '1.5.4'
5
+ VERSION = '1.6.0'
6
6
  end
7
7
  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.5.4
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński