Class: CKEditor5::Rails::Editor::Props

Inherits:
Object
  • Object
show all
Defined in:
lib/ckeditor5/rails/editor/props.rb

Constant Summary collapse

EDITOR_TYPES =
{
  classic: 'ClassicEditor',
  inline: 'InlineEditor',
  balloon: 'BalloonEditor',
  decoupled: 'DecoupledEditor',
  multiroot: 'MultiRootEditor'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, config, bundle: nil, watchdog: true, editable_height: nil) ⇒ Props

Returns a new instance of Props.

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ckeditor5/rails/editor/props.rb', line 16

def initialize(
  type, config,
  bundle: nil,
  watchdog: true,
  editable_height: nil
)
  raise ArgumentError, "Invalid editor type: #{type}" unless Props.valid_editor_type?(type)

  @bundle = bundle
  @watchdog = watchdog
  @type = type
  @config = config
  @editable_height = EditableHeightNormalizer.new(type).normalize(editable_height)
end

Class Method Details

.valid_editor_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ckeditor5/rails/editor/props.rb', line 43

def self.valid_editor_type?(type)
  EDITOR_TYPES.key?(type)
end

Instance Method Details

#to_attributesObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ckeditor5/rails/editor/props.rb', line 31

def to_attributes
  {
    bundle: bundle&.to_json,
    plugins: serialize_plugins,
    config: serialize_config,
    watchdog: watchdog,
    type: EDITOR_TYPES[@type]
  }
    .merge(editable_height ? { 'editable-height': editable_height } : {})
    .transform_keys(&:to_sym)
end