Class: Caisson::Helpers::Form::Builder::Interpreti

Inherits:
Object
  • Object
show all
Defined in:
lib/caisson/helpers/form/builder/interpreti.rb

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Interpreti

Returns a new instance of Interpreti.



4
5
6
# File 'lib/caisson/helpers/form/builder/interpreti.rb', line 4

def initialize(record)
  @record = record
end

Instance Method Details

#field_choices(name, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/caisson/helpers/form/builder/interpreti.rb', line 8

def field_choices(name, options={})
  options.reverse_merge!(base_choices: nil, include_blank: false)

  if options[:base_choices] and options[:base_choices][0].is_a? Array
    choices = options[:base_choices]
  elsif options[:base_choices] or model_obj.respond_to? :options_for
    base_choices = [options[:base_choices] || model_obj.options_for(name.to_s)].compact.flatten
    choices = base_choices.map { |k| [field_option(name, k), k] }
  else
    choices = []
  end

  choices.insert(0, blank_choice(name)) if options[:include_blank]

  return choices
end

#field_errors(name) ⇒ Object



25
26
27
28
# File 'lib/caisson/helpers/form/builder/interpreti.rb', line 25

def field_errors(name)
  []
  #@core.errors[name].map{ |e| [I18n.translate_with_article('form.field'), field_label(name).downcase_utf8, e].join(' ')}
end

#field_hint(name) ⇒ Object



30
31
32
# File 'lib/caisson/helpers/form/builder/interpreti.rb', line 30

def field_hint(name)
  field_translation(name, 'hint')
end

#field_label(name) ⇒ Object



34
35
36
37
38
39
# File 'lib/caisson/helpers/form/builder/interpreti.rb', line 34

def field_label(name)
  text = field_translation(name, 'label')
  text = field_translation(name) if text.empty?

  return text
end

#field_option(field_name, option_name, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/caisson/helpers/form/builder/interpreti.rb', line 41

def field_option(field_name, option_name, options={})
  options.reverse_merge!(text: 'label')

  text = field_translation(field_name, "options.#{option_name}.#{options[:text]}")
  text = field_translation(field_name, "options.#{option_name}") if text.empty? and options[:text] == 'label'

  return text
end