Class: Polites::Block

Inherits:
Node
  • Object
show all
Defined in:
lib/polites/block.rb

Overview

A block represents a structural element in a Polites document, mapping to block-level elements in HTML. Examples include paragraphs and headings.

Blocks may technically contain other blocks, as well as Text and Span elements.

Direct Known Subclasses

Blockquote, CodeBlock, Divider, Heading, List, Paragraph

Defined Under Namespace

Classes: Blockquote, CodeBlock, Divider, Heading, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, List, OrderedList, Paragraph, UnorderedList

Instance Attribute Summary

Attributes inherited from Node

#children

Class Method Summary collapse

Methods inherited from Node

#eql?, #initialize, #text

Constructor Details

This class inherits a constructor from Polites::Node

Class Method Details

.build(children = [], kind: 'paragraph', level: 0, syntax: nil) ⇒ Span

Build the proper kind of span from the given arguments.

Parameters:

  • children (Array<Node>) (defaults to: [])
  • kind (String) (defaults to: 'paragraph')

    the type Polites has given to this node.

  • level (Fixnum) (defaults to: 0)

    the indentation level used by list items.

  • syntax (String) (defaults to: nil)

    the syntax attribute used in code blocks.

Returns:

Raises:

  • (ParseError)

    when encountering unexpected kind



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/polites/block.rb', line 21

def self.build(children = [], kind: 'paragraph', level: 0, syntax: nil)
  case kind
  when 'heading1'
    Heading1.new(children)
  when 'heading2'
    Heading2.new(children)
  when 'heading3'
    Heading3.new(children)
  when 'heading4'
    Heading4.new(children)
  when 'heading5'
    Heading5.new(children)
  when 'heading6'
    Heading6.new(children)
  when 'paragraph'
    Paragraph.new(children)
  when 'unorderedList'
    UnorderedList.new(children, level)
  when 'orderedList'
    OrderedList.new(children, level)
  when 'blockquote'
    Blockquote.new(children)
  when 'divider'
    Divider.new(children)
  when 'codeblock'
    CodeBlock.new(children, syntax)
  else
    raise ParseError, "unknown block type #{kind.inspect}"
  end
end