Class: ExpressTemplates::Components::Forms::FormComponent
- Defined in:
- lib/express_templates/components/forms/form_component.rb
Instance Attribute Summary
Attributes inherited from Expander
#handlers, #locals, #stack, #template
Instance Method Summary collapse
- #compile(*args) ⇒ Object
-
#field_name ⇒ Object
Return the field_name as a string.
-
#field_name_attribute ⇒ Object
Return the field name attribute.
- #field_wrapper_class ⇒ Object
-
#label_name ⇒ Object
Return the name attribute for the lable.
-
#label_text ⇒ Object
Return the text content for the label.
-
#parent_form ⇒ Object
Search the parent graph until we find an ExpressForm.
- #resource_class ⇒ Object
-
#resource_name ⇒ Object
Lookup the resource_name from the parent ExpressForm.
- #resource_var ⇒ Object
Methods included from Capabilities::Adoptable
Methods included from Capabilities::Configurable
Methods inherited from Base
Methods included from Capabilities::Iterating
Methods included from Capabilities::Wrapping
Methods included from Capabilities::Rendering
Methods included from Capabilities::Templating
Methods included from Macro
Methods inherited from Expander
#expand, #initialize, #initialize_expander, #method_missing, #process_children!, register_macros_for
Constructor Details
This class inherits a constructor from ExpressTemplates::Expander
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ExpressTemplates::Expander
Instance Method Details
#compile(*args) ⇒ Object
8 9 10 11 |
# File 'lib/express_templates/components/forms/form_component.rb', line 8 def compile(*args) raise "#{self.class} requires a parent ExpressForm" if parent.nil? or parent_form.nil? super(*args) end |
#field_name ⇒ Object
Return the field_name as a string. This taken from the first argument to the component macro in the template or fragment.
42 43 44 |
# File 'lib/express_templates/components/forms/form_component.rb', line 42 def field_name (@config[:id] || (@args.first.is_a?(String) && @args.first)).to_s end |
#field_name_attribute ⇒ Object
Return the field name attribute. Currently handles only simple attributes on the resource. Does not handle attributes for associated resources.
48 49 50 |
# File 'lib/express_templates/components/forms/form_component.rb', line 48 def field_name_attribute "#{resource_name.singularize}[#{field_name}]" end |
#field_wrapper_class ⇒ Object
52 53 54 |
# File 'lib/express_templates/components/forms/form_component.rb', line 52 def field_wrapper_class @config[:wrapper_class] || 'field-wrapper' end |
#label_name ⇒ Object
Return the name attribute for the lable
31 32 33 |
# File 'lib/express_templates/components/forms/form_component.rb', line 31 def label_name "#{resource_name.singularize}_#{field_name}" end |
#label_text ⇒ Object
Return the text content for the label
36 37 38 |
# File 'lib/express_templates/components/forms/form_component.rb', line 36 def label_text @options[:label] || field_name.titleize end |
#parent_form ⇒ Object
Search the parent graph until we find an ExpressForm. Returns nil if none found.
57 58 59 60 61 62 63 |
# File 'lib/express_templates/components/forms/form_component.rb', line 57 def parent_form @my_form ||= parent until @my_form.nil? || @my_form.kind_of?(ExpressForm) @my_form = @my_form.parent end return @my_form end |
#resource_class ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/express_templates/components/forms/form_component.rb', line 22 def resource_class if namespace = parent_form.namespace "#{namespace}/#{resource_name}".classify else resource_name.classify end end |
#resource_name ⇒ Object
Lookup the resource_name from the parent ExpressForm.
14 15 16 |
# File 'lib/express_templates/components/forms/form_component.rb', line 14 def resource_name parent_form.resource_name end |
#resource_var ⇒ Object
18 19 20 |
# File 'lib/express_templates/components/forms/form_component.rb', line 18 def resource_var resource_name.to_sym end |