Sha256: b358bb243de14a8c2ece12c3364e1cd43a5069fc77fb6a0a03dec8015b934ae4

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require_relative '../editor/props_external_plugin'

module CKEditor5::Rails::Plugins
  class WProofreader < CKEditor5::Rails::Editor::PropsExternalPlugin
    DEFAULT_VERSION = '3.1.2'
    DEFAULT_CDN = 'https://cdn.jsdelivr.net/npm/@webspellchecker/wproofreader-ckeditor5'

    def initialize(version: nil, cdn: nil)
      cdn ||= DEFAULT_CDN
      version ||= DEFAULT_VERSION

      script_url = "#{cdn}@#{version}/dist/browser/index.js"
      style_url = "#{cdn}@#{version}/dist/browser/index.css"

      super(
        :WProofreader,
        script: script_url,
        import_as: 'WProofreader',
        stylesheets: [style_url],
      )
    end
  end

  # Sync I18n language from editor to WProofreader plugin
  class WProofreaderSync < CKEditor5::Rails::Editor::PropsInlinePlugin
    PLUGIN_CODE = <<~JS
      const CORRECTION_LANGUAGES = [
        'en_US', 'en_GB', 'pt_BR', 'da_DK',
        'nl_NL', 'en_CA', 'fi_FI', 'fr_FR',
        'fr_CA', 'de_DE', 'el_GR', 'it_IT',
        'nb_NO', 'pt_PT', 'es_ES', 'sv_SE',
        'uk_UA', 'auto'
      ];

      export default function WProofreaderSync(editor) {
        const wproofreaderConfig = editor.config.get('wproofreader');
        const editorLangCode = (() => {
          const config = editor.config.get('language');

          return config.content || config.ui;
        })();

        if (!wproofreaderConfig || !editorLangCode) {
          return;
        }

        const lang = CORRECTION_LANGUAGES.find(
          lang => lang.startsWith(editorLangCode.toLowerCase())
        ) || 'auto';

        editor.config.set('wproofreader', {
          lang,
          localization: editorLangCode,
          ...wproofreaderConfig,
        });
      }
    JS

    def initialize
      super(:WProofreaderSync, PLUGIN_CODE)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ckeditor5-1.19.5 lib/ckeditor5/rails/plugins/wproofreader.rb
ckeditor5-1.19.4 lib/ckeditor5/rails/plugins/wproofreader.rb
ckeditor5-1.19.3 lib/ckeditor5/rails/plugins/wproofreader.rb
ckeditor5-1.19.2 lib/ckeditor5/rails/plugins/wproofreader.rb
ckeditor5-1.19.1 lib/ckeditor5/rails/plugins/wproofreader.rb
ckeditor5-1.19.0 lib/ckeditor5/rails/plugins/wproofreader.rb
ckeditor5-1.18.3 lib/ckeditor5/rails/plugins/wproofreader.rb