Module: Reactive::WxOutput::Helpers::FormsHelper

Included in:
Binder
Defined in:
lib/reactive-wx/helpers/forms.rb

Instance Method Summary collapse

Instance Method Details

#form_name_and_container(form) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/reactive-wx/helpers/forms.rb', line 23

def form_name_and_container(form)
  case form
    when ::Wx::Window
      raise InvalidForm, "Window #{form} has no name!" unless name = form.get_name
      [name, form]
    when String
      raise InvalidForm, "No window named #{form}" unless win = ::Wx::Window.find_window_by_name(form, self)
      [form, win]
    when Hash
      form.to_a
    else
      raise InvalidForm, "Unhandled param, passed form: #{form.inspect}"
  end
end

#form_to_param(container) ⇒ Object



17
18
19
20
21
# File 'lib/reactive-wx/helpers/forms.rb', line 17

def form_to_param(container)
  form_param = {}
  container.get_children.each {|child| next unless child.get_name =~ /^[\da-z_]+$/ ;form_param[child.get_name] = child.get_data}       #TODO: Handle sub-children recursively
  form_param
end

#forms_to_params(forms) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/reactive-wx/helpers/forms.rb', line 9

def forms_to_params(forms)
  forms = [forms] unless forms.is_a?(Array)
  forms.compact.inject({}) do |params, form|
    form_name, container = form_name_and_container(form)
    params.update(form_name => form_to_param(container))
  end
end