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
126 127 128 129 130 |
# File 'lib/adva/extensible_forms.rb', line 126 def (name = :submit_buttons, &block) @template.concat with_callbacks(name) { @template.capture { @template.(&block) } } end |
#field_set(*args, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/adva/extensible_forms.rb', line 79 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
132 133 134 |
# File 'lib/adva/extensible_forms.rb', line 132 def render(*args) @template.send(:render, *args) end |
#tab(name, &block) ⇒ Object
120 121 122 123 124 |
# File 'lib/adva/extensible_forms.rb', line 120 def tab(name, &block) with_callbacks(:"tab_#{name}") { self.class.tab(name, &block) } end |
#tabs ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/adva/extensible_forms.rb', line 95 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 |