Class: Brandish::Processors::Common::Header Abstract
- Inherits:
-
Brandish::Processor::Base
- Object
- Brandish::Processor::Base
- Brandish::Processors::Common::Header
- Includes:
- Brandish::Processor::Command
- Defined in:
- lib/brandish/processors/common/header.rb
Overview
Implement #header_render, and register the processor with Brandish::Processor::Base.register.
A processor that defines the header
command. This creates a list
internally of all of the headers in the document, to later be used to
possibly create a table of contents, if needed.
This takes no options.
Pairs:
"level"
- Optional. Defaults to1
. The "level" of the header. This should be a value between 1 and 6."value"
- Required. The name of the header."id"
- Optional. The ID of the header. This is a unique value to reference to this header. If no value is given, it defaults to a modified"value"
.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Brandish::Processor::Base
Instance Method Summary collapse
-
#header_data ⇒ {::Symbol => ::Object}
The header data used for the internal
:headers
structure. -
#header_id ⇒ ::String
The "id" of the header.
-
#header_level ⇒ Numeric
The header level.
-
#header_render ⇒ Parser::Node::Text
abstract
Renders the header for the format.
-
#header_value ⇒ ::String
The "value" of the header.
-
#perform ⇒ Parser::Node::Text
Handles the header.
-
#setup ⇒ void
This is called by Brandish::Processor::Base#initialize.
Methods included from Brandish::Processor::Command
Methods inherited from Brandish::Processor::Base
#accept, #call, #initialize, #postprocess, #process_block, #process_command, #process_root, #process_text, register
Constructor Details
This class inherits a constructor from Brandish::Processor::Base
Instance Method Details
#header_data ⇒ {::Symbol => ::Object}
The header data used for the internal :headers
structure.
57 58 59 |
# File 'lib/brandish/processors/common/header.rb', line 57 def header_data { level: header_level, value: header_value, id: header_id } end |
#header_id ⇒ ::String
The "id" of the header. This should be a unique value between all headers that specifies this exact header.
80 81 82 |
# File 'lib/brandish/processors/common/header.rb', line 80 def header_id @pairs.fetch("id") { header_value.downcase.gsub(/[^\w]|_/, "-") } end |
#header_level ⇒ Numeric
The header level. This is an integer between 1 and 6.
64 65 66 |
# File 'lib/brandish/processors/common/header.rb', line 64 def header_level @pairs.fetch("level", "1").to_i end |
#header_render ⇒ Parser::Node::Text
Renders the header for the format. This should be implemented by the implementing format.
49 50 51 52 |
# File 'lib/brandish/processors/common/header.rb', line 49 def header_render fail ProcessorNotImplementedError, "Please implement #{self.class}#header_render" end |
#header_value ⇒ ::String
The "value" of the header. This is the contents or the name of the header. This is required.
72 73 74 |
# File 'lib/brandish/processors/common/header.rb', line 72 def header_value @pairs.fetch("value") end |
#perform ⇒ Parser::Node::Text
Handles the header. This stores the #header_data in the context
:headers
key, and then calls #header_render.
39 40 41 42 |
# File 'lib/brandish/processors/common/header.rb', line 39 def perform @context[:headers] << header_data header_render 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.
30 31 32 33 |
# File 'lib/brandish/processors/common/header.rb', line 30 def setup super @context[:headers] = [] end |