Class: Brandish::Processors::Common::Markup Abstract

Inherits:
Brandish::Processor::Base show all
Defined in:
lib/brandish/processors/common/markup.rb

Overview

This class is abstract.

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

HTML::Markup, Latex::Markup

Instance Attribute Summary

Attributes inherited from Brandish::Processor::Base

#context

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • name (::Symbol)

    The name of the engine. This isn't the actual name of the markup; this is the name of the engine that processes the markup.

  • default (::Object)

    The default options for the engine.

  • initializer (::Symbol, ::Proc, nil)

    The initializer for the engine. If this is nil, no initializer is called. If this is a Symbol, the method is called for initialization. If this is a Proc, it is called for initialization.

  • processor (::Symbol, ::Proc)

    The processor for the engine. If this is a Symbol, the method is called for processing. If this is a Proc, it is called for processing.



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.

Returns:

  • ({::Symbol => (::Object, ::Proc<::String, ::Object, ::String>)})


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.

Parameters:

Returns:

  • (::Object)


73
74
75
# File 'lib/brandish/processors/common/markup.rb', line 73

def process_text(node)
  node.update(value: markup(node.value))
end

#setupvoid

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