Class: ExpressTemplates::Components::Forms::ExpressForm

Inherits:
Base
  • Object
show all
Includes:
Capabilities::Configurable, Capabilities::Parenting
Defined in:
lib/express_templates/components/forms/express_form.rb

Instance Attribute Summary

Attributes inherited from Expander

#handlers, #locals, #stack, #template

Instance Method Summary collapse

Methods included from Capabilities::Parenting

included

Methods included from Capabilities::Configurable

included

Methods inherited from Base

inherited

Methods included from Capabilities::Iterating

included

Methods included from Capabilities::Wrapping

included

Methods included from Capabilities::Rendering

included

Methods included from Capabilities::Templating

included

Methods included from Macro

included

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

#form_actionObject



23
24
25
26
27
28
29
30
31
# File 'lib/express_templates/components/forms/express_form.rb', line 23

def form_action
  if _modifying_resource?
    "{{#{resource_name_for_path}_path(@#{resource_name})}}"
  else # posting a new to a collection
    # We also have to take in to account singular resources 
    # e.g. resource :config -> will throw an unknown method error of configs_path
    "{{#{resource_name_for_path.pluralize}_path}}"
  end
end

#form_argsObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/express_templates/components/forms/express_form.rb', line 34

def form_args
  # there are no put/patch emthods in HTML5, so we have to enforce post
  # need to find a better way to do this: id/action can be overridden but method
  # should always be :post IN THE FORM TAG
  args = {id: form_id, action: form_action}.merge!(@config).merge!(method: :post)

  if html_options = args.delete(:html_options)
    args.merge!(html_options)
  end
  args[:method] = args[:method].to_s.upcase
  args
end

#form_idObject



15
16
17
# File 'lib/express_templates/components/forms/express_form.rb', line 15

def form_id
  "#{resource_name}_{{@#{resource_name}.id}}"
end

#form_methodObject



19
20
21
# File 'lib/express_templates/components/forms/express_form.rb', line 19

def form_method
  @config[:method]
end

#namespaceObject



55
56
57
# File 'lib/express_templates/components/forms/express_form.rb', line 55

def namespace
  @config[:namespace]
end

#resource_nameObject



51
52
53
# File 'lib/express_templates/components/forms/express_form.rb', line 51

def resource_name
  (@config[:resource_name] || @config[:id]).to_s
end

#resource_name_for_pathObject



47
48
49
# File 'lib/express_templates/components/forms/express_form.rb', line 47

def resource_name_for_path
  @config[:id].to_s
end