ckeditor5 1.17.1 → 1.17.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.
- checksums.yaml +4 -4
- data/README.md +37 -7
- data/lib/ckeditor5/rails/cdn/helpers.rb +8 -1
- data/lib/ckeditor5/rails/presets/manager.rb +1 -1
- data/lib/ckeditor5/rails/presets/preset_builder.rb +5 -3
- data/lib/ckeditor5/rails/version.rb +1 -1
- data/spec/lib/ckeditor5/rails/cdn/helpers_spec.rb +35 -8
- data/spec/lib/ckeditor5/rails/presets/preset_builder_spec.rb +11 -5
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 789a4ca2ac0428fa31866a6fd99433577137e9ccbe64e321e86c20126814dc80
         | 
| 4 | 
            +
              data.tar.gz: f4d3bc6f16777dd8dc03c4e62aada4c772021fc72bc99eeecbc668ac0dcc39b6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: '02238ab74fc9982f48177b33bc20b59332ca58f9cb594868649e72ec5e504760d41e5a0ce4afee0cbeb5463335e34fb4303e5e30fd6b21abd96968a017ba715f'
         | 
| 7 | 
            +
              data.tar.gz: f4a331e7b9afca50f1063626a73c083ed521521333e7492eaf252bd30a360b435459fe5a8d321c4b5a4355c291272c2ee352a01bbd15d8c916434222fbdaa804
         | 
    
        data/README.md
    CHANGED
    
    | @@ -44,8 +44,9 @@ In your view: | |
| 44 44 | 
             
            <!-- app/views/demos/index.html.erb -->
         | 
| 45 45 |  | 
| 46 46 | 
             
            <% content_for :head do %>
         | 
| 47 | 
            -
              <!-- 📦 Adds importmap with CKEditor 5 assets.  | 
| 48 | 
            -
               | 
| 47 | 
            +
              <!-- 📦 Adds importmap with CKEditor 5 assets. -->
         | 
| 48 | 
            +
              <!-- 🌍 It'll automatically use your `I18n.locale` language. -->
         | 
| 49 | 
            +
              <%= ckeditor5_assets %>
         | 
| 49 50 | 
             
            <% end %>
         | 
| 50 51 |  | 
| 51 52 | 
             
            <!-- 🖋️ CKEditor 5 might be placed using simple view helper ... -->
         | 
| @@ -77,6 +78,11 @@ CKEditor5::Rails.configure do | |
| 77 78 |  | 
| 78 79 | 
             
              # Upload images to the server using the simple upload adapter, instead of Base64 encoding.
         | 
| 79 80 | 
             
              # simple_upload_adapter
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              # Specify global language for the editor.
         | 
| 83 | 
            +
              # It can be done here, in controller or in the view.
         | 
| 84 | 
            +
              # By default the `I18n.locale` is used.
         | 
| 85 | 
            +
              # language :pl
         | 
| 80 86 | 
             
            end
         | 
| 81 87 | 
             
            ```
         | 
| 82 88 |  | 
| @@ -149,6 +155,10 @@ For extending CKEditor's functionality, refer to the [plugins directory](https:/ | |
| 149 155 | 
             
              - [How to access editor instance? 🤔](#how-to-access-editor-instance-)
         | 
| 150 156 | 
             
              - [Common Tasks and Solutions 💡](#common-tasks-and-solutions-)
         | 
| 151 157 | 
             
                - [Setting Editor Language 🌐](#setting-editor-language-)
         | 
| 158 | 
            +
                  - [Setting the language in the assets helper](#setting-the-language-in-the-assets-helper)
         | 
| 159 | 
            +
                  - [Setting the language in the initializer](#setting-the-language-in-the-initializer)
         | 
| 160 | 
            +
                  - [Setting the language on the editor level](#setting-the-language-on-the-editor-level)
         | 
| 161 | 
            +
                  - [Preloading multiple translation packs](#preloading-multiple-translation-packs)
         | 
| 152 162 | 
             
                - [Integrating with Forms 📋](#integrating-with-forms-)
         | 
| 153 163 | 
             
                  - [Rails form builder integration](#rails-form-builder-integration)
         | 
| 154 164 | 
             
                  - [Simple form integration](#simple-form-integration)
         | 
| @@ -443,7 +453,7 @@ In order to set the language for the content, you can pass the `content` keyword | |
| 443 453 | 
             
            CKEditor5::Rails.configure do
         | 
| 444 454 | 
             
              # ... other configuration
         | 
| 445 455 |  | 
| 446 | 
            -
              language :pl
         | 
| 456 | 
            +
              language :pl, content: :en
         | 
| 447 457 | 
             
            end
         | 
| 448 458 | 
             
            ```
         | 
| 449 459 |  | 
| @@ -1089,7 +1099,7 @@ The `ckeditor5_editor` helper renders CKEditor 5 instances in your views. Before | |
| 1089 1099 |  | 
| 1090 1100 | 
             
            You can set the initial content of the editor using the `initial_data` keyword argument or by passing the content directly to the `ckeditor5_editor` helper block.
         | 
| 1091 1101 |  | 
| 1092 | 
            -
            The example below shows how to set the initial content of the editor using the `initial_data` keyword  | 
| 1102 | 
            +
            The example below shows how to set the initial content of the editor using the `initial_data` and `language` keyword arguments:
         | 
| 1093 1103 |  | 
| 1094 1104 | 
             
            ```erb
         | 
| 1095 1105 | 
             
            <!-- app/views/demos/index.html.erb -->
         | 
| @@ -1407,7 +1417,11 @@ This section covers frequent questions and scenarios when working with CKEditor | |
| 1407 1417 |  | 
| 1408 1418 | 
             
            ### Setting Editor Language 🌐
         | 
| 1409 1419 |  | 
| 1410 | 
            -
             | 
| 1420 | 
            +
            By default, CKEditor 5 uses the language specified in your `I18n.locale` configuration. However, you can override the language of the editor by passing the `language` keyword in few places.
         | 
| 1421 | 
            +
             | 
| 1422 | 
            +
            #### Setting the language in the assets helper
         | 
| 1423 | 
            +
             | 
| 1424 | 
            +
            Language specified here will be used for all editor instances on the page.
         | 
| 1411 1425 |  | 
| 1412 1426 | 
             
            ```erb
         | 
| 1413 1427 | 
             
            <!-- app/views/demos/index.html.erb -->
         | 
| @@ -1419,7 +1433,9 @@ You can set the language of the editor using the `language` keyword argument. Th | |
| 1419 1433 | 
             
            <%= ckeditor5_editor %>
         | 
| 1420 1434 | 
             
            ```
         | 
| 1421 1435 |  | 
| 1422 | 
            -
             | 
| 1436 | 
            +
            #### Setting the language in the initializer
         | 
| 1437 | 
            +
             | 
| 1438 | 
            +
            Language specified here will be used for all editor instances in your application.
         | 
| 1423 1439 |  | 
| 1424 1440 | 
             
            ```rb
         | 
| 1425 1441 | 
             
            # config/initializers/ckeditor5.rb
         | 
| @@ -1430,7 +1446,9 @@ CKEditor5::Rails.configure do | |
| 1430 1446 | 
             
            end
         | 
| 1431 1447 | 
             
            ```
         | 
| 1432 1448 |  | 
| 1433 | 
            -
             | 
| 1449 | 
            +
            #### Setting the language on the editor level
         | 
| 1450 | 
            +
             | 
| 1451 | 
            +
            Language specified here will be used only for this editor instance. Keep in mind that you have to load the translation pack in the assets helper using the `translations` initializer method.
         | 
| 1434 1452 |  | 
| 1435 1453 | 
             
            ```erb
         | 
| 1436 1454 | 
             
            <!-- app/views/demos/index.html.erb -->
         | 
| @@ -1438,6 +1456,18 @@ end | |
| 1438 1456 | 
             
            <%= ckeditor5_editor language: :pl %>
         | 
| 1439 1457 | 
             
            ```
         | 
| 1440 1458 |  | 
| 1459 | 
            +
            #### Preloading multiple translation packs
         | 
| 1460 | 
            +
             | 
| 1461 | 
            +
            You can preload multiple translation packs in the initializer using the `translations` method:
         | 
| 1462 | 
            +
             | 
| 1463 | 
            +
            ```rb
         | 
| 1464 | 
            +
            # config/initializers/ckeditor5.rb
         | 
| 1465 | 
            +
             | 
| 1466 | 
            +
            CKEditor5::Rails.configure do
         | 
| 1467 | 
            +
              translations :pl, :es
         | 
| 1468 | 
            +
            end
         | 
| 1469 | 
            +
            ```
         | 
| 1470 | 
            +
             | 
| 1441 1471 | 
             
            ### Integrating with Forms 📋
         | 
| 1442 1472 |  | 
| 1443 1473 | 
             
            You can integrate CKEditor 5 with Rails form builders like `form_for` or `simple_form`. The example below shows how to integrate CKEditor 5 with a Rails form using the `form_for` helper:
         | 
| @@ -44,7 +44,7 @@ module CKEditor5::Rails | |
| 44 44 |  | 
| 45 45 | 
             
                private
         | 
| 46 46 |  | 
| 47 | 
            -
                def merge_with_editor_preset(preset, **kwargs)
         | 
| 47 | 
            +
                def merge_with_editor_preset(preset, language: nil, **kwargs)
         | 
| 48 48 | 
             
                  found_preset = Engine.find_preset(preset)
         | 
| 49 49 |  | 
| 50 50 | 
             
                  if found_preset.blank?
         | 
| @@ -55,6 +55,13 @@ module CKEditor5::Rails | |
| 55 55 |  | 
| 56 56 | 
             
                  new_preset = found_preset.clone.merge_with_hash!(**kwargs)
         | 
| 57 57 |  | 
| 58 | 
            +
                  # Assign default language if not present
         | 
| 59 | 
            +
                  if language.present?
         | 
| 60 | 
            +
                    new_preset.language(language)
         | 
| 61 | 
            +
                  elsif !new_preset.language?
         | 
| 62 | 
            +
                    new_preset.language(I18n.locale)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 58 65 | 
             
                  %i[version type].each do |key|
         | 
| 59 66 | 
             
                    next if new_preset.public_send(key).present?
         | 
| 60 67 |  | 
| @@ -61,7 +61,7 @@ module CKEditor5::Rails | |
| 61 61 | 
             
                    end
         | 
| 62 62 | 
             
                  end
         | 
| 63 63 |  | 
| 64 | 
            -
                  def merge_with_hash!( | 
| 64 | 
            +
                  def merge_with_hash!(**overrides) # rubocop:disable Metrics/AbcSize
         | 
| 65 65 | 
             
                    @version = Semver.new(overrides[:version]) if overrides.key?(:version)
         | 
| 66 66 | 
             
                    @premium = overrides.fetch(:premium, premium)
         | 
| 67 67 | 
             
                    @cdn = overrides.fetch(:cdn, cdn)
         | 
| @@ -73,8 +73,6 @@ module CKEditor5::Rails | |
| 73 73 | 
             
                    @ckbox = overrides.fetch(:ckbox, ckbox) if overrides.key?(:ckbox) || ckbox
         | 
| 74 74 | 
             
                    @config = config.merge(overrides.fetch(:config, {}))
         | 
| 75 75 |  | 
| 76 | 
            -
                    language(language) if language
         | 
| 77 | 
            -
             | 
| 78 76 | 
             
                    self
         | 
| 79 77 | 
             
                  end
         | 
| 80 78 |  | 
| @@ -182,6 +180,10 @@ module CKEditor5::Rails | |
| 182 180 | 
             
                    builder
         | 
| 183 181 | 
             
                  end
         | 
| 184 182 |  | 
| 183 | 
            +
                  def language?
         | 
| 184 | 
            +
                    config[:language].present?
         | 
| 185 | 
            +
                  end
         | 
| 186 | 
            +
             | 
| 185 187 | 
             
                  def language(ui = nil, content: ui) # rubocop:disable Naming/MethodParameterName
         | 
| 186 188 | 
             
                    return config[:language] if ui.nil?
         | 
| 187 189 |  | 
| @@ -16,6 +16,10 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do | |
| 16 16 | 
             
                end
         | 
| 17 17 | 
             
              end
         | 
| 18 18 |  | 
| 19 | 
            +
              let(:context) do
         | 
| 20 | 
            +
                helper.instance_variable_get(:@__ckeditor_context)
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 19 23 | 
             
              let(:bundle_html) { '<script src="test.js"></script>' }
         | 
| 20 24 | 
             
              let(:serializer) do
         | 
| 21 25 | 
             
                instance_double(CKEditor5::Rails::Assets::AssetsBundleHtmlSerializer, to_html: bundle_html)
         | 
| @@ -37,7 +41,7 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do | |
| 37 41 | 
             
                      .with(
         | 
| 38 42 | 
             
                        instance_of(CKEditor5::Rails::Semver),
         | 
| 39 43 | 
             
                        'ckeditor5',
         | 
| 40 | 
            -
                        translations: [ | 
| 44 | 
            +
                        translations: %i[pl en],
         | 
| 41 45 | 
             
                        cdn: :cloud
         | 
| 42 46 | 
             
                      )
         | 
| 43 47 | 
             
                      .and_call_original
         | 
| @@ -61,7 +65,7 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do | |
| 61 65 | 
             
                        .with(
         | 
| 62 66 | 
             
                          instance_of(CKEditor5::Rails::Semver),
         | 
| 63 67 | 
             
                          'ckeditor5',
         | 
| 64 | 
            -
                          translations: [ | 
| 68 | 
            +
                          translations: %i[pl en],
         | 
| 65 69 | 
             
                          cdn: :cloud
         | 
| 66 70 | 
             
                        )
         | 
| 67 71 | 
             
                        .and_call_original
         | 
| @@ -71,7 +75,7 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do | |
| 71 75 | 
             
                        .with(
         | 
| 72 76 | 
             
                          instance_of(CKEditor5::Rails::Semver),
         | 
| 73 77 | 
             
                          'ckeditor5-premium-features',
         | 
| 74 | 
            -
                          translations: [ | 
| 78 | 
            +
                          translations: %i[pl en],
         | 
| 75 79 | 
             
                          cdn: :cloud
         | 
| 76 80 | 
             
                        )
         | 
| 77 81 | 
             
                        .and_call_original
         | 
| @@ -111,7 +115,7 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do | |
| 111 115 | 
             
                    CKEditor5::Rails::Presets::PresetBuilder.new do
         | 
| 112 116 | 
             
                      version '34.1.0'
         | 
| 113 117 | 
             
                      type :classic
         | 
| 114 | 
            -
                       | 
| 118 | 
            +
                      language :pl
         | 
| 115 119 | 
             
                      cdn :cloud
         | 
| 116 120 | 
             
                      license_key 'preset-license'
         | 
| 117 121 | 
             
                      premium false
         | 
| @@ -121,20 +125,43 @@ RSpec.describe CKEditor5::Rails::Cdn::Helpers do | |
| 121 125 | 
             
                  it 'allows overriding preset values' do
         | 
| 122 126 | 
             
                    helper.ckeditor5_assets(preset: :default, license_key: 'overridden-license')
         | 
| 123 127 |  | 
| 124 | 
            -
                    expect( | 
| 125 | 
            -
                      .to eq('overridden-license')
         | 
| 128 | 
            +
                    expect(context[:preset].license_key).to eq('overridden-license')
         | 
| 126 129 | 
             
                  end
         | 
| 127 130 |  | 
| 128 131 | 
             
                  it 'preserves non-overridden preset values' do
         | 
| 129 132 | 
             
                    helper.ckeditor5_assets(preset: :default, license_key: 'overridden-license')
         | 
| 130 | 
            -
                    preset_context =  | 
| 133 | 
            +
                    preset_context = context[:preset]
         | 
| 131 134 |  | 
| 132 135 | 
             
                    expect(preset_context.version).to eq('34.1.0')
         | 
| 133 136 | 
             
                    expect(preset_context.premium?).to be false
         | 
| 134 137 | 
             
                    expect(preset_context.cdn).to eq(:cloud)
         | 
| 135 | 
            -
                    expect(preset_context.translations).to eq([ | 
| 138 | 
            +
                    expect(preset_context.translations).to eq(%i[en pl])
         | 
| 136 139 | 
             
                    expect(preset_context.type).to eq(:classic)
         | 
| 137 140 | 
             
                  end
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                  it 'allows to override language using language parameter' do
         | 
| 143 | 
            +
                    preset.language(:en)
         | 
| 144 | 
            +
                    helper.ckeditor5_assets(preset: :default, language: :pl)
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                    expect(context[:preset].language).to eq({ ui: :pl, content: :pl })
         | 
| 147 | 
            +
                  end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                  it 'should not override language if it\'s specified in preset and not passed to helper' do
         | 
| 150 | 
            +
                    preset.language(:en)
         | 
| 151 | 
            +
                    helper.ckeditor5_assets(preset: :default)
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                    expect(context[:preset].language).to eq({ ui: :en, content: :en })
         | 
| 154 | 
            +
                  end
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                  it 'should use I18n.locale as default language if it\'s not specified in preset' do
         | 
| 157 | 
            +
                    preset.configure :language, nil
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                    allow(I18n).to receive(:locale).and_return(:pl)
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                    helper.ckeditor5_assets(preset: :default)
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                    expect(context[:preset].language).to eq({ ui: :pl, content: :pl })
         | 
| 164 | 
            +
                  end
         | 
| 138 165 | 
             
                end
         | 
| 139 166 |  | 
| 140 167 | 
             
                context 'with missing required parameters' do
         | 
| @@ -293,11 +293,6 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do | |
| 293 293 | 
             
                  expect(builder.merge_with_hash!(version: '35.0.0')).to eq(builder)
         | 
| 294 294 | 
             
                end
         | 
| 295 295 |  | 
| 296 | 
            -
                it 'merges language configuration' do
         | 
| 297 | 
            -
                  builder.merge_with_hash!(language: :pl)
         | 
| 298 | 
            -
                  expect(builder.config[:language]).to eq({ ui: :pl, content: :pl })
         | 
| 299 | 
            -
                end
         | 
| 300 | 
            -
             | 
| 301 296 | 
             
                it 'preserves existing values when not overridden' do
         | 
| 302 297 | 
             
                  builder.version '34.0.0'
         | 
| 303 298 | 
             
                  builder.translations :en, :pl
         | 
| @@ -328,6 +323,17 @@ RSpec.describe CKEditor5::Rails::Presets::PresetBuilder do | |
| 328 323 | 
             
                end
         | 
| 329 324 | 
             
              end
         | 
| 330 325 |  | 
| 326 | 
            +
              describe '#language?' do
         | 
| 327 | 
            +
                it 'returns false when language is not set' do
         | 
| 328 | 
            +
                  expect(builder.language?).to be false
         | 
| 329 | 
            +
                end
         | 
| 330 | 
            +
             | 
| 331 | 
            +
                it 'returns true when language is set' do
         | 
| 332 | 
            +
                  builder.language(:pl)
         | 
| 333 | 
            +
                  expect(builder.language?).to be true
         | 
| 334 | 
            +
                end
         | 
| 335 | 
            +
              end
         | 
| 336 | 
            +
             | 
| 331 337 | 
             
              describe '#language' do
         | 
| 332 338 | 
             
                it 'returns language config when called without arguments' do
         | 
| 333 339 | 
             
                  builder.language(:pl, content: :en)
         | 
    
        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.17. | 
| 4 | 
            +
              version: 1.17.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- | 
| 12 | 
            +
            date: 2024-11-27 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rails
         |