Class: CKEditor5::Rails::Presets::PresetBuilder
- Inherits:
-
Object
- Object
- CKEditor5::Rails::Presets::PresetBuilder
- 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
- #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
Constructor Details
#initialize ⇒ PresetBuilder
Returns a new instance of PresetBuilder.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 8 def initialize @version = nil @premium = false @cdn = :jsdelivr @translations = [] @license_key = nil @type = :classic @ckbox = nil @config = { plugins: [], toolbar: [] } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 6 def config @config end |
Instance Method Details
#cdn(cdn = nil, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 70 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
35 36 37 38 39 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 35 def ckbox(version = nil, theme: :lark) return @ckbox if version.nil? @ckbox = { version: version, theme: theme } end |
#configure(key, value) ⇒ Object
92 93 94 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 92 def configure(key, value) @config[key] = value end |
#gpl ⇒ Object
47 48 49 50 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 47 def gpl license_key('GPL') premium(false) end |
#inline_plugin(name, code) ⇒ Object
116 117 118 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 116 def inline_plugin(name, code) @config[:plugins] << Editor::PropsInlinePlugin.new(name, code) end |
#language(ui, content: ui) ⇒ Object
rubocop:disable Naming/MethodParameterName
128 129 130 131 132 133 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 128 def language(ui, content: ui) # rubocop:disable Naming/MethodParameterName @config[:language] = { ui: ui, content: content } end |
#license_key(license_key = nil) ⇒ Object
41 42 43 44 45 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 41 def license_key(license_key = nil) return @license_key if license_key.nil? @license_key = license_key end |
#menubar(visible: true) ⇒ Object
96 97 98 99 100 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 96 def (visible: true) @config[:menuBar] = { isVisible: visible } end |
#plugin(name, **kwargs) ⇒ Object
120 121 122 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 120 def plugin(name, **kwargs) @config[:plugins] << Editor::PropsPlugin.new(name, **kwargs) end |
#plugins(*names, **kwargs) ⇒ Object
124 125 126 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 124 def plugins(*names, **kwargs) names.each { |name| plugin(name, **kwargs) } end |
#premium(premium = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 52 def premium(premium = nil) return @premium if premium.nil? @premium = premium end |
#to_h_with_overrides(**overrides) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 22 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
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 102 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
58 59 60 61 62 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 58 def translations(*translations) return @translations if translations.empty? @translations = translations end |
#type(type = nil) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/ckeditor5/rails/presets/preset_builder.rb', line 85 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 |