Class: Vedeu::DSL::View
- Inherits:
-
Object
- Object
- Vedeu::DSL::View
- Includes:
- Common, Vedeu::DSL
- Defined in:
- lib/vedeu/dsl/view.rb
Overview
-
A view (‘View`) is made up of one or more interfaces.
-
An interface is an area on the screen where you can take input or direct output. You will define it’s colour and style, its dimensions, including position and give it a name. You can then direct the output of a command, or event, to this interface and Vedeu will ensure the content is placed there.
-
Interfaces (‘Interface`) are made up of lines (`Line`), their length being the width of the interface and their number being the height of the interface.
-
An interface with ‘width: 12, height: 5` will have five lines, each made of 12 characters- providing 60 cells. Colours and styles are handled by terminal escape sequences and therefore do not consume a cell.
-
Lines are made up of zero, one or multiple streams which are basically subsets of the line.
-
An interface, line or stream can have a colour attribute.
-
An interface, line or stream can have a style attribute.
-
Interfaces have a position (‘y`, `x`) on the screen, and a size. (`width`, `height`)
-
Interfaces can be placed relative to each other based on their attributes.
-
An interface has a ‘top`, `right`, `bottom`, `left`.
-
An interface also has a ‘north` and `west` (`top` and `left` minus 1 respectively).
-
An interface also has a ‘south` and `east` (`bottom` and `right` plus 1 respectively).
-
-
Colours are defined in CSS-style values, i.e. ‘#ff0000` would be red.
-
Styles are named. See the table below for supported styles.
Instance Attribute Summary collapse
-
#client ⇒ Object
included
from Vedeu::DSL
readonly
protected
The object instance where the DSL is being used.
-
#model ⇒ void
included
from Vedeu::DSL
readonly
protected
The new model object which the DSL is constructing.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#attributes ⇒ Hash<Symbol => void>
included
from Vedeu::DSL
private
Returns the default attributes for the new model.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#existing_attributes(name) ⇒ Hash<Symbol => void>
private
Retrieve the attributes of the interface by name.
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#initialize(model, client = nil) ⇒ void
included
from Vedeu::DSL
Returns a new instance of the DSL class including Vedeu::DSL.
- #interface(name) ⇒ Vedeu::Interfaces::Interface private
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#method_missing(method, *args, &block) ⇒ void
included
from Vedeu::DSL
private
Attempts to find the missing method on the client object.
-
#name ⇒ NilClass|String|Symbol
included
from Vedeu::DSL
Returns the model name if available.
-
#new_attributes(name) ⇒ Hash<Symbol => void>
private
Return the current attributes combined with the existing interface attributes defined by the interface.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #template_attributes(name, lines) ⇒ Hash<Symbol => void> private
-
#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Views::Views<Vedeu::Views::View>
Load content from an ERb template.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view(name, &block) ⇒ Vedeu::Views::Views<Vedeu::Views::View>
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Attribute Details
#client ⇒ Object (readonly, protected) Originally defined in module Vedeu::DSL
Returns The object instance where the DSL is being used.
#model ⇒ void (readonly, protected) Originally defined in module Vedeu::DSL
This method returns an undefined value.
Returns The new model object which the DSL is constructing.
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable is nil or empty.
#attributes ⇒ Hash<Symbol => void> (private) Originally defined in module Vedeu::DSL
Specific DSL classes may be overriding this method.
Returns the default attributes for the new model.
#become(klass, attributes) ⇒ Class Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts one class into another.
#boolean(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the value was a boolean.
#boolean?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Boolean.
#escape?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#existing_attributes(name) ⇒ Hash<Symbol => void> (private)
Retrieve the attributes of the interface by name.
132 133 134 |
# File 'lib/vedeu/dsl/view.rb', line 132 def existing_attributes(name) interface(name).attributes end |
#falsy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered false.
#hash?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Hash.
#initialize(model, client = nil) ⇒ void Originally defined in module Vedeu::DSL
Returns a new instance of the DSL class including Vedeu::DSL.
#interface(name) ⇒ Vedeu::Interfaces::Interface (private)
137 138 139 |
# File 'lib/vedeu/dsl/view.rb', line 137 def interface(name) Vedeu.interfaces.by_name(name) end |
#line_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Line.
#name ⇒ NilClass|String|Symbol Originally defined in module Vedeu::DSL
Returns the model name if available.
#new_attributes(name) ⇒ Hash<Symbol => void> (private)
Return the current attributes combined with the existing interface attributes defined by the interface.
124 125 126 |
# File 'lib/vedeu/dsl/view.rb', line 124 def new_attributes(name) existing_attributes(name).merge!(attributes) end |
#numeric?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#present?(variable) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether a variable has a useful value.
#snake_case(klass) ⇒ String Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a class name to a lowercase snake case string.
#stream_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::Stream.
#string?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value is a Fixnum.
#template_attributes(name, lines) ⇒ Hash<Symbol => void> (private)
115 116 117 |
# File 'lib/vedeu/dsl/view.rb', line 115 def template_attributes(name, lines) new_attributes(name).merge!(value: lines) end |
#template_for(name, filename, object = nil, options = {}) ⇒ Vedeu::Views::Views<Vedeu::Views::View>
More documentation required.
Load content from an ERb template.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/vedeu/dsl/view.rb', line 89 def template_for(name, filename, object = nil, = {}) fail Vedeu::Error::MissingRequired, 'Cannot render template without the name of the ' \ 'view.' unless present?(name) fail Vedeu::Error::MissingRequired, 'Cannot render template without a ' \ 'filename.' unless present?(filename) [:name] = name content = Vedeu::Templating::ViewTemplate.parse(object, filename, ) # lines = Vedeu::DSL::Wordwrap.for(content, options) new_model = Vedeu::Views::View.build(template_attributes(name, content)) model.add(new_model) end |
#truthy?(value) ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the value should be considered true.
#view(name, &block) ⇒ Vedeu::Views::Views<Vedeu::Views::View>
More documentation required.
57 58 59 60 61 62 63 64 65 |
# File 'lib/vedeu/dsl/view.rb', line 57 def view(name, &block) fail Vedeu::Error::RequiresBlock unless block_given? fail Vedeu::Error::MissingRequired, 'Cannot add view without a name.' unless present?(name) new_model = Vedeu::Views::View.build(new_attributes(name), &block) model.add(new_model) end |
#view_model? ⇒ Boolean Originally defined in module Common
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating the model is a Views::View.