Class: Vedeu::DSL::Views
- Inherits:
-
Object
- Object
- Vedeu::DSL::Views
- 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
Class Method Summary collapse
-
.client_binding(&block) ⇒ void
private
Handles the directives you wish to send to render.
-
.composition(refresh = false, &block) ⇒ Vedeu::Views::Composition
private
Creates a new Vedeu::Views::Composition which may contain one or more view Views::View objects.
-
.renders(&block) ⇒ Vedeu::Views::Composition
(also: render)
-
.views(&block) ⇒ Vedeu::Views::Composition
Methods included from Elements
#build_attributes, #build_line, #build_stream, #build_view, #centre, #left, #line, #lines, #new_line, #new_stream, #new_streams, #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
Methods included from Geometry
Methods included from Border
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
.client_binding(&block) ⇒ void (private)
This method returns an undefined value.
Handles the directives you wish to send to render. Typically includes ‘view` with associated sub-directives. The binding of the block is also accessed so that we can ascertain the calling client application class, this is so that if there methods being called inside your views, Vedeu will redirect that call to the client class instance instead. (This actually occurs when Vedeu rescues from method_missing. See Vedeu::DSL.)
132 133 134 135 136 137 |
# File 'lib/vedeu/dsl/views.rb', line 132 def client_binding(&block) eval('self', block.binding).tap do |client| Vedeu.log(type: :debug, message: "Client binding: #{client.class.name}") end end |
.composition(refresh = false, &block) ⇒ Vedeu::Views::Composition (private)
Creates a new Vedeu::Views::Composition which may contain one or more view Views::View objects.
145 146 147 148 149 150 151 152 |
# File 'lib/vedeu/dsl/views.rb', line 145 def composition(refresh = false, &block) attrs = { client: client_binding(&block), colour: Vedeu.config.colour, } Vedeu::Views::Composition.build(attrs, &block).update_buffers(refresh) end |
.renders(&block) ⇒ Vedeu::Views::Composition Also known as: render
102 103 104 105 106 |
# File 'lib/vedeu/dsl/views.rb', line 102 def renders(&block) raise Vedeu::Error::RequiresBlock unless block_given? composition(true, &block) end |
.views(&block) ⇒ Vedeu::Views::Composition
113 114 115 116 117 |
# File 'lib/vedeu/dsl/views.rb', line 113 def views(&block) raise Vedeu::Error::RequiresBlock unless block_given? composition(false, &block) end |