Class: Vedeu::Interfaces::DSL
- Inherits:
-
Object
- Object
- Vedeu::Interfaces::DSL
- Extended by:
- Common
- Includes:
- Common, Cursors::DSL, DSL, DSL::Presentation, DSL::Shared, DSL::Text, DSL::Use
- Defined in:
- lib/vedeu/interfaces/dsl.rb
Overview
DSL for creating interfaces.
Instance Attribute Summary collapse
-
#client ⇒ Object
included
from DSL
readonly
protected
The object instance where the DSL is being used.
-
#model ⇒ void
included
from DSL
readonly
protected
The new model object which the DSL is constructing.
Class Method Summary collapse
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.add_buffers!(name) ⇒ Vedeu::Buffers::Buffer
private
Registers a set of buffers for the interface unless already registered, and also adds interface’s name to list of focussable interfaces.
-
.add_cursor!(name) ⇒ Vedeu::Cursors::Cursor
private
Registers a new cursor for the interface unless already registered.
-
.add_editor!(name) ⇒ Object
private
Registers a new document with the interface.
-
.add_focusable!(name) ⇒ void
private
Registers interface name in focus list unless already registered.
-
.client(&block) ⇒ Object
private
Returns the client object which called the DSL method.
-
.demodulize(klass) ⇒ String
extended
from Common
private
Removes the module part from the expression in the string.
-
.interface(name, &block) ⇒ Vedeu::Interfaces::Interface
Register an interface by name which will display output from an event or a command.
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
.snake_case(name) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
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 DSL
private
Returns the default attributes for the new model.
-
#background(value = '') ⇒ String
(also: #bg, #bgcolor, #background=, #bg=, #bgcolor=)
included
from DSL::Presentation
Define the background colour for an interface, line, or a stream.
-
#border(name = nil, &block) ⇒ Vedeu::Borders::Border
included
from DSL::Shared
Allows the setting of a border for the interface.
-
#border! ⇒ Vedeu::Borders::Border
included
from DSL::Shared
Applies the default border to the interface.
-
#colour(attrs = {}) ⇒ Vedeu::Colours::Colour
(also: #colour=)
included
from DSL::Presentation
Define either or both foreground and background colours for an interface, line or a stream.
- #colour_attributes ⇒ Hash<Symbol => String> included from DSL::Presentation private
-
#cursor(value = true) ⇒ Vedeu::Cursors::Cursor
included
from Cursors::DSL
Set the cursor visibility on an interface.
-
#cursor! ⇒ Vedeu::Cursors::Cursor
(also: #show_cursor!)
included
from Cursors::DSL
Set the cursor to visible for the interface or view.
-
#delay(value) ⇒ Fixnum|Float
To maintain performance interfaces can be delayed from refreshing too often, the reduces artefacts particularly when resizing the terminal screen.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
-
#editable(value = true) ⇒ Boolean
Set whether the interface is editable.
-
#editable! ⇒ Boolean
Set the interface to be editable.
-
#focus! ⇒ Array<String>
Specify this interface as being in focus when the application starts.
- #foreground(value = '') ⇒ Object (also: #fg, #fgcolor, #foreground=, #fg=, #fgcolor=) included from DSL::Presentation
-
#geometry(name = nil, &block) ⇒ Vedeu::Geometry::Geometry
included
from DSL::Shared
Define the geometry for an interface.
-
#group(name) ⇒ Vedeu::Groups::Group
Specify a group for an interface.
-
#hide! ⇒ Boolean
Set the interface to invisible.
-
#initialize(model, client = nil) ⇒ void
included
from DSL
Returns an instance of the DSL class including DSL.
- #keymap(name = model.name, &block) ⇒ Object (also: #keys)
-
#method_missing(method, *args, &block) ⇒ void
included
from DSL
private
Attempts to find the missing method on the client object.
-
#name(value) ⇒ String|Symbol
The name of the interface.
-
#no_cursor! ⇒ Vedeu::Cursors::Cursor
(also: #hide_cursor!)
included
from Cursors::DSL
Set the cursor to invisible for the interface or view.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#show! ⇒ Boolean
(also: #visible!)
Set the interface to visible.
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#style(value) ⇒ Vedeu::Presentation::Style
(also: #style=, #styles, #styles=)
included
from DSL::Presentation
Define a style or styles for an interface, line or a stream.
-
#text(value = '', options = {}) ⇒ String
(also: #text=, #align, #center, #centre, #left, #right, #align=, #center=, #centre=, #left=, #right=)
included
from DSL::Text
Specify the content for a view.
-
#use(name) ⇒ Vedeu::Interfaces::Interface
Use a value from another model.
-
#visible(value = true) ⇒ Boolean
Set the visibility of the interface.
-
#zindex(value) ⇒ Fixnum
(also: #z_index, #z)
Set the zindex of the interface.
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 DSL
Returns The object instance where the DSL is being used.
#model ⇒ void (readonly, protected) Originally defined in module DSL
This method returns an undefined value.
Returns The new model object which the DSL is constructing.
Class 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.
.add_buffers!(name) ⇒ Vedeu::Buffers::Buffer (private)
Registers a set of buffers for the interface unless already registered, and also adds interface’s name to list of focussable interfaces.
66 67 68 |
# File 'lib/vedeu/interfaces/dsl.rb', line 66 def add_buffers!(name) Vedeu::Buffers::Buffer.new(name: name).store end |
.add_cursor!(name) ⇒ Vedeu::Cursors::Cursor (private)
Registers a new cursor for the interface unless already registered.
75 76 77 |
# File 'lib/vedeu/interfaces/dsl.rb', line 75 def add_cursor!(name) Vedeu::Cursors::Cursor.store(name: name) end |
.add_editor!(name) ⇒ Object (private)
Registers a new document with the interface.
82 83 84 |
# File 'lib/vedeu/interfaces/dsl.rb', line 82 def add_editor!(name) Vedeu::Editor::Document.store(name: name) end |
.add_focusable!(name) ⇒ void (private)
This method returns an undefined value.
Registers interface name in focus list unless already registered.
91 92 93 |
# File 'lib/vedeu/interfaces/dsl.rb', line 91 def add_focusable!(name) Vedeu::Models::Focus.add(name) end |
.client(&block) ⇒ Object (private)
Returns the client object which called the DSL method.
99 100 101 |
# File 'lib/vedeu/interfaces/dsl.rb', line 99 def client(&block) eval('self', block.binding) end |
.demodulize(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.
Removes the module part from the expression in the string.
.interface(name, &block) ⇒ Vedeu::Interfaces::Interface
More documentation required.
Register an interface by name which will display output from an event or a command. This provides the means for you to define your the views of your application without their content.
Vedeu.interface :my_interface do
# ... some code
end
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vedeu/interfaces/dsl.rb', line 38 def interface(name, &block) fail Vedeu::Error::RequiresBlock unless block_given? fail Vedeu::Error::MissingRequired, 'name not given'.freeze unless present?(name) attributes = { client: client(&block), name: name } interface = Vedeu::Interfaces::Interface .build(attributes, &block) .store add_buffers!(name) add_cursor!(name) add_editor!(name) if interface.editable? add_focusable!(name) interface end |
.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(name) ⇒ 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.
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 DSL
Specific DSL classes may be overriding this method.
Returns the default attributes for the new model.
#background(value = '') ⇒ String Also known as: bg, bgcolor, background=, bg=, bgcolor= Originally defined in module DSL::Presentation
The last defined background colour for a particular interface, line or stream overrides previously defined entries in the same block.
Define the background colour for an interface, line, or a stream. When called with a block, will create a new stream with the background colour specified. When the block terminates, the background will return to that of the parent.
#border(name = nil, &block) ⇒ Vedeu::Borders::Border Originally defined in module DSL::Shared
Allows the setting of a border for the interface.
#border! ⇒ Vedeu::Borders::Border Originally defined in module DSL::Shared
Applies the default border to the interface.
#colour(attrs = {}) ⇒ Vedeu::Colours::Colour Also known as: colour= Originally defined in module DSL::Presentation
Rejects invalid keys and empty/nil attributes. Also, the last defined colour for a particular interface, line or stream overrides previously defined entries in the same block.
Define either or both foreground and background colours for an interface, line or a stream. At least one attribute is required.
#colour_attributes ⇒ Hash<Symbol => String> (private) Originally defined in module DSL::Presentation
#cursor(value = true) ⇒ Vedeu::Cursors::Cursor Originally defined in module Cursors::DSL
Set the cursor visibility on an interface.
#cursor! ⇒ Vedeu::Cursors::Cursor Also known as: show_cursor! Originally defined in module Cursors::DSL
Set the cursor to visible for the interface or view.
#delay(value) ⇒ Fixnum|Float
To maintain performance interfaces can be delayed from refreshing too often, the reduces artefacts particularly when resizing the terminal screen.
119 120 121 |
# File 'lib/vedeu/interfaces/dsl.rb', line 119 def delay(value) model.delay = value end |
#demodulize(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.
Removes the module part from the expression in the string.
#editable(value = true) ⇒ Boolean
When an interface is made editable, then the cursor visibility will be set to visible.
Set whether the interface is editable.
153 154 155 156 157 158 159 |
# File 'lib/vedeu/interfaces/dsl.rb', line 153 def editable(value = true) boolean = value ? true : false cursor(true) if boolean model.editable = boolean end |
#editable! ⇒ Boolean
Set the interface to be editable.
164 165 166 |
# File 'lib/vedeu/interfaces/dsl.rb', line 164 def editable! editable(true) end |
#focus! ⇒ Array<String>
If multiple interfaces are defined, and this is included in each, then the last defined will be the interface in focus. However, this behaviour can be overridden:
“‘ruby Vedeu.focus_by_name :some_interface “`
When the above is specified (outside of a ‘Vedeu.interface` declaration), the named interface will be focussed instead.
Specify this interface as being in focus when the application starts.
183 184 185 |
# File 'lib/vedeu/interfaces/dsl.rb', line 183 def focus! Vedeu::Models::Focus.add(model.name, true) if present?(model.name) end |
#foreground(value = '') ⇒ Object Also known as: fg, fgcolor, foreground=, fg=, fgcolor= Originally defined in module DSL::Presentation
#geometry(name = nil, &block) ⇒ Vedeu::Geometry::Geometry Originally defined in module DSL::Shared
Define the geometry for an interface.
#group(name) ⇒ Vedeu::Groups::Group
Specify a group for an interface. Interfaces of the same group can be targetted together; for example you may want to refresh multiple interfaces at once.
200 201 202 203 204 205 206 |
# File 'lib/vedeu/interfaces/dsl.rb', line 200 def group(name) return false unless present?(name) model.group = name Vedeu.groups.by_name(name).add(model.name) end |
#hide! ⇒ Boolean
Set the interface to invisible.
255 256 257 |
# File 'lib/vedeu/interfaces/dsl.rb', line 255 def hide! visible(false) end |
#initialize(model, client = nil) ⇒ void Originally defined in module DSL
Returns an instance of the DSL class including Vedeu::DSL.
#keymap(name = model.name, &block) ⇒ Object Also known as: keys
211 212 213 |
# File 'lib/vedeu/interfaces/dsl.rb', line 211 def keymap(name = model.name, &block) Vedeu.keymap(name, &block) end |
#name(value) ⇒ String|Symbol
The name of the interface. Used to reference the interface throughout your application’s execution lifetime.
228 229 230 |
# File 'lib/vedeu/interfaces/dsl.rb', line 228 def name(value) model.name = value end |
#no_cursor! ⇒ Vedeu::Cursors::Cursor Also known as: hide_cursor! Originally defined in module Cursors::DSL
Set the cursor to invisible for the interface or view.
#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.
#show! ⇒ Boolean Also known as: visible!
Set the interface to visible.
242 243 244 |
# File 'lib/vedeu/interfaces/dsl.rb', line 242 def show! visible(true) end |
#snake_case(name) ⇒ 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.
#style(value) ⇒ Vedeu::Presentation::Style Also known as: style=, styles, styles= Originally defined in module DSL::Presentation
Define a style or styles for an interface, line or a stream.
#text(value = '', options = {}) ⇒ String Also known as: text=, align, center, centre, left, right, align=, center=, centre=, left=, right= Originally defined in module DSL::Text
If using the convenience methods; left, centre, center or right, then a specified anchor will be ignored.
Specify the content for a view. Provides the means to align a string (or object responding to ‘to_s`), and add it as a Line or to the Stream.
#use(name) ⇒ Vedeu::Interfaces::Interface
Use a value from another model.
264 265 266 |
# File 'lib/vedeu/interfaces/dsl.rb', line 264 def use(name) model.repository.by_name(name) end |
#visible(value = true) ⇒ Boolean
Set the visibility of the interface.
294 295 296 297 298 |
# File 'lib/vedeu/interfaces/dsl.rb', line 294 def visible(value = true) boolean = value ? true : false model.visible = boolean end |
#zindex(value) ⇒ Fixnum Also known as: z_index, z
Set the zindex of the interface. This controls the render order of interfaces. Interfaces with a lower zindex will render before those with a higher zindex.
317 318 319 |
# File 'lib/vedeu/interfaces/dsl.rb', line 317 def zindex(value) model.zindex = value end |