Sha256: 2a47955c3e3dfc0f2cb4fd65aad3d1412456b9d6bc28aab24d50546abd9384a2
Contents?: true
Size: 1.48 KB
Versions: 16
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true require_relative 'props_plugin' module CKEditor5::Rails::Editor class Props EDITOR_TYPES = { classic: 'ClassicEditor', inline: 'InlineEditor', balloon: 'BalloonEditor', decoupled: 'DecoupledEditor', multiroot: 'MultiRootEditor' }.freeze def initialize(controller_context, type, config, watchdog: true) raise ArgumentError, "Invalid editor type: #{type}" unless Props.valid_editor_type?(type) @controller_context = controller_context @watchdog = watchdog @type = type @config = config end def to_attributes { type: EDITOR_TYPES[@type], **serialized_attributes } end def self.valid_editor_type?(type) EDITOR_TYPES.key?(type) end private attr_reader :controller_context, :watchdog, :type, :config def serialized_attributes { translations: serialize_translations, plugins: serialize_plugins, config: serialize_config, watchdog: watchdog } end def serialize_translations controller_context[:bundle].translations_scripts.map(&:to_h).to_json end def serialize_plugins (config[:plugins] || []).map { |plugin| PropsPlugin.normalize(plugin).to_h }.to_json end def serialize_config config .except(:plugins) .tap { |cfg| cfg[:licenseKey] = controller_context[:license_key] if controller_context[:license_key] } .to_json end end end
Version data entries
16 entries across 16 versions & 1 rubygems