Class: Inkpen::Extensions::Base Abstract
- Inherits:
-
Object
- Object
- Inkpen::Extensions::Base
- Defined in:
- lib/inkpen/extensions/base.rb
Overview
Subclass and override #name and #to_config to implement a custom extension.
Base class for all Inkpen TipTap extensions.
Extensions follow the TipTap extension pattern and are configured through this Ruby PORO layer before being passed to the JavaScript TipTap editor.
Direct Known Subclasses
CodeBlockSyntax, DocumentSection, ForcedDocument, Mention, Preformatted, Section, SlashCommands, Table, TaskList
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
The options passed during initialization.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Whether this extension is currently enabled.
-
#initialize(**options) ⇒ Base
constructor
Initialize a new extension with optional configuration.
-
#name ⇒ Symbol
abstract
The unique name of the extension.
-
#to_config ⇒ Hash
Convert the extension configuration to a hash for JSON serialization.
-
#to_h ⇒ Hash
Full configuration including name and enabled status.
-
#to_json(*args) ⇒ String
JSON representation of the extension.
Constructor Details
#initialize(**options) ⇒ Base
Initialize a new extension with optional configuration.
40 41 42 |
# File 'lib/inkpen/extensions/base.rb', line 40 def initialize(**) @options = .merge() end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns the options passed during initialization.
32 33 34 |
# File 'lib/inkpen/extensions/base.rb', line 32 def @options end |
Instance Method Details
#enabled? ⇒ Boolean
Whether this extension is currently enabled.
60 61 62 |
# File 'lib/inkpen/extensions/base.rb', line 60 def enabled? .fetch(:enabled, true) end |
#name ⇒ Symbol
Subclasses must override this method.
The unique name of the extension.
51 52 53 |
# File 'lib/inkpen/extensions/base.rb', line 51 def name raise NotImplementedError, "#{self.class} must implement #name" end |
#to_config ⇒ Hash
Convert the extension configuration to a hash for JSON serialization.
This hash is passed to the JavaScript TipTap extension.
71 72 73 |
# File 'lib/inkpen/extensions/base.rb', line 71 def to_config {} end |
#to_h ⇒ Hash
Full configuration including name and enabled status.
80 81 82 83 84 85 86 |
# File 'lib/inkpen/extensions/base.rb', line 80 def to_h { name: name, enabled: enabled?, config: to_config } end |
#to_json(*args) ⇒ String
JSON representation of the extension.
93 94 95 |
# File 'lib/inkpen/extensions/base.rb', line 93 def to_json(*args) to_h.to_json(*args) end |