Class: CKEditor5::Rails::Editor::PropsPatchPlugin

Inherits:
PropsInlinePlugin show all
Defined in:
lib/ckeditor5/rails/editor/props_patch_plugin.rb

Instance Attribute Summary collapse

Attributes inherited from PropsInlinePlugin

#code

Attributes inherited from PropsBasePlugin

#assets_bundle, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PropsInlinePlugin

#compress!, #to_h

Methods inherited from PropsBasePlugin

normalize, #preload_assets_bundle, #to_h

Constructor Details

#initialize(name, code, min_version: nil, max_version: nil) ⇒ PropsPatchPlugin

Returns a new instance of PropsPatchPlugin.



10
11
12
13
14
15
16
17
# File 'lib/ckeditor5/rails/editor/props_patch_plugin.rb', line 10

def initialize(name, code, min_version: nil, max_version: nil)
  super(name, code)

  @min_version = min_version && CKEditor5::Rails::Semver.new(min_version)
  @max_version = max_version && CKEditor5::Rails::Semver.new(max_version)

  compress!
end

Instance Attribute Details

#max_versionObject (readonly)

Returns the value of attribute max_version.



8
9
10
# File 'lib/ckeditor5/rails/editor/props_patch_plugin.rb', line 8

def max_version
  @max_version
end

#min_versionObject (readonly)

Returns the value of attribute min_version.



8
9
10
# File 'lib/ckeditor5/rails/editor/props_patch_plugin.rb', line 8

def min_version
  @min_version
end

Class Method Details

.applicable_for_version?(editor_version, min_version: nil, max_version: nil) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
# File 'lib/ckeditor5/rails/editor/props_patch_plugin.rb', line 19

def self.applicable_for_version?(editor_version, min_version: nil, max_version: nil)
  return true if min_version.nil? && max_version.nil?

  current_version = CKEditor5::Rails::Semver.new(editor_version)

  min_check = min_version.nil? || current_version >= CKEditor5::Rails::Semver.new(min_version)
  max_check = max_version.nil? || current_version <= CKEditor5::Rails::Semver.new(max_version)

  min_check && max_check
end

Instance Method Details

#applicable_for_version?(editor_version) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/ckeditor5/rails/editor/props_patch_plugin.rb', line 30

def applicable_for_version?(editor_version)
  self.class.applicable_for_version?(
    editor_version,
    min_version: @min_version&.to_s,
    max_version: @max_version&.to_s
  )
end