ckeditor5 1.5.4 → 1.6.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 +16 -0
- data/lib/ckeditor5/rails/cdn/helpers.rb +2 -1
- data/lib/ckeditor5/rails/editor/helpers.rb +22 -9
- data/lib/ckeditor5/rails/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4936a08e0bc4d84574d2f692c6efe59e683cac2be8d87cc2ef51cdd2ad7846e8
         | 
| 4 | 
            +
              data.tar.gz: d1a65da5eb7795fcd85bb258a067afb6990c6f6f7ea6fe5359e11cc767883139
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9590a33cd9a2caf0c191255d7efa154a7bbbde8857ee8b40bf19cf9ae03411220230cbc5cf1f608aabf1ba3dcb8a49cb9ceb768553a8655efd139c0e9e98c110
         | 
| 7 | 
            +
              data.tar.gz: 2d2c6853bf4a09e01da3fb83f44ed711b8ee96de4bd9e2bf0e47c1519b04169507e56e403f012731dd6c402c3e7b8196b3e42cc833d6689c3bc6dbe2e6c5abfc
         | 
    
        data/README.md
    CHANGED
    
    | @@ -2,6 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            [](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
         | 
| 4 4 | 
             
            
         | 
| 5 | 
            +
            
         | 
| 5 6 | 
             
            [](http://makeapullrequest.com)
         | 
| 6 7 | 
             
            
         | 
| 7 8 | 
             
            [](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:
         | 
| @@ -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( | 
| 12 | 
            +
                def ckeditor5_editor(
         | 
| 13 13 | 
             
                  config: nil, extra_config: {},
         | 
| 14 | 
            -
                  type: nil, preset:  | 
| 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 | 
            -
                   | 
| 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,
         |