Class: SimpleFormDependentFields::DependentFieldsBuilder
- Inherits:
-
Object
- Object
- SimpleFormDependentFields::DependentFieldsBuilder
- Extended by:
- Forwardable
- Defined in:
- lib/simple_form_dependent_fields/dependent_fields_builder.rb
Constant Summary collapse
- BASE_DOM_CLASS =
'simple_form_dependent_fields'
Instance Attribute Summary collapse
-
#builder ⇒ Object
Returns the value of attribute builder.
-
#options ⇒ Object
Returns the value of attribute options.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #dependent_fields(&block) ⇒ Object
-
#initialize(builder, template, options = {}) ⇒ DependentFieldsBuilder
constructor
A new instance of DependentFieldsBuilder.
Constructor Details
#initialize(builder, template, options = {}) ⇒ DependentFieldsBuilder
Returns a new instance of DependentFieldsBuilder.
9 10 11 12 13 |
# File 'lib/simple_form_dependent_fields/dependent_fields_builder.rb', line 9 def initialize(builder, template, = {}) @builder = builder @template = template @options = end |
Instance Attribute Details
#builder ⇒ Object
Returns the value of attribute builder.
5 6 7 |
# File 'lib/simple_form_dependent_fields/dependent_fields_builder.rb', line 5 def builder @builder end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_form_dependent_fields/dependent_fields_builder.rb', line 5 def @options end |
#template ⇒ Object
Returns the value of attribute template.
5 6 7 |
# File 'lib/simple_form_dependent_fields/dependent_fields_builder.rb', line 5 def template @template end |
Instance Method Details
#dependent_fields(&block) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/simple_form_dependent_fields/dependent_fields_builder.rb', line 17 def dependent_fields(&block) html = template.capture(&block) tag_html = condition_valid? ? html : nil data_template_html = condition_valid? ? {} : { template_html: CGI.escapeHTML(html).html_safe } template.content_tag :div, tag_html, class: [dom_class, BASE_DOM_CLASS].reject(&:blank?).flatten, data: dom_data.merge(data_template_html) end |