Sha256: 9457875ab4166001813fe935b00e3ff327d0442de6133f6f5debe1b294e6c1ec

Contents?: true

Size: 970 Bytes

Versions: 25

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

module CKEditor5::Rails::Editor
  class PropsPlugin
    delegate :to_h, to: :import_meta

    def initialize(name, premium: false, **js_import_meta)
      @name = name
      @js_import_meta = if js_import_meta.empty?
                          { import_name: premium ? 'ckeditor5-premium-features' : 'ckeditor5' }
                        else
                          js_import_meta
                        end
    end

    def self.normalize(plugin)
      case plugin
      when String, Symbol then new(plugin)
      when PropsPlugin, PropsInlinePlugin then plugin
      else raise ArgumentError, "Invalid plugin: #{plugin}"
      end
    end

    def to_h
      meta = ::CKEditor5::Rails::Assets::JSImportMeta.new(
        import_as: js_import_meta[:window_name] ? nil : name,
        **js_import_meta
      ).to_h

      meta.merge!({ type: :external })
      meta
    end

    private

    attr_reader :name, :js_import_meta
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ckeditor5-1.12.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.11.1 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.11.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.10.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.9.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.8.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.7.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.6.1 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.6.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.5.4 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.5.3 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.5.2 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.5.1 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.5.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.4.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.3.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.2.0 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.1.7 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.1.6 lib/ckeditor5/rails/editor/props_plugin.rb
ckeditor5-1.1.5 lib/ckeditor5/rails/editor/props_plugin.rb