Class: Polites::Span

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

Overview

A span is an element mapping to inline formatting, such as text formatting and images. Spans only exist within blocks and cannot themselves contain Block nodes.

Direct Known Subclasses

Annotation, Code, Delete, Emph, Footnote, Image, Link, Mark, Strong

Defined Under Namespace

Classes: Annotation, Code, Delete, Emph, Footnote, Image, Link, Mark, Strong

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: nil, url: nil, image: nil, filename: nil, title: nil, description: nil, width: nil, height: nil, text: nil) ⇒ Span

Build the proper kind of span from the given arguments.

Parameters:

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

    the type Polites has given to this node.

  • url (String, nil) (defaults to: nil)

    the URL attribute for links.

  • image (String, nil) (defaults to: nil)

    the image fingerprint referring to a sheet file.

  • filename (String, nil) (defaults to: nil)

    the explicit filename to use for images.

  • title (String, nil) (defaults to: nil)

    the title attribute for links, images.

  • description (String, nil) (defaults to: nil)

    the description attribute used by images.

  • width (String, nil) (defaults to: nil)

    the explicitly configured image width

  • height (String, nil) (defaults to: nil)

    the explicitly configured image height

  • text (Array<Node>) (defaults to: nil)

    the contents of footnoes and annotation.

Returns:

Raises:

  • (ParseError)

    when encountering unexpected kind



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

def self.build(children = [], kind: nil, url: nil, image: nil, filename: nil, title: nil, description: nil, width: nil, height: nil, text: nil)
  case kind
  when 'link'
    Span::Link.new(children, url: url, title: title)
  when 'mark'
    Span::Mark.new(children)
  when 'emph'
    Span::Emph.new(children)
  when 'strong'
    Span::Strong.new(children)
  when 'annotation'
    Span::Annotation.new(children, text)
  when 'footnote'
    Span::Footnote.new(children, text)
  when 'delete'
    Span::Delete.new(children)
  when 'code'
    Span::Code.new(children)
  when 'image'
    Span::Image.new(children, image: image, filename: filename, title: title, description: description, width: width, height: height)
  else
    raise ParseError, "unexpected kind #{kind.inspect}"
  end
end