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.

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

#text

Methods included from Presentation

#background, #colour, #foreground, #style

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)


46
47
48
49
# File 'lib/vedeu/dsl/line.rb', line 46

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, protected)

Returns:

  • (Object)


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

def client
  @client
end

#modelLine (readonly, protected)

Returns:



115
116
117
# File 'lib/vedeu/dsl/line.rb', line 115

def model
  @model
end

Instance Method Details

#attributesHash (private)

Returns:

  • (Hash)


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

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

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

Parameters:

  • value (String)

Returns:



129
130
131
# File 'lib/vedeu/dsl/line.rb', line 129

def build_stream(value)
  Vedeu::Stream.build(client: client, parent: model, value: value)
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.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/vedeu/dsl/line.rb', line 64

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

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

  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:



100
101
102
103
104
# File 'lib/vedeu/dsl/line.rb', line 100

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

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