Class: Adva::ExtensibleFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Adva::ExtensibleFormBuilder
- Defined in:
- lib/adva/extensible_forms.rb
Class Method Summary collapse
- .after(object_name, method, string = nil, &block) ⇒ Object
- .before(object_name, method, string = nil, &block) ⇒ Object
- .default_class_names(type = nil) ⇒ Object
- .tab(name, options = {}, &block) ⇒ Object
Instance Method Summary collapse
- #buttons(name = :submit_buttons, &block) ⇒ Object
- #field_set(*args, &block) ⇒ Object
- #render(*args) ⇒ Object
- #tab(name, &block) ⇒ Object
- #tabs ⇒ Object
Class Method Details
.after(object_name, method, string = nil, &block) ⇒ Object
60 61 62 |
# File 'lib/adva/extensible_forms.rb', line 60 def after(object_name, method, string = nil, &block) add_callback(:after, object_name, method, string || block) end |
.before(object_name, method, string = nil, &block) ⇒ Object
56 57 58 |
# File 'lib/adva/extensible_forms.rb', line 56 def before(object_name, method, string = nil, &block) add_callback(:before, object_name, method, string || block) end |
.default_class_names(type = nil) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/adva/extensible_forms.rb', line 48 def default_class_names(type = nil) if type self.[:default_class_names][type] ||= [] else self.[:default_class_names] end end |
.tab(name, options = {}, &block) ⇒ Object
64 65 66 67 |
# File 'lib/adva/extensible_forms.rb', line 64 def tab(name, = {}, &block) self.tabs.reject! { |n, b| name == n } self.tabs += [[name, block]] end |
Instance Method Details
#buttons(name = :submit_buttons, &block) ⇒ Object
155 156 157 158 159 |
# File 'lib/adva/extensible_forms.rb', line 155 def (name = :submit_buttons, &block) @template.concat with_callbacks(name) { @template.capture { @template.(&block) } } end |
#field_set(*args, &block) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/adva/extensible_forms.rb', line 108 def field_set(*args, &block) = args. = add_default_class_names(, :field_set) name = args.first name ||= :default_fields @template.concat with_callbacks(name) { legend = .delete(:legend) || '' legend = @template.content_tag('legend', legend) unless legend.blank? @template.field_set(@object_name, name, nil, ()) do legend.to_s + (block ? block.call.to_s : '') end } end |
#render(*args) ⇒ Object
161 162 163 |
# File 'lib/adva/extensible_forms.rb', line 161 def render(*args) @template.send(:render, *args) end |
#tab(name, &block) ⇒ Object
149 150 151 152 153 |
# File 'lib/adva/extensible_forms.rb', line 149 def tab(name, &block) with_callbacks(:"tab_#{name}") { self.class.tab(name, &block) } end |
#tabs ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/adva/extensible_forms.rb', line 124 def tabs yield if block_given? assign_ivars! @template.content_tag(:div, :class => 'tabs') { self.class.tabs.map.with_index { |(name, _), index| active = self.class.tabs.first.first == name %(<input type="radio" id="adva_current_tab_#{index}" name="adva_current_tab" #{"checked" if active}>) }.join.html_safe + @template.content_tag(:ul) { self.class.tabs.map.with_index { |(name, _), index| @template.content_tag(:li) { title = I18n.t(name, :scope => :'adva.titles') %(<label for="adva_current_tab_#{index}">#{title}</label>).html_safe } }.join.html_safe } + self.class.tabs.map.with_index { |(name, block), index| klass = self.class.tabs.first.first == name ? 'tab active' : 'tab' @template.content_tag 'fieldset', block.call(self), id: "tab_#{name}", class: klass, for: "adva_current_tab_#{index}" }.join.html_safe }.html_safe end |