Module: Vedeu::DSL::Text

Included in:
Interface, Line, Stream, View
Defined in:
lib/vedeu/dsl/text.rb

Overview

Provides helper methods for building views.

Instance Method Summary collapse

Instance Method Details

#text(value = '', options = {}) ⇒ String Also known as: text=, align, center, centre, left, right, align=, center=, centre=, left=, right=

right ‘This will be right aligned.’, width: 35, anchor: centre

# => '        This will be right aligned.'

text 'This will be truncated here. More text here.', width: 28
# => 'This will be truncated here.'

text 'Padded with hyphens.', width: 25, pad: '-', anchor: :right
# => '-----Padded with hyphens.'

Parameters:

  • value (String|Object) (defaults to: '')

    A string or object that responds to ‘to_s`.

  • options (Hash) (defaults to: {})

    Text options.

Options Hash (options):

  • :anchor (Symbol)

    One of ‘:left`, `:centre`/`:center`, or `:right`.

  • :width (Integer|NilClass)

    The width of the text stream to add. If the ‘string` provided is longer than this value, the string will be truncated. If no width is provided in the context of ’lines’, then the interface width is used. If no width is provided in the context of a ‘stream’, then no alignment will occur.

  • :pad (String)

    The character to use to pad the width, by default uses an empty space (0x20). Only when the string is shorter than the specified width.

Returns:

  • (String)


56
57
58
59
60
# File 'lib/vedeu/dsl/text.rb', line 56

def text(value = '', options = {})
  options.merge!(anchor: __callee__, model: model)

  Vedeu::Output::Text.add(value, options)
end