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.
497 498 499 500 501 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 |
# File 'lib/htmlcom.rb', line 497 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, value] end.to_h .each do |key, value| h[key] << value 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 when :dropdown content = value.last 'Select' else 'Enter' end obj = klass[type].new content, id: id, label: action + ' ' + id.to_s 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
549 550 551 |
# File 'lib/htmlcom.rb', line 549 def to_doc() @form.to_doc end |
#to_html ⇒ Object
553 554 555 |
# File 'lib/htmlcom.rb', line 553 def to_html() @form.to_html end |