Class: GovukElementsFormBuilder::BlockBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_elements_form_builder/block_buffer.rb

Overview

This class is intended to be a proxy for a FormBuilder object, and accumulate multiple form elements rendered inside a block. Its main reason for existence is to enable the following syntax when rendering revealing panels:

f.radio_button_fieldset :asked_for_help do |fieldset|

fieldset.radio_input(GenericYesNo::YES) do |radio|
  # Here, `radio` is a `BlockBuffer` instance, delegating all methods to
  # a `FormBuilder` instance, but doing the accumulation/concatenation.
  radio.text_field(:help_party)
  radio.text_field(:another_field)
  [...]
end
fieldset.radio_input(GenericYesNo::NO)

end

Instance Method Summary collapse

Constructor Details

#initialize(form_object) ⇒ BlockBuffer

Returns a new instance of BlockBuffer.



21
22
23
# File 'lib/govuk_elements_form_builder/block_buffer.rb', line 21

def initialize(form_object)
  @form_object = form_object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



25
26
27
# File 'lib/govuk_elements_form_builder/block_buffer.rb', line 25

def method_missing(method, *args, &block)
  safe_concat send(method, *args, &block)
end