Class: Vedeu::Input::DSL Private
- Inherits:
-
Object
- Object
- Vedeu::Input::DSL
- Defined in:
- lib/vedeu/input/dsl.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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
Attributes included from DSL
Class Method Summary collapse
-
.keymap(name, &block) ⇒ Vedeu::Input::Keymap
private
Define actions for keypresses for when specific interfaces are in focus.
Instance Method Summary collapse
-
#key(*keys, &block) ⇒ Array
(also: #key=)
private
Define keypress(es) to perform an action.
- #valid_keys(keys) ⇒ Array<String|Symbol> private private
Methods included from DSL
#attributes, #initialize, #method_missing, #name
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?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Class Method Details
.keymap(name, &block) ⇒ Vedeu::Input::Keymap
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.
If a keymap with this name does not already exist, pre-register it, otherwise we have no way of knowing if a key defined in the DSL for this keymap has already been registered. This protects the client application from attempting to define the same key more than once for the same keymap.
This is also used when defining the ‘global’ keymap.
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
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vedeu/input/dsl.rb', line 67 def self.keymap(name, &block) raise Vedeu::Error::MissingRequired unless name raise Vedeu::Error::RequiresBlock unless block_given? unless Vedeu.keymaps.registered?(name) Vedeu::Input::Keymap.new(name: name).store end Vedeu::Input::Keymap.build(name: name, &block).store end |
Instance Method Details
#key(*keys, &block) ⇒ Array Also known as: key=
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.
Define keypress(es) to perform an action.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vedeu/input/dsl.rb', line 88 def key(*keys, &block) raise Vedeu::Error::InvalidSyntax, 'No action defined for `key`.' unless block_given? raise Vedeu::Error::InvalidSyntax, 'No keypresses defined for `key`.' unless present?(keys) valid_keys(keys).each do |key| model.add(Vedeu::Input::Key.new(key, &block)) end end |
#valid_keys(keys) ⇒ Array<String|Symbol> (private)
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.
105 106 107 108 109 |
# File 'lib/vedeu/input/dsl.rb', line 105 def valid_keys(keys) keys.compact.keep_if do |key| symbol?(key) || (string?(key) && present?(key)) end end |