Class: Vedeu::DSL::Line

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

Overview

Provides methods to be used to define views.

Examples:

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

Methods included from Text

#stream_attributes, #stream_builder, #text

Methods included from Style

#style

Methods included from Colour

#background, #colour, #foreground

Methods included from Vedeu::DSL

#method_missing

Constructor Details

#initialize(model, client = nil) ⇒ Vedeu::DSL::Line

Returns an instance of DSL::Line.

Parameters:

  • model (Vedeu::Line)
  • client (Object) (defaults to: nil)


50
51
52
53
# File 'lib/vedeu/dsl/line.rb', line 50

def initialize(model, client = nil)
  @model  = model
  @client = client
end

Dynamic Method Handling

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

Instance Attribute Details

#clientObject (readonly, private)

Returns:

  • (Object)


117
118
119
# File 'lib/vedeu/dsl/line.rb', line 117

def client
  @client
end

#modelLine (readonly, private)

Returns:



120
121
122
# File 'lib/vedeu/dsl/line.rb', line 120

def model
  @model
end

Instance Method Details

#attributesHash (private)

Returns:

  • (Hash)


123
124
125
126
127
128
# File 'lib/vedeu/dsl/line.rb', line 123

def attributes
  {
    client: client,
    parent: model,
  }
end

#line(value = '', &block) ⇒ Vedeu::Lines

Specify a single line in a view.

Examples:

Vedeu.renders do
  view 'my_interface' do
    line 'some text...'
    # ...

    line do
      # ...

Returns:

Raises:

  • (InvalidSyntax)

    When no block or value is provided.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vedeu/dsl/line.rb', line 68

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

  elsif value
    stream = Vedeu::Stream.build({ client: client,
                                   parent: model,
                                   value: value })
    Vedeu::Line.build({ client:  client,
                        parent:  model.parent,
                        streams: [stream] })

  else
    fail InvalidSyntax, 'block not given'

  end

  model.parent.add(content)
end

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

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

Examples:

Vedeu.renders do
  view 'my_interface' do
    line do
      streams do
        # ...

      stream do
        # ...

Parameters:

  • block (Proc)

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.

See Also:



107
108
109
110
111
# File 'lib/vedeu/dsl/line.rb', line 107

def streams(&block)
  fail InvalidSyntax, 'block not given' unless block_given?

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