builtin/widgets/screen_variants.rb in rtml-2.0.3 vs builtin/widgets/screen_variants.rb in rtml-2.0.4

- old
+ new

@@ -12,11 +12,17 @@ # Examples: # screen :main do # next_screen :terminate_loop # next_screen :loop_again, :if => 'tmlvar:counter < tmlvar:loop_count' # end - def next(uri, options = {}) + def next(uri = :__not_set, options = {}) + if uri == :__not_set + next_element = (parent / 'next').first + return next_element.property('uri') if next_element + return parent.property('next') + end + unless options.empty? variant process_variant_options(options.merge(:uri => uri)) else next_element = (parent / 'next').first if next_element @@ -54,20 +60,41 @@ end end variants = (next_element / "variant") variants.each do |variant| # If variant contains the same conditions, replace the URI and return. - if (variant.property('lo') == options[:lo] && variant.property('ro') == options[:ro] && variant.property('op') == options[:op]) || - (options.key?('key') && variant.property('key') == options[:key]) || - (options.key?('timeout') && variant.property('timeout') == options[:timeout]) + if replaces_variant?(variant, options) variant.property('uri', options[:uri]) return variant end end next_element.build(:variant, options) end private + def replaces_variant?(variant, options) + equivalent_operation?(variant, options) \ + || same_key?(variant, options) \ + || both_timeout?(variant, options) + end + + def equivalent_operation?(variant, options) + options.key?(:lo) \ + && variant.property('lo') == options[:lo] \ + && variant.property('ro') == options[:ro] \ + && variant.property('op') == options[:op] + end + + def same_key?(variant, options) + options.key?(:key) \ + && variant.property('key') == options[:key] + end + + def both_timeout?(variant, options) + options.key?(:timeout) \ + && variant.property('timeout') == options[:timeout] + end + def process_variant_options(options) ret = {} if options[:lo] || options[:ro] || options[:op] options.delete(:unless) options[:if] = [options.delete(:lo), options.delete(:op), options.delete(:ro)]