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

Attributes included from Vedeu::DSL

#client, #model

Instance Method Summary collapse

Methods included from Text

#text

Methods included from Presentation

#background, #colour, #colour_attributes, #foreground, #style

Methods included from Vedeu::DSL

#attributes, #method_missing

Constructor Details

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

Returns an instance of DSL::Line.

Parameters:



44
45
46
47
# File 'lib/vedeu/dsl/line.rb', line 44

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 Method Details

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

Parameters:

  • value (String)

Returns:



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

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

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

Specify a single line in a view.

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

    line do
      # ... some code
    end
  end
end

Returns:

Raises:



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::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::InvalidSyntax, 'block not 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
    line do
      streams do
        # ... some code
      end

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

Parameters:

  • block (Proc)

Returns:

Raises:

See Also:



104
105
106
107
108
# File 'lib/vedeu/dsl/line.rb', line 104

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

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