Class: CKEditor5::Rails::Presets::PresetBuilder
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Presets::PresetBuilder
- Includes:
- Editor::ConfigHelpers
- Defined in:
- lib/ckeditor5/rails/presets/preset_builder.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #cdn(cdn = nil, &block) ⇒ Object
- #ckbox(version = nil, theme: :lark) ⇒ Object
- #configure(key, value) ⇒ Object
- #editable_height(height = nil) ⇒ Object
- #gpl ⇒ Object
-
#initialize ⇒ PresetBuilder
constructor
A new instance of PresetBuilder.
- #inline_plugin(name, code) ⇒ Object
-
#language(ui, content: ui) ⇒ Object
rubocop:disable Naming/MethodParameterName.
- #license_key(license_key = nil) ⇒ Object
- #menubar(visible: true) ⇒ Object
- #plugin(name, **kwargs) ⇒ Object
- #plugins(*names, **kwargs) ⇒ Object
- #premium(premium = nil) ⇒ Object
- #to_h_with_overrides(**overrides) ⇒ Object
- #toolbar(*items, should_group_when_full: true, &block) ⇒ Object
- #translations(*translations) ⇒ Object
- #type(type = nil) ⇒ Object
- #version(version = nil) ⇒ Object
Methods included from Editor::ConfigHelpers
Constructor Details
#initialize ⇒ PresetBuilder
Returns a new instance of PresetBuilder.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 10 def initialize @version = nil @premium = false @cdn = :jsdelivr @translations = [] @license_key = nil @type = :classic @ckbox = nil @editable_height = nil @config = { plugins: [], toolbar: [] } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 8 def config @config end |
Instance Method Details
#cdn(cdn = nil, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 79 def cdn(cdn = nil, &block) return @cdn if cdn.nil? && block.nil? if block_given? unless block.arity == 3 raise ArgumentError, 'Block must accept exactly 3 arguments: bundle, version, path' end @cdn = block else @cdn = cdn end end |
#ckbox(version = nil, theme: :lark) ⇒ Object
44 45 46 47 48 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 44 def ckbox(version = nil, theme: :lark) return @ckbox if version.nil? @ckbox = { version: version, theme: theme } end |
#configure(key, value) ⇒ Object
101 102 103 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 101 def configure(key, value) @config[key] = value end |
#editable_height(height = nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 38 def editable_height(height = nil) return @editable_height if height.nil? @editable_height = height end |
#gpl ⇒ Object
56 57 58 59 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 56 def gpl license_key('GPL') premium(false) end |
#inline_plugin(name, code) ⇒ Object
125 126 127 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 125 def inline_plugin(name, code) @config[:plugins] << Editor::PropsInlinePlugin.new(name, code) end |
#language(ui, content: ui) ⇒ Object
rubocop:disable Naming/MethodParameterName
137 138 139 140 141 142 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 137 def language(ui, content: ui) # rubocop:disable Naming/MethodParameterName @config[:language] = { ui: ui, content: content } end |
#license_key(license_key = nil) ⇒ Object
50 51 52 53 54 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 50 def license_key(license_key = nil) return @license_key if license_key.nil? @license_key = license_key end |
#menubar(visible: true) ⇒ Object
105 106 107 108 109 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 105 def (visible: true) @config[:menuBar] = { isVisible: visible } end |
#plugin(name, **kwargs) ⇒ Object
129 130 131 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 129 def plugin(name, **kwargs) @config[:plugins] << Editor::PropsPlugin.new(name, **kwargs) end |
#plugins(*names, **kwargs) ⇒ Object
133 134 135 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 133 def plugins(*names, **kwargs) names.each { |name| plugin(name, **kwargs) } end |
#premium(premium = nil) ⇒ Object
61 62 63 64 65 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 61 def premium(premium = nil) return @premium if premium.nil? @premium = premium end |
#to_h_with_overrides(**overrides) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 25 def to_h_with_overrides(**overrides) { version: overrides.fetch(:version, version), premium: overrides.fetch(:premium, premium), cdn: overrides.fetch(:cdn, cdn), translations: overrides.fetch(:translations, translations), license_key: overrides.fetch(:license_key, license_key), type: overrides.fetch(:type, type), ckbox: overrides.fetch(:ckbox, ckbox), config: config.merge(overrides.fetch(:config, {})) } end |
#toolbar(*items, should_group_when_full: true, &block) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 111 def (*items, should_group_when_full: true, &block) if @config[:toolbar].blank? || !items.empty? @config[:toolbar] = { items: items, shouldNotGroupWhenFull: !should_group_when_full } end return unless block builder = ToolbarBuilder.new(@config[:toolbar]) builder.instance_eval(&block) end |
#translations(*translations) ⇒ Object
67 68 69 70 71 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 67 def translations(*translations) return @translations if translations.empty? @translations = translations end |
#type(type = nil) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 94 def type(type = nil) return @type if type.nil? raise ArgumentError, "Invalid editor type: #{type}" unless Editor::Props.valid_editor_type?(type) @type = type end |