Class: Rad::Face::ThemedFormHelper

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ ThemedFormHelper

Returns a new instance of ThemedFormHelper.



4
5
6
# File 'lib/face/themed_form_helper.rb', line 4

def initialize template
  self.template = template
end

Instance Attribute Details

#templateObject

Returns the value of attribute template.



2
3
4
# File 'lib/face/themed_form_helper.rb', line 2

def template
  @template
end

Class Method Details

.generate_form_helper_methods(methods) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/face/themed_form_helper.rb', line 39

def self.generate_form_helper_methods methods
  methods.each do |m|
    define_method m do |*args|
      options = args.extract_options!
      template.capture do
        form_field options do |html_options|
          args << html_options
          template.concat(template.send(m, *args))
        end
      end
    end
  end
end

Instance Method Details

#error_messages(*errors) ⇒ Object



8
9
10
11
# File 'lib/face/themed_form_helper.rb', line 8

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



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

def form_field options, &block      
  html_options = options.to_openobject
  options = Rad::Face::HtmlOpenObject.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



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

def line *items
  object = Rad::Face::HtmlOpenObject.initialize_from(items: items)
  template.render template.themed_partial('/forms/line'), object: object
end