Module: Layouter

Defined in:
lib/layouter.rb,
lib/layouter/errors.rb,
lib/layouter/parent.rb,
lib/layouter/element.rb,
lib/layouter/version.rb,
lib/layouter/leaf/base.rb,
lib/layouter/leaf/custom.rb,
lib/layouter/leaf/spacer.rb,
lib/layouter/leaf/annotation.rb

Defined Under Namespace

Modules: Leaf Classes: AssertionError, Element, GenericError, LayoutError, Parent, StateError

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.annotation(*args) ⇒ Object



24
25
26
# File 'lib/layouter.rb', line 24

def annotation(*args)
  Leaf::Annotation.new(*args)
end

.bordered(chars, *args, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/layouter.rb', line 46

def bordered(chars, *args, &block)
  rows(
    cols(
      literal(chars[:tl]),
      horizontal(chars[:t]),
      literal(chars[:tr]),
    ),
    cols(
      vertical(chars[:l]),
      custom(*args, &block),
      vertical(chars[:r]),
    ),
    cols(
      literal(chars[:bl]),
      horizontal(chars[:b]),
      literal(chars[:br]),
    )
  )
end

.cols(*children) ⇒ Object



16
17
18
# File 'lib/layouter.rb', line 16

def cols(*children)
  Parent.new(:cols, children)
end

.custom(*args, &block) ⇒ Object



32
33
34
# File 'lib/layouter.rb', line 32

def custom(*args, &block)
  Leaf::Custom.new(*args, &block)
end

.horizontal(char) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
# File 'lib/layouter.rb', line 36

def horizontal(char)
  raise(ArgumentError.new("Must pass single character")) if char.length != 1
  custom(height: 1) { |w, h| char * w }
end

.literal(content) ⇒ Object



28
29
30
# File 'lib/layouter.rb', line 28

def literal(content)
  annotation(content, trim: false)
end

.rows(*children) ⇒ Object



12
13
14
# File 'lib/layouter.rb', line 12

def rows(*children)
  Parent.new(:rows, children)
end

.spacer(*args) ⇒ Object



20
21
22
# File 'lib/layouter.rb', line 20

def spacer(*args)
  Leaf::Spacer.new(*args)
end

.vertical(char) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
# File 'lib/layouter.rb', line 41

def vertical(char)
  raise(ArgumentError.new("Must pass single character")) if char.length != 1
  custom(width: 1) { |w, h| ([char] * h).join("\n") }
end