Class: Vedeu::DSL::View

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/dsl/view.rb

Overview

DSL for creating views.

Class Method Summary collapse

Class Method Details

.client(&block) ⇒ Object (private)

Returns the client object which called the DSL method.

Parameters:

  • block (Proc)

Returns:

  • (Object)


103
104
105
# File 'lib/vedeu/dsl/view.rb', line 103

def client(&block)
  eval('self', block.binding)
end

.composition(client, &block) ⇒ Vedeu::Composition (private)

Creates a new Composition which may contain one or more views (Interface objects).

Parameters:

  • client (Object)
  • block (Proc)

Returns:



113
114
115
# File 'lib/vedeu/dsl/view.rb', line 113

def composition(client, &block)
  Vedeu::Composition.build({ client: client }, &block)
end

.interface(name = '', &block) ⇒ Interface

TODO:

More documentation required.

Register an interface by name which will display output from a event or command. This provides the means for you to define your the views of your application without their content.

Examples:

Vedeu.interface 'my_interface' do
  # ...

Vedeu.interface do
  name 'interfaces_must_have_a_name'
  # ...

Parameters:

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

    The name of the interface. Used to reference the interface throughout your application’s execution lifetime.

  • block (Proc)

    A set of attributes which define the features of the interface.

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



36
37
38
39
40
41
42
# File 'lib/vedeu/dsl/view.rb', line 36

def interface(name = '', &block)
  fail InvalidSyntax, 'block not given' unless block_given?

  attributes = { client: client(&block), name: name }

  Vedeu::Interface.build(attributes, &block).store
end

.renders(&block) ⇒ Array<Interface>

Immediate render

Directly write a view buffer to the terminal. Using this method means that the refresh event does not need to be triggered after creating the views, though can be later triggered if needed.

Examples:

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

Parameters:

  • block (Proc)

    The directives you wish to send to render. Typically includes ‘view` with associated sub-directives.

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



60
61
62
63
64
# File 'lib/vedeu/dsl/view.rb', line 60

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

  store(:store_immediate, &block)
end

.store(method, &block) ⇒ Array (private)

Stores each of the views defined in their respective buffers ready to be rendered on next refresh.

Parameters:

  • method (Symbol)

    An instruction; ‘:store_immediate` or `:store_deferred` which determines whether the view will be shown immediately or later respectively.

  • block (Proc)

Returns:

  • (Array)


125
126
127
128
129
# File 'lib/vedeu/dsl/view.rb', line 125

def store(method, &block)
  composition(client(&block), &block).interfaces.map do |interface|
    interface.public_send(method)
  end
end

.views(&block) ⇒ Array<Interface>

Note:

The views declared within this block are stored in their respective interface back buffers until a refresh event occurs. When the refresh event is triggered, the back buffers are swapped into the front buffers and the content here will be rendered to Terminal.output.

Deferred view

Define a view (content) for an interface.

Examples:

Vedeu.views do
  view 'my_interface' do
    # ... some attributes ...
  end
  view 'my_other_interface' do
    # ... some other attributes ...
  end
  ...

Parameters:

  • block (Proc)

    The directives you wish to send to render. Typically includes ‘view` with associated sub-directives.

Returns:

Raises:

  • (InvalidSyntax)

    The required block was not given.



91
92
93
94
95
# File 'lib/vedeu/dsl/view.rb', line 91

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

  store(:store_deferred, &block)
end