Class: SWS::Repetition
- Defined in:
- lib/sws/Core/components/Repetition/Repetition.rb
Overview
-
index (settable) - an index of current item in list iterator
Instance Attribute Summary
Attributes inherited from Component
#action_components, #definition_component, #encoding, #html_attrs, #method_to_call, #name, #parameters, #parent, #request, #request_number, #slots, #subcomponents, #tokens
Instance Method Summary collapse
-
#append_to_response(response) ⇒ Object
Calls super for each element of @subcomponent_array.
-
#awake ⇒ Object
Calls awake repeatedly for each element in @subcomponent_array.
-
#create_component_tree ⇒ Object
Overriden method of the Component class - initializes elements of.
-
#initialize(name, request, parent, slots) ⇒ Repetition
constructor
A new instance of Repetition.
-
#perform_action ⇒ Object
Performs action - again, calls super for each element of.
-
#process_bindings ⇒ Object
Processes bindings - calls super for..
-
#sleep ⇒ Object
Calls sleep repeatedly for each element in @subcomponent_array.
-
#tokenize_binding(key, value) ⇒ Object
Tokenizes binding - retrieves iteration number from binding name and calls super with @subcomponents set to proper @subcomponent_array object.
Methods inherited from Component
#api_filename, #app, #container?, #content?, create, #definition_filename, #page, #process_parameters, #process_request, #remove_subcomponents, #session, #set_request_subcomponents, #slot_bound?, #subcomponent_for_name, synchronize_slot, #synchronize_slot?, #synchronize_slots, #template_filename, #update_binding, #url_string
Constructor Details
#initialize(name, request, parent, slots) ⇒ Repetition
Returns a new instance of Repetition.
17 18 19 20 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 17 def initialize ( name, request, parent, slots ) super @subcomponent_array = Array.new end |
Instance Method Details
#append_to_response(response) ⇒ Object
Calls super for each element of @subcomponent_array. Number of iteration is added to the name of the receiver.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 116 def append_to_response ( response ) #store original name of the repetition old_name = @name.dup() @list.each_index do |i| @slots["item"].value = @list[i] if ( slot_bound?("index") ) @slots["index"].value = i end @subcomponents = @subcomponent_array[i] # Add iteration number to the end of name - will be necessary in other phases @name << ".#{i}" super # Revert name @name = old_name.dup() end end |
#awake ⇒ Object
Calls awake repeatedly for each element in @subcomponent_array
38 39 40 41 42 43 44 45 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 38 def awake () @list.each_index do |i| @subcomponents = @subcomponent_array [i] super end end |
#create_component_tree ⇒ Object
Overriden method of the Component class - initializes elements of
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 61 def create_component_tree () @list = @slots["list"].value() @list.each_index do |i| @slots["item"].value = @list[i] if ( slot_bound?("index") ) @slots["index"].value = i end @subcomponent_array [i] = Array.new() @subcomponents = @subcomponent_array [i] super end end |
#perform_action ⇒ Object
Performs action - again, calls super for each element of
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 79 def perform_action () @list.each_index do |i| @slots["item"].value = @list[i] if ( slot_bound?("index") ) @slots["index"].value = i end @subcomponents = @subcomponent_array[i] #dirty hack to set bindings to proper values :) @subcomponents.each { |com| com.process_bindings() } next_page = super return next_page if ( next_page ) end return nil end |
#process_bindings ⇒ Object
Processes bindings - calls super for.. guest what? :)
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 100 def process_bindings () @list.each_index do |i| @slots["item"].value = @list[i] if ( slot_bound?("index") ) @slots["index"].value = i end @subcomponents = @subcomponent_array[i] super end end |
#sleep ⇒ Object
Calls sleep repeatedly for each element in @subcomponent_array
49 50 51 52 53 54 55 56 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 49 def sleep () @list.each_index do |i| @subcomponents = @subcomponent_array [i] super end end |
#tokenize_binding(key, value) ⇒ Object
Tokenizes binding - retrieves iteration number from binding name and calls super with @subcomponents set to proper @subcomponent_array object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sws/Core/components/Repetition/Repetition.rb', line 25 def tokenize_binding ( key,value ) if ( md = /^(\d+)\.(.*)$/.match( key ) ) #extract iteration number (must be present) and rest of binding @subcomponents = @subcomponent_array [md[1].to_i] super( md[2],value ) else #without dot - should never happen here (repetition has no settable bindings) raise( "Cannot set parameter #{key} to value #{value} in Repetition" ) end end |