Sha256: 0bfd1e978f72f48bf4f76dded0500a55d4bb3cd428db3837b7f9a04c43d0f1b6
Contents?: true
Size: 1.1 KB
Versions: 5
Compression:
Stored size: 1.1 KB
Contents
class Rtml::Widgets::EventListener < Rtml::Widget affects :document, :screen entry_point :on disable_subprocessing! def on(events) events.each do |key, destination| make_sure_key_is_valid(key) register_event(key, destination) end end def valid_keys case source_type when :document then %w(menu cancel) when :screen then %w(0 1 2 3 4 5 6 7 8 9 00 f1 f2 f3 f4 f5 f6 f7 f8 f9 down up menu stop cancel enter) end end # Returns the +defaults+ TML tag beneath the document's +head+ TML tag, or creates it. def defaults_tag head = (document / "head").first (head / "defaults").first || head.build(:defaults) end private def make_sure_key_is_valid(key) if !valid_keys.include?(key.to_s) raise Rtml::Errors::RulesViolationError, "Expected key to be one of #{valid_keys.to_sentence(:locale => :en)}; found #{key.inspect}" end end def register_event(key, destination) if source_type == :document defaults_tag.property(key, destination, :id_ref => true) else parent.goto destination, :key => key end end end
Version data entries
5 entries across 5 versions & 1 rubygems