Class: AdminWidgets::BaseFormWidget
- Inherits:
-
BaseWidget
- Object
- Erector::Widget
- BaseWidget
- AdminWidgets::BaseFormWidget
- Defined in:
- lib/admin_widgets/base_form_widget.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
- #around_form ⇒ Object
- #autofocus!(options = {}) ⇒ Object
-
#autofocus_done? ⇒ Boolean
FIXME: Beware, arcane magic below.
-
#builder ⇒ Object
TODO: WTF? Who the hell is overriding the ‘form’ method?.
- #content ⇒ Object
-
#field(name, options = {}) ⇒ Object
DSL methods.
- #form_content ⇒ Object
Methods inherited from BaseWidget
#capture, #content_block, #helper, #method_missing, #root
Methods included from Memoization
Methods included from Delegation
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AdminWidgets::BaseWidget
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
4 5 6 |
# File 'lib/admin_widgets/base_form_widget.rb', line 4 def form @form end |
Instance Method Details
#around_form ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/admin_widgets/base_form_widget.rb', line 25 def around_form form_method = @form ? :simple_fields_for : :simple_form_for helper.send(form_method, resource, :url => url, :as => as, :class => css_class, :html => @html) do |f| @form = f # IMPORTANT! capture do form_content end end end |
#autofocus!(options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/admin_widgets/base_form_widget.rb', line 46 def autofocus!( = {}) root.instance_variable_set(:@autofocus_done, true) { autofocus: true }.merge() end |
#autofocus_done? ⇒ Boolean
FIXME: Beware, arcane magic below. We are polluting the root widget with a instance variable, is there a better way to do this?
43 44 45 |
# File 'lib/admin_widgets/base_form_widget.rb', line 43 def autofocus_done? root.instance_variable_get(:@autofocus_done) end |
#builder ⇒ Object
TODO: WTF? Who the hell is overriding the ‘form’ method?
7 8 9 |
# File 'lib/admin_widgets/base_form_widget.rb', line 7 def builder form end |
#content ⇒ Object
21 22 23 |
# File 'lib/admin_widgets/base_form_widget.rb', line 21 def content rawtext around_form end |
#field(name, options = {}) ⇒ Object
DSL methods
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/admin_widgets/base_form_widget.rb', line 53 def field(name, = {}) = autofocus!() unless autofocus_done? condition = [:if] return if (condition.present? && !resource.instance_eval(&condition)) form = ([:nested] === false && self.respond_to?(:parent)) ? parent.form : self.form rawtext form.input(name, ) end |
#form_content ⇒ Object
37 38 39 40 |
# File 'lib/admin_widgets/base_form_widget.rb', line 37 def form_content content_block end |