Class: VCFB::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/vcfb/template.rb

Overview

Several FormBuilder methods are more complex and have changed a good bit between between Rails releases. Rather than trying to keep up with these changes, we put together an intermediate Template class (see VCFB::FormBuilder) to defer the compnetifying until after it’s gone through ActionView::Helpers::FormBuilder.

Instance Method Summary collapse

Constructor Details

#initialize(template, form) ⇒ Template

Returns a new instance of Template.



8
9
10
11
# File 'lib/vcfb/template.rb', line 8

def initialize(template, form)
  @template = template
  @form = form
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



41
42
43
# File 'lib/vcfb/template.rb', line 41

def method_missing(method_name, *args, &block)
  @template.public_send(method_name, *args, &block)
end

Instance Method Details

#button_tag(value, options) ⇒ Object

Custom Tag Helpers



15
16
17
18
19
20
21
22
23
# File 'lib/vcfb/template.rb', line 15

def button_tag(value, options)
  block = options.delete(:_block_for_component)
  if @form.component_defined?(:button)
    @form.componentify_with_slots(:button, value, options, &block)
  else
    value = @template.capture(value, &block)
    super(value, options)
  end
end

#public_send(method_name, *args, &block) ⇒ Object



37
38
39
# File 'lib/vcfb/template.rb', line 37

def public_send(method_name, *args, &block)
  @template.public_send(method_name, *args, &block)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/vcfb/template.rb', line 45

def respond_to_missing?(method_name, include_private = false)
  @template.respond_to?(method_name, include_private)
end

#send(method_name, *args, &block) ⇒ Object

Forward everything else to @template



33
34
35
# File 'lib/vcfb/template.rb', line 33

def send(method_name, *args, &block)
  @template.send(method_name, *args, &block)
end

#submit_tag(value, options) ⇒ Object



25
26
27
28
29
# File 'lib/vcfb/template.rb', line 25

def submit_tag(value, options)
  return super unless @form.component_defined?(:submit)

  @form.componentify(:submit, value, options)
end