Class: Decidim::Toggle::SettingsFormBuilder
- Inherits:
-
FormBuilder
- Object
- FormBuilder
- Decidim::Toggle::SettingsFormBuilder
- Defined in:
- lib/decidim/toggle/settings_form_builder.rb
Overview
Form builder for add_tab form tabs. Renders all form attributes via #all_fields.
Form classes can define class method collection_for_require "decidim/core" so Decidim::FormBuilder autoload works.
Constant Summary collapse
- CALLOUT_CLASS_BY_TYPE =
{ info: "info", warning: "warning", danger: "alert" }.freeze
Instance Method Summary collapse
- #all_fields ⇒ Object
-
#fields_for_names(*names) ⇒ Object
Renders a subset of attributes (e.g. machine translation fields after a custom locale table).
- #informative_callouts ⇒ Object
Instance Method Details
#all_fields ⇒ Object
32 33 34 35 36 37 |
# File 'lib/decidim/toggle/settings_form_builder.rb', line 32 def all_fields fields = attribute_names.map do |name| @template.content_tag(:div, input_field(name), class: field_wrapper_classes(name)) end safe_join(fields) end |
#fields_for_names(*names) ⇒ Object
Renders a subset of attributes (e.g. machine translation fields after a custom locale table).
40 41 42 43 44 45 46 47 48 |
# File 'lib/decidim/toggle/settings_form_builder.rb', line 40 def fields_for_names(*names) names = names.flatten.map(&:to_s) fields = names.filter_map do |name| next unless object.class.respond_to?(:attribute_types) && object.class.attribute_types.has_key?(name) @template.content_tag(:div, input_field(name.to_sym), class: field_wrapper_classes(name)) end safe_join(fields) end |
#informative_callouts ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/decidim/toggle/settings_form_builder.rb', line 15 def informative_callouts return "".html_safe unless object.class.include?(InformativeCallouts) entries = object.visible_informative_callouts return "".html_safe if entries.blank? callouts = entries.map do |entry| callout = @template.cell( "decidim/announcement", entry.(object), callout_class: CALLOUT_CLASS_BY_TYPE.fetch(entry.type) ) @template.content_tag(:div, callout, class: InformativeCallouts::WRAPPER_CLASS) end safe_join(callouts) end |