Class: Vedeu::DSL::Line

Inherits:
Object
  • Object
show all
Includes:
Vedeu::DSL, Presentation, Text
Defined in:
lib/vedeu/dsl/line.rb

Overview

Provides methods to be used to define views.

Vedeu.renders do
  view :my_interface do
    lines do
      background '#000000'
      foreground '#ffffff'
      line 'This is white text on a black background.'
      line 'Next is a blank line:'
      line ''

      streams { stream 'We can define ' }

      streams do
        foreground '#ff0000'
        stream 'parts of a line '
      end

      streams { stream 'independently using ' }

      streams do
        foreground '#00ff00'
        stream 'streams.'
      end
    end
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Vedeu::DSL

Instance Attribute Details

#clientObject (readonly, protected) Originally defined in module Vedeu::DSL

Returns The object instance where the DSL is being used.

Returns:

  • (Object)

    The object instance where the DSL is being used.

#modelvoid (readonly, protected) Originally defined in module Vedeu::DSL

This method returns an undefined value.

Returns The new model object which the DSL is constructing.

Instance Method Details

#attributesHash<Symbol => void> (private) Originally defined in module Vedeu::DSL

Note:

Specific DSL classes may be overriding this method.

Returns the default attributes for the new model.

Returns:

  • (Hash<Symbol => void>)

#background(value = '') ⇒ String Also known as: bg, bgcolor, background=, bg=, bgcolor= Originally defined in module Presentation

Note:

The last defined background colour for a particular interface, line or stream overrides previously defined entries in the same block.

Define the background colour for an interface, line, or a stream. When called with a block, will create a new stream with the background colour specified. When the block terminates, the background will return to that of the parent.

Examples:

interface 'my_interface' do
  background '#0022ff' # /or/ (blue)
  bgcolor    '#22ff00' # /or/ (blue is overridden to green)
  bg         '#ff0022' #      (green is overridden to red)
  # ...

  lines do
    background '#2200ff'
    # ...

    stream do
      background '#22ff00'
      # ...
    end
  end
end

Parameters:

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

    A HTML/CSS value.

Returns:

  • (String)

#build_stream(value) ⇒ Vedeu::Views::Stream (private)

Parameters:

  • value (String)

Returns:



111
112
113
# File 'lib/vedeu/dsl/line.rb', line 111

def build_stream(value)
  Vedeu::Views::Stream.build(client: client, parent: model, value: value)
end

#colour(attrs = {}) ⇒ Vedeu::Colours::Colour Also known as: colour= Originally defined in module Presentation

Note:

Rejects invalid keys and empty/nil attributes. Also, the last defined colour for a particular interface, line or stream overrides previously defined entries in the same block.

Define either or both foreground and background colours for an interface, line or a stream. At least one attribute is required.

Examples:

interface 'my_interface' do
  colour background: '#ff00ff', foreground: '#ffff00'
  # ...

  lines do
    colour background: '#000000', foreground: '#ffffff'
    # ...

    stream do
      colour background: '#000000', foreground: '#ffffff'
      # ...
    end
  end
end

Parameters:

Returns:

#colour_attributesHash<Symbol => String> (private) Originally defined in module Presentation

Returns:

  • (Hash<Symbol => String>)

#foreground(value = '') ⇒ Object Also known as: fg, fgcolor, foreground=, fg=, fgcolor= Originally defined in module Presentation

See Also:

#initialize(model, client = nil) ⇒ void Originally defined in module Vedeu::DSL

Returns an instance of the DSL class including Vedeu::DSL.

Parameters:

  • model (void)

    The model class which the DSL class is wrapping.

  • client (void) (defaults to: nil)

    The class where the DSL methods are being used.

#line(value = '', &block) ⇒ Vedeu::Views::Lines Also known as: line=

Specify a single line in a view.

Vedeu.renders do
  view :my_interface do
    lines do
      line 'some text...'
      # ... some code

      line 'some more text...'
      # ... some code
    end
  end
end


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vedeu/dsl/line.rb', line 55

def line(value = '', &block)
  if block_given?
    content = Vedeu::Views::Line.build(client: client,
                                       parent: model.parent, &block)

  elsif value
    content = Vedeu::Views::Line.build(client: client,
                                       parent: model.parent,
                                       value:  [build_stream(value)])

  else
    fail Vedeu::Error::RequiresBlock unless block_given?

  end

  model.parent.add(content)
end

#streams(&block) ⇒ Vedeu::Views::Streams<Vedeu::Views::Stream> Also known as: stream, stream=, streams=

Define multiple streams (a stream is a subset of a line). Uses Stream for all directives within the required block.

Vedeu.renders do
  view :my_interface do
    lines do
      line do
        streams do
          # ... some code
        end

        stream do
          # ... some code
        end
      end
    end
  end
end

Parameters:

  • block (Proc)

Returns:

Raises:

See Also:



98
99
100
101
102
# File 'lib/vedeu/dsl/line.rb', line 98

def streams(&block)
  fail Vedeu::Error::RequiresBlock unless block_given?

  model.add(model.member.build(attributes, &block))
end

#style(value) ⇒ Vedeu::Presentation::Style Also known as: style=, styles, styles= Originally defined in module Presentation

Define a style or styles for an interface, line or a stream.

Examples:

interface 'my_interface' do
  style 'normal'
  # ...
end

lines do
  style ['bold', 'underline']
  # ...
end

stream do
  style 'blink'
  # ...
end

Parameters:

  • value (Array<Symbol>|Array<String>|Symbol|String)

Returns:

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

Note:

If using the convenience methods; left, centre, center or right, then a specified anchor will be ignored.

Specify the content for a view. Provides the means to align a string (or object responding to ‘to_s`), and add it as a Line or to the Stream.

Examples:

lines do
  centre '...'
end

line do
  right '...'
end

line do
  stream do
    text '...'
  end
end

left 'This will be left aligned.', width: 35
# => 'This will be left aligned.         '

centre 'This will be aligned centrally.', width: 35
# => '  This will be aligned centrally.  '
# centre is also aliased to center

right 'This will be right aligned.', width: 35
# => '        This will be right aligned.'

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

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)