Class: Vedeu::Input::DSL
- Inherits:
-
Object
- Object
- Vedeu::Input::DSL
- Defined in:
- lib/vedeu/input/dsl.rb
Overview
You can define keymaps by name which matches a defined interface. When that interface is in focus, keys pressed as part of this definition will affect that interface. This allows you to form context driven behaviour for your application.
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
-
.keymap(name, &block) ⇒ Vedeu::Input::Keymap
Define actions for keypresses for when specific interfaces are in focus.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
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.
-
#demodulize(klass) ⇒ String
included
from Common
Removes the module part from the expression in the string.
-
#initialize(model, client = nil) ⇒ void
included
from DSL
Returns an instance of the DSL class including DSL.
-
#key(*values, &block) ⇒ Array
(also: #key=)
Define keypress(es) to perform an action.
-
#method_missing(method, *args, &block) ⇒ void
included
from DSL
private
Attempts to find the missing method on the client object.
-
#name(value) ⇒ String
(also: #name=)
Define the name of the keymap.
-
#present?(variable) ⇒ Boolean
included
from Common
Returns a boolean indicating whether a variable has a useful value.
-
#snake_case(name) ⇒ String
included
from Common
Converts a class name to a lowercase snake case string.
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
#model ⇒ void (readonly, protected) Originally defined in module DSL
Class Method Details
.keymap(name, &block) ⇒ Vedeu::Input::Keymap
Try to remember why we need to pre-create the keymap in the repository.
Define actions for keypresses for when specific interfaces are in focus. Unless an interface is specified, the key will be assumed to be global, meaning its action will happen regardless of the interface in focus.
Vedeu.keymap :my_interface do
key('s') { Vedeu.trigger(:save) }
key('h', :left) { Vedeu.trigger(:left) }
key('j', :down) { Vedeu.trigger(:down) }
key('p') do
# ... some code
end
# ... some code
end
# or...
Vedeu.keys :my_interface do
# ... some code
end
# or...
Vedeu.interface :my_interface do
keymap do
# ... some code
end # or...
keys do
# ... some code
end
end
55 56 57 58 59 |
# File 'lib/vedeu/input/dsl.rb', line 55 def self.keymap(name, &block) Vedeu::Input::Keymap.new(name: name).store Vedeu::Input::Keymap.build(name: name, &block).store end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
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.
#demodulize(klass) ⇒ String Originally defined in module Common
Removes the module part from the expression in the string.
#initialize(model, client = nil) ⇒ void Originally defined in module DSL
Returns an instance of the DSL class including Vedeu::DSL.
#key(*values, &block) ⇒ Array Also known as: key=
Define keypress(es) to perform an action.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vedeu/input/dsl.rb', line 74 def key(*values, &block) fail Vedeu::Error::InvalidSyntax, 'No action defined for `key`.'.freeze unless block_given? fail Vedeu::Error::InvalidSyntax, 'No keypress(es) defined for `key`.'.freeze unless present?(values) values.each do |value| unless present?(value) fail Vedeu::Error::InvalidSyntax, 'An invalid value for `key` was encountered.'.freeze end model.add(model.member.new(value, &block)) end end |
#name(value) ⇒ String Also known as: name=
Define the name of the keymap.
To only allow certain keys to work with specific interfaces, use the same name as the interface.
When the name :global is used, all keys in the keymap block will be available to all interfaces. Once a key has been defined in the :global keymap, it cannot be used for a specific interface.
Vedeu.keymap do
name :some_interface
end
108 109 110 |
# File 'lib/vedeu/input/dsl.rb', line 108 def name(value) model.name = value end |
#present?(variable) ⇒ Boolean Originally defined in module Common
Returns a boolean indicating whether a variable has a useful value.
#snake_case(name) ⇒ String Originally defined in module Common
Converts a class name to a lowercase snake case string.