Module: Eggshell::BlockHandler
- Includes:
- BaseHandler, ProcessHandler
- Included in:
- Defaults::NoOpHandler, Eggshell::Bundles::Basic::ListBlocks, Eggshell::Bundles::Basic::SectionBlocks, Eggshell::Bundles::Basic::TableBlock, Eggshell::Bundles::Basic::TextBlocks, Eggshell::Bundles::Basics::BasicBlocks, Eggshell::Bundles::Basics::SectionBlocks
- Defined in:
- lib/eggshell/block-handler.rb
Overview
A block handler handles one or more lines as a unit as long as all the lines conform to the block’s expectations.
Blocks are either identified explicitly:
pre. block_name. some content \ block_name({}). some content
Or, through some non-alphanumeric character:
pre. |table|start|inferred |another|row|here
When a handler can handle a line, it sets an internal block type (retrieved with {current_type()}). Subsequent lines are passed to {continue_with()} which returns ‘true` if the line conforms to the current type or `false` to close the block.
The line or lines are finally passed to {process()} to generate the output.
h2. Block Standards
When explicitly calling a block and passing a parameter, always expect the first argument to be a hash of various attributes:
pre. p(”, ‘id’: ”, ‘attributes’: {}, other, arguments, …). paragraph start
Defined Under Namespace
Modules: BlockParams, Defaults, HtmlUtils
Constant Summary collapse
- COLLECT =
Indicates that subsequent lines should be collected.
:collect
- COLLECT_RAW =
Unlike COLLECT, which will parse out macros and keep the execution order, this will collect the line raw before any macro detection takes place.
:collect_raw
- DONE =
Indicates that the current line ends the block and all collected lines should be processed.
:done
- RETRY =
A variant of DONE: if the current line doesn’t conform to expected structure, process the previous lines and indicate to processor that a new block has started.
:retry
Instance Method Summary collapse
-
#can_handle(line) ⇒ Object
Sets the type based on the line given, and returns one of the following:.
-
#continue_with(line) ⇒ Object
Determines if processing for the current type ends (e.g. a blank line usually terminates the block).
-
#current_type ⇒ Object
Returns the handler’s current type.
-
#equal?(handler, type) ⇒ Boolean
Useful for pipeline chains in the form ‘block-macro*-block`.
-
#reset ⇒ Object
Resets state of line inspection.
- #set_processor(proc, opts = nil) ⇒ Object
Methods included from ProcessHandler
Instance Method Details
#can_handle(line) ⇒ Object
Sets the type based on the line given, and returns one of the following:
-
{RETRY}: doesn’t handle this line;
-
{COLLECT}: will collect lines following normal processing.
-
{COLLECT_RAW}: will collect lines before macro/block checks can take place.
-
{DONE}: line processed, no need to collect more lines.
71 72 73 |
# File 'lib/eggshell/block-handler.rb', line 71 def can_handle(line) RETRY end |
#continue_with(line) ⇒ Object
Determines if processing for the current type ends (e.g. a blank line usually terminates the block). continue; {DONE} to collect this line but end the block.
79 80 81 82 83 84 85 |
# File 'lib/eggshell/block-handler.rb', line 79 def continue_with(line) if line != nil && line != '' COLLECT else RETRY end end |
#current_type ⇒ Object
Returns the handler’s current type.
61 62 63 |
# File 'lib/eggshell/block-handler.rb', line 61 def current_type @block_type end |
#equal?(handler, type) ⇒ Boolean
Useful for pipeline chains in the form ‘block-macro*-block`. This checks if the current block handler/type is equivalent to the block that’s being pipelined.
89 90 91 |
# File 'lib/eggshell/block-handler.rb', line 89 def equal?(handler, type) false end |
#reset ⇒ Object
Resets state of line inspection.
56 57 58 |
# File 'lib/eggshell/block-handler.rb', line 56 def reset @block_type = nil end |
#set_processor(proc, opts = nil) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/eggshell/block-handler.rb', line 48 def set_processor(proc, opts = nil) @eggshell = proc @eggshell.add_block_handler(self, *@block_types) @vars = @eggshell.vars @vars[:block_params] = {} if !@vars[:block_params] end |