Class: HtmlCom::FormBuilder
- Inherits:
-
Object
- Object
- HtmlCom::FormBuilder
- Defined in:
- lib/htmlcom.rb
Overview
e.g. inputs = [:textarea], audiotype: [:dropdown, ‘gsm’], voice: [:dropdown, ‘Stuart’]
= {audiotype: ['gsm', 'wav'], voice: %w(Stuart Kirsty Andrew)}
fb = HtmlCom::FormBuilder.new(inputs: inputs, options: options) puts fb.to_html
Instance Method Summary collapse
-
#initialize(inputs: {}, options: {}, id: 'form1', method: :get, action: '', debug: false) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #to_doc ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(inputs: {}, options: {}, id: 'form1', method: :get, action: '', debug: false) ⇒ FormBuilder
Returns a new instance of FormBuilder.
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/htmlcom.rb', line 502 def initialize(inputs: {}, options: {}, id: 'form1', method: :get, action: '', debug: false) @debug = debug h = inputs.map do |key, value| if debug then puts 'id: ' + key.inspect puts 'klass: ' + value.first.inspect end [key.to_sym, value] end.to_h if then .each do |key, value| h[key.to_sym] << value end end klass = { dropdown: HtmlCom::Dropdown, textarea: HtmlCom::Textarea, text: HtmlCom::Text, hidden: HtmlCom::Hidden } @form = HtmlCom::Form.new(id: id, method: method, action: action) h.each do |key, value| id = key puts 'value: ' + value.inspect type, content = value action = case type.to_sym when :dropdown content = value.last 'Select' else 'Enter' end puts 'type: ' + type.inspect obj = klass[type.to_sym].new content, id: id, label: action + ' ' + id.to_s puts 'after klass' obj.to_doc.root.element(type.to_s).elements.each do |e| @form.html_element.add e end end @form.add_submit end |
Instance Method Details
#to_doc ⇒ Object
558 559 560 |
# File 'lib/htmlcom.rb', line 558 def to_doc() @form.to_doc end |
#to_html ⇒ Object
562 563 564 |
# File 'lib/htmlcom.rb', line 562 def to_html() @form.to_html end |