Class: AbstractInterface::ThemedFormHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/abstract_interface/themed_form_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ ThemedFormHelper

Returns a new instance of ThemedFormHelper.



5
6
7
# File 'lib/abstract_interface/themed_form_helper.rb', line 5

def initialize template
  self.template = template
end

Instance Attribute Details

#templateObject

Returns the value of attribute template.



3
4
5
# File 'lib/abstract_interface/themed_form_helper.rb', line 3

def template
  @template
end

Instance Method Details

#error_messages(*errors) ⇒ Object



9
10
11
12
# File 'lib/abstract_interface/themed_form_helper.rb', line 9

def error_messages *errors
  errors = errors.first if errors.size == 1 and errors.first.is_a? Array
  template.render template.themed_partial('forms/errors'), :object => errors
end

#form_field(options, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/abstract_interface/themed_form_helper.rb', line 14

def form_field options, &block
  html_options = options.to_openobject
  options = OpenObject.new
  
  # prepare options
  %w(errors label description required theme).each do |k| 
    v = html_options.delete k
    options[k] = v unless v.nil?
  end
  options.errors = options.errors.to_a

  # CSS style
  html_options.class ||= ""
  html_options << " themed_input"
  
  options.content = template.capture{block.call(html_options)}
  
  html = template.render(template.themed_partial('forms/field'), :object => options)
  template.concat html
end

#line(*items) ⇒ Object



35
36
37
# File 'lib/abstract_interface/themed_form_helper.rb', line 35

def line *items
  template.render template.themed_partial('forms/line'), :object => {:items => items, :delimiter => false}.to_openobject
end

#line_with_delimiters(*items) ⇒ Object



39
40
41
# File 'lib/abstract_interface/themed_form_helper.rb', line 39

def line_with_delimiters *items
  template.render template.themed_partial('forms/line'), :object => {:items => items, :delimiter => true}.to_openobject
end