module Eggshell::BlockHandler

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({'class': '', 'id': '', 'attributes': {}}, other, arguments, …). paragraph start

Constants

COLLECT

Indicates that subsequent lines should be collected.

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.

DONE

Indicates that the current line ends the block and all collected lines should be processed.

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.

Private Instance Methods

can_handle(line) click to toggle source

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.

# File lib/eggshell/block-handler.rb, line 71
def can_handle(line)
        RETRY
end
continue_with(line) click to toggle source

Determines if processing for the current type ends (e.g. a blank line usually terminates the block). @return Symbol {{RETRY}} if not handled at all; {{COLLECT}} to collect and continue; {{DONE}} to collect this line but end the block.

# File lib/eggshell/block-handler.rb, line 79
def continue_with(line)
        if line != nil && line != ''
                COLLECT
        else
                RETRY
        end
end
current_type() click to toggle source

Returns the handler's current type.

# File lib/eggshell/block-handler.rb, line 61
def current_type
        @block_type
end
equal?(handler, type) click to toggle source

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.

# File lib/eggshell/block-handler.rb, line 89
def equal?(handler, type)
        false
end
reset() click to toggle source

Resets state of line inspection.

# File lib/eggshell/block-handler.rb, line 56
def reset
        @block_type = nil
end
set_processor(proc, opts = nil) click to toggle source
# 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