| Module | Erubis::Helpers::RailsFormHelper |
| In: |
lib/erubis/helpers/rails_form_helper.rb
|
# File lib/erubis/helpers/rails_form_helper.rb, line 107
107: def _pp_check_box_checked?(value, checked_value)
108: return ActionView::Helpers::InstanceTag::check_box_checked?(value, checked_value)
109: end
# File lib/erubis/helpers/rails_form_helper.rb, line 47
47: def _pp_error_tags(value)
48: return value ? ['<div class="fieldWithErrors">', '</div>'] : ['', '']
49: end
# File lib/erubis/helpers/rails_form_helper.rb, line 118
118: def _pp_radio_button_checked?(value, tag_value)
119: return ActionView::Helpers::InstanceTag::radio_button_checked?(value, tag_value)
120: end
# File lib/erubis/helpers/rails_form_helper.rb, line 51
51: def _pp_remove_error_div(s)
52: s.sub!(/\A<div class="fieldWithErrors">(.*)<\/div>\z/, '\1')
53: return s
54: end
# File lib/erubis/helpers/rails_form_helper.rb, line 122
122: def _pp_select(object, method, collection, priority_collection, options={}, html_options={})
123: return pp_error_on(object, method) do
124: s = ""
125: ## start tag
126: s << "<select id=\"#{object}_#{method}\" name=\"#{object}[#{method}]\""
127: for key, val in html_options:
128: s << " #{key}=\"#{val}\""
129: end
130: s << ">\n"
131: ## selected table
132: key = options.key?(:value) ? :value : (options.key?('value') ? 'value' : nil)
133: if key.nil? ; selected = "@#{object}.#{method}"
134: elsif (val=options[key]).nil? ; selected = nil
135: elsif val =~ /\A<%=(.*)%>\z/ ; selected = $1
136: else ; selected = val.inspect
137: end
138: s << "<% _table = {#{selected}=>' selected=\"selected\"'} %>\n" if selected
139: ## <option> tags
140: if options[:include_blank] || options['include_blank']
141: s << "<option value=\"\"></option>\n"
142: end
143: unless priority_collection.blank?
144: _pp_select_options(s, priority_collection, selected, 'delete')
145: s << "<option value=\"\">-------------</option>\n"
146: end
147: _pp_select_options(s, collection, selected, '[]')
148: ## end tag
149: s << "</select>"
150: s
151: end
152: end
# File lib/erubis/helpers/rails_form_helper.rb, line 154
154: def _pp_select_options(s, collection, selected, operator)
155: for item in collection
156: value, text = item.is_a?(Array) ? item : [item, item]
157: if !selected
158: t = ''
159: elsif operator == 'delete'
160: t = "<%= _table.delete(#{value.inspect}) %>"
161: else
162: t = "<%= _table[#{value.inspect}] %>"
163: end
164: s << "<option value=\"#{h value}\"#{t}>#{h text}</option>\n"
165: end
166: end
# File lib/erubis/helpers/rails_form_helper.rb, line 100
100: def pp_check_box(object_name, method, options={}, checked_value="1", unchecked_value="0")
101: s = check_box(object_name, method, options, checked_value, unchecked_value)
102: s.sub!(/\schecked=\"checked\"/, '')
103: s.sub!(/type="checkbox"/, "\\&<%= _pp_check_box_checked?(@#{object_name}.#{method}, #{checked_value.inspect}) ? ' checked=\"checked\"' : '' %>")
104: return pp_error_on(object_name, method) { _pp_remove_error_div(s) }
105: end
# File lib/erubis/helpers/rails_form_helper.rb, line 172
172: def pp_collection_select(object, method, collection, value_method, text_method, options={}, html_options={})
173: collection2 = collection.collect { |e|
174: [e.__send__(value_method), e.__send__(text_method)]
175: }
176: return _pp_select(object, method, collection2, nil, options, html_options)
177: end
# File lib/erubis/helpers/rails_form_helper.rb, line 179
179: def pp_country_select(object, method, priority_countries=nil, options={}, html_options={})
180: collection = ActionView::Helpers::FormOptionsHelper::COUNTRIES
181: return _pp_select(object, method, collection, priority_countries, options, html_options)
182: end
# File lib/erubis/helpers/rails_form_helper.rb, line 38
38: def pp_error_on(object_name, method)
39: s = ''
40: s << "<% _stag, _etag = _pp_error_tags(@#{object_name}.errors.on('#{method}')) %>"
41: s << "<%= _stag %>"
42: s << yield(object_name, method)
43: s << "<%= _etag %>"
44: return s
45: end
# File lib/erubis/helpers/rails_form_helper.rb, line 92
92: def pp_file_field(object_name, method, options={})
93: return pp_tag_helper(:file_field, object_name, method, options)
94: end
# File lib/erubis/helpers/rails_form_helper.rb, line 70
70: def pp_form_tag(url_for_options={}, options={}, *parameters_for_url, &block)
71: return form_tag(url_for_options, options, *parameters_for_url, &block)
72: end
# File lib/erubis/helpers/rails_form_helper.rb, line 88
88: def pp_hidden_field(object_name, method, options={})
89: return pp_tag_helper(:hidden_field, object_name, method, options)
90: end
# File lib/erubis/helpers/rails_form_helper.rb, line 194
194: def pp_image_submit_tag(source, options={})
195: return image_submit_tag(source, options)
196: end
# File lib/erubis/helpers/rails_form_helper.rb, line 84
84: def pp_password_field(object_name, method, options={})
85: return pp_tag_helper(:password_field, object_name, method, options)
86: end
# File lib/erubis/helpers/rails_form_helper.rb, line 111
111: def pp_radio_button(object_name, method, tag_value, options={})
112: s = radio_button(object_name, method, tag_value, options)
113: s.sub!(/\schecked=\"checked\"/, '')
114: s.sub!(/type="radio"/, "\\&<%= _pp_radio_button_checked?(@#{object_name}.#{method}, #{tag_value.inspect}) ? ' checked=\"checked\"' : '' %>")
115: return pp_error_on(object_name, method) { _pp_remove_error_div(s) }
116: end
# File lib/erubis/helpers/rails_form_helper.rb, line 31
31: def pp_render_partial(basename)
32: basename = "_#{basename}" unless basename[0] == ?_
33: filename = pp_template_filename(basename)
34: preprocessor = _create_preprocessor(File.read(filename))
35: return preprocessor.evaluate(_preprocessing_context_object())
36: end
# File lib/erubis/helpers/rails_form_helper.rb, line 168
168: def pp_select(object, method, collection, options={}, html_options={})
169: return _pp_select(object, method, collection, nil, options, html_options)
170: end
# File lib/erubis/helpers/rails_form_helper.rb, line 190
190: def pp_submit_tag(value="Save changes", options={})
191: return submit_tag(value, options)
192: end
# File lib/erubis/helpers/rails_form_helper.rb, line 56
56: def pp_tag_helper(helper, object_name, method, options={})
57: if object_name.is_a?(ActionView::Helpers::FormHelper)
58: object_name = object_name.object_name
59: end
60: unless options.key?(:value) || options.key?('value')
61: options['value'] = _?("h @#{object_name}.#{method}")
62: end
63: #$stderr.puts "*** debug: pp_tag_helper(): options=#{options.inspect}"
64: return pp_error_on(object_name, method) {
65: s = __send__(helper, object_name, method, options)
66: _pp_remove_error_div(s)
67: }
68: end
# File lib/erubis/helpers/rails_form_helper.rb, line 24
24: def pp_template_filename(basename)
25: fname = "#{RAILS_ROOT}/app/views/#{controller.controller_name}/#{basename}.html.erb"
26: return fname if test(?f, fname)
27: return "#{RAILS_ROOT}/app/views/#{controller.controller_name}/#{basename}.rhtml"
28: end
# File lib/erubis/helpers/rails_form_helper.rb, line 20
20: def pp_template_filename(basename)
21: return "#{RAILS_ROOT}/app/views/#{controller.controller_name}/#{basename}.rhtml"
22: end
# File lib/erubis/helpers/rails_form_helper.rb, line 96
96: def pp_text_area(object_name, method, options={})
97: return pp_tag_helper(:text_area, object_name, method, options)
98: end
# File lib/erubis/helpers/rails_form_helper.rb, line 80
80: def pp_text_field(object_name, method, options={})
81: return pp_tag_helper(:text_field, object_name, method, options)
82: end
# File lib/erubis/helpers/rails_form_helper.rb, line 184
184: def pp_time_zone_select(object, method, priority_zones=nil, options={}, html_options={})
185: model = options[:model] || options['model'] || TimeZone
186: collection = model.all.collect { |e| [e.name, e.to_s] }
187: return _pp_select(object, method, collection, priority_zones, options, html_options)
188: end