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.



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

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).



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

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'
  # ...

Raises:

  • (InvalidSyntax)

    The required block was not given.



33
34
35
36
37
38
39
# File 'lib/vedeu/dsl/view.rb', line 33

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
    # ...

Raises:

  • (InvalidSyntax)

    The required block was not given.



57
58
59
60
61
# File 'lib/vedeu/dsl/view.rb', line 57

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.



122
123
124
125
126
# File 'lib/vedeu/dsl/view.rb', line 122

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
  ...

Raises:

  • (InvalidSyntax)

    The required block was not given.



88
89
90
91
92
# File 'lib/vedeu/dsl/view.rb', line 88

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

  store(:store_deferred, &block)
end