Class: Brandish::Processors::Common::Markup Abstract
- Inherits:
-
Brandish::Processor::Base
- Object
- Brandish::Processor::Base
- Brandish::Processors::Common::Markup
- Defined in:
- lib/brandish/processors/common/markup.rb
Overview
Implement engines using Markup.engine, and register the processor using Brandish::Processor::Base.register.
Processes the text in the document with the given markup. Markup support varies from format to format, from a lot, to none. All supported markups are not included as a dependency on the Brandish gem; they must be used as a dependency for the using library or application.
All formats must provide an :escape
engine, that escapes the
source for the target format.
Options:
:engine
- Required. This is the markup engine to use. The allowed values for this option is dependant on the format.:options
- Optional. This is the options for the markup engine. The actual type is dependant on the markup engine. The default values are dependant on the markup engine.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Brandish::Processor::Base
Class Method Summary collapse
-
.engine(name, default, initializer, processor) ⇒ void
private
Defines an engine for use on the subclass.
-
.engines ⇒ {::Symbol => (::Object, ::Proc<::String, ::Object, ::String>)}
private
The engines defined for the subclass.
Instance Method Summary collapse
-
#process_text(node) ⇒ ::Object
Processes a text node.
-
#setup ⇒ void
This is called by Brandish::Processor::Base#initialize.
Methods inherited from Brandish::Processor::Base
#accept, #call, #initialize, #postprocess, #process_block, #process_command, #process_root, register
Constructor Details
This class inherits a constructor from Brandish::Processor::Base
Class Method Details
.engine(name, default, initializer, processor) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Defines an engine for use on the subclass. This should not be used on the parent class (Brandish::Processors::Common::Markup). This takes the name of the engine, the default options for the engine, and the processor to perform the markup processor.
If both a third argument and a block are provided, then the block takes precedence.
62 63 64 |
# File 'lib/brandish/processors/common/markup.rb', line 62 def self.engine(name, default, initializer, processor) engines[name] = [default.freeze, initializer, processor] end |
.engines ⇒ {::Symbol => (::Object, ::Proc<::String, ::Object, ::String>)}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The engines defined for the subclass. This should not be used on the
parent class (Brandish::Processors::Common::Markup). This returns a key-value pair for
the engines. The key is the "name" of the format; this is used for
the :engine
option. The value is a tuple containing two values:
the default options, and a proc that takes two arguments to markup
the text.
37 38 39 |
# File 'lib/brandish/processors/common/markup.rb', line 37 def self.engines @_engines ||= {} end |
Instance Method Details
#process_text(node) ⇒ ::Object
Processes a text node. By default, this performs no modifications on the node, and returns the node itself.
73 74 75 |
# File 'lib/brandish/processors/common/markup.rb', line 73 def process_text(node) node.update(value: markup(node.value)) end |
#setup ⇒ void
This method returns an undefined value.
This is called by Brandish::Processor::Base#initialize. This allows subclasses to perform any nessicary setups without having to override Brandish::Processor::Base#initialize. This does nothing by default.
67 68 69 70 |
# File 'lib/brandish/processors/common/markup.rb', line 67 def setup super initialize_engine end |