Class: Freeberry::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/freeberry/utils.rb

Class Method Summary collapse

Class Method Details

.form_field(form_name, field_name, column, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/freeberry/utils.rb', line 12

def form_field(form_name, field_name, column, options={})
  field = case column.type
    when :string, :binary, :integer, :float, :decimal then 
      options[:class] = "'text'"
      "text_field"
    when :boolean then "check_box"
    when :datetime, :date, :timestamp, :time then 
      options[:extra_html] ||= "<script type='text/javascript'>
        $(function() {
         $('\##{form_name}_#{field_name}').datepicker({
          numberOfMonths: 1,
          dateFormat: 'dd.mm.yy'
         });
        });
      </script>"
      'text_field'
    when :text then 
      options[:cols] ||= 70
      options[:rows] ||= 5
      "text_area"
  end
  
  extra_html = options.delete(:extra_html) || ''
  
  options_fields = []
  options.each { |k, v| options_fields << ":#{k}=>#{v}" }
  
  options_str = ", {#{options_fields.join(', ')}}" unless options_fields.empty? 
  options_str ||= ''
  
  "<%= #{form_name}.#{field} #{field_name}#{options_str} %>#{extra_html}"
end

.parameterize_filename(filename) ⇒ Object



5
6
7
8
9
10
# File 'lib/freeberry/utils.rb', line 5

def parameterize_filename(filename)
  extension = File.extname(filename)
  basename = filename.gsub(/#{extension}$/, "")
  
  [basename.parameterize('_'), extension].join.downcase
end