Module: RulesEngineView::FormStyles

Included in:
FormBuilder
Defined in:
lib/rules_engine_view/form_styles.rb

Instance Method Summary collapse

Instance Method Details

#re_build_form_data(value, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rules_engine_view/form_styles.rb', line 37

def re_build_form_data value, options = {}
  result = "<div class='re-form-data".html_safe
  result << "-error" if options.include?(:error) && !options[:error].blank?
  result << " re-form-disabled" if options.include?(:disabled) && options[:disabled]
  result << " #{options[:class]}" if options.include?(:class)
  result << " span-#{options[:span] || '8'}"
  result << " last"
  result << "'" 
  result << " id='form_data_#{options[:id]}'" if options.include?(:id)
  result << ">".html_safe
  result << value
  if options.include?(:text) && !options[:text].blank?
    result << "<span class='form-text'>".html_safe
    result << options[:text]
    result << "</span>".html_safe
  end
  if options.include?(:hint) && !options[:hint].blank? && (!options.include?(:error) || options[:error].blank?)
    result << "<span class='form-hint'>".html_safe
    result << options[:hint]
    result << "</span>".html_safe
  end
  if options.include?(:error) && !options[:error].blank?
    result << "<span class='form-error-message'>".html_safe
    result << options[:error]
    result << "</span>".html_safe
  end
  result << "</div>".html_safe
  result      
end

#re_build_form_field(value, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rules_engine_view/form_styles.rb', line 4

def re_build_form_field(value, options = {})
  result = ''.html_safe
  result << "<div class='re-form-field".html_safe
  result << " re-form-disabled" if options.include?(:disabled) && options[:disabled]
  result << " #{options[:class]}" if options.include?(:class)
  result << " span-#{options[:span] || '12'}"
  result << " clear'"
  result << " id='form_field_#{options[:id]}'" unless options[:id].blank?
  result << ">".html_safe
  result << value
  result << "</div>".html_safe
  result      
end

#re_build_form_label(value, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rules_engine_view/form_styles.rb', line 18

def re_build_form_label value, options = {}
  result = "<div class='re-form-label".html_safe
  result << "-error" if options.include?(:error) && !options[:error].blank?
  result << " re-form-disabled" if options.include?(:disabled) && options[:disabled]
  result << " #{options[:class]}" if options.include?(:class)
  result << " span-#{options[:span] || '4'}"
  result << "'"
  result << " id='re_form_label_#{options[:id]}'" unless options[:id].blank?
  result << ">".html_safe
  result << value
  if options.include?(:required) && options[:required]
    result << "<span class='re-form-required".html_safe
    result << " re-form-disabled" if options.include?(:disabled) && options[:disabled]
    result << "'>*</span>".html_safe
  end  
  result << "</div>".html_safe
  result
end

#re_data_span(options) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rules_engine_view/form_styles.rb', line 82

def re_data_span(options)
  span = options[:span]
  if span =~ %r{^\d+x\d+$}
    return span.split("x")[1].to_i 
  elsif span =~ %r{^\d+$} 
    if span.to_i < 8
      return 8 - span.to_i 
    elsif span.to_i < 16
      return 16 - span.to_i 
    else  
      return 24 - span.to_i 
    end  
  end
  
  return 8
end

#re_error_on_tag(message) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/rules_engine_view/form_styles.rb', line 103

def re_error_on_tag(message)
  result = ''.html_safe
  result << '<div class="re-error"><p>'.html_safe
  result << message
  result << '</p></div>'.html_safe
  result
end

#re_field_span(options) ⇒ Object



99
100
101
# File 'lib/rules_engine_view/form_styles.rb', line 99

def re_field_span(options)
  re_label_span(options) + re_data_span(options)
end

#re_label_span(options) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/rules_engine_view/form_styles.rb', line 71

def re_label_span(options)      
  span = options[:span]
  if span =~ %r{^\d+x\d+$}
    return span.split("x")[0].to_i 
  elsif span =~ %r{^\d+$}
    return span.to_i 
  end
  
  return 4
end

#re_options_exclude(options) ⇒ Object



67
68
69
# File 'lib/rules_engine_view/form_styles.rb', line 67

def re_options_exclude(options)
  options.except(:error, :hint, :label, :text, :required, :span)
end