Class: Brandish::Processors::Common::Header Abstract

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

Overview

This class is abstract.

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 to 1. 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

HTML::Header

Instance Attribute Summary

Attributes inherited from Brandish::Processor::Base

#context

Instance Method Summary collapse

Methods included from Brandish::Processor::Command

included, #process_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.

Returns:

  • ({::Symbol => ::Object})


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.

Returns:

  • (::String)


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_levelNumeric

The header level. This is an integer between 1 and 6.

Returns:

  • (Numeric)


64
65
66
# File 'lib/brandish/processors/common/header.rb', line 64

def header_level
  @pairs.fetch("level", "1").to_i
end

#header_renderParser::Node::Text

This method is abstract.

Renders the header for the format. This should be implemented by the implementing format.

Returns:



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.

Returns:

  • (::String)


72
73
74
# File 'lib/brandish/processors/common/header.rb', line 72

def header_value
  @pairs.fetch("value")
end

#performParser::Node::Text

Handles the header. This stores the #header_data in the context :headers key, and then calls #header_render.

Returns:



39
40
41
42
# File 'lib/brandish/processors/common/header.rb', line 39

def perform
  @context[:headers] << header_data
  header_render
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.



30
31
32
33
# File 'lib/brandish/processors/common/header.rb', line 30

def setup
  super
  @context[:headers] = []
end