Class: Vedeu::DSL::Views

Inherits:
Object
  • Object
show all
Includes:
Vedeu::DSL, Border, Cursors, Elements, Geometry, Use
Defined in:
lib/vedeu/dsl/views.rb

Overview

There are two ways to construct views with Vedeu. You would like to draw the view to the screen immediately (immediate render) or you want to save a view to be drawn when you trigger a refresh event later (deferred view).

Both of these approaches require that you have defined an interface (or ‘visible area’) first. You can find out how to define an interface with Vedeu below or in Interfaces::DSL. The examples in ‘Immediate Render’ and ‘Deferred View’ use these interface definitions: (Note: should you use these examples, ensure your terminal is at least 70 characters in width and 5 lines in height.)

Vedeu.interface :main do
  geometry do
    height 4
    width  50
  end
end

Vedeu.interface :title do
  geometry do
    height 1
    width  50
    x      use('main').left
    y      use('main').north
  end
end

Both of these approaches use a concept of Buffers in Vedeu. There are three buffers for any defined interface. These are imaginatively called: ‘back’, ‘front’ and ‘previous’.

The ‘back’ buffer is the content for an interface which will be shown next time a refresh event is fired globally or for that interface. So, ‘back’ becomes ‘front’.

The ‘front’ buffer is the content for an interface which is currently showing. When a refresh event is fired, again, globally or for that interface specifically, the content of this ‘front’ buffer is first copied to the ‘previous’ buffer, and then the current ‘back’ buffer overwrites this ‘front’ buffer.

The ‘previous’ buffer contains what was shown on the ‘front’ before the current ‘front’.

You can only write to either the ‘front’ (you want the content to be drawn immediately (immediate render)) or the ‘back’ (you would like the content to be drawn on the next refresh (deferred view)).

The basic view DSL methods look like this:

renders/views
  |- view
      |- lines
      |   |- line
      |       |- streams
      |       |   |- stream
      |       |       |- char
      |       |
      |       |- stream
      |           |- char
      |
      |- line
          |- streams
          |   |- stream
          |       |- char
          |
          |- stream
              |- char

renders/views
  |- view
      |- lines/line
          |- streams/stream
              |- char

Instance Attribute Summary

Attributes included from Vedeu::DSL

#client, #model

Class Method Summary collapse

Methods included from Elements

#centre, #left, #line, #lines, #requires_block!, #requires_model!, #right, #stream, #text

Methods included from Presentation

#background, #colour, #colour_attributes, #foreground, #no_wordwrap!, #style, #wordwrap

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Methods included from Use

#use

Methods included from Geometry

included

Methods included from Border

included

Methods included from Cursors

#cursor, #cursor!, #no_cursor!

Methods included from Vedeu::DSL

#attributes, #initialize, #method_missing, #name

Dynamic Method Handling

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

Class Method Details

.composition(client, refresh = false, &block) ⇒ Object (private)

Creates a new Vedeu::Views::Composition which may contain one or more view Views::View objects.

# @return [Vedeu::Views::Composition]

Parameters:

  • client (Object)

    The client class which called the DSL object.

  • refresh (Boolean) (defaults to: false)
  • block (Proc)

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



133
134
135
136
137
# File 'lib/vedeu/dsl/views.rb', line 133

def composition(client, refresh = false, &block)
  attrs = { client: client, colour: Vedeu.config.colour }

  Vedeu::Views::Composition.build(attrs, &block).update_buffers(refresh)
end

.renders(&block) ⇒ Vedeu::Views::Composition Also known as: render

Parameters:

  • block (Proc)

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

Returns:

Raises:



102
103
104
105
106
# File 'lib/vedeu/dsl/views.rb', line 102

def renders(&block)
  raise Vedeu::Error::RequiresBlock unless block_given?

  composition(eval('self', block.binding), true, &block)
end

.views(&block) ⇒ Vedeu::Views::Composition

Parameters:

  • block (Proc)

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

Returns:

Raises:



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

def views(&block)
  raise Vedeu::Error::RequiresBlock unless block_given?

  composition(eval('self', block.binding), false, &block)
end