actionpack 2.1.2 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (200) hide show
  1. data/CHANGELOG +223 -7
  2. data/README +6 -12
  3. data/Rakefile +11 -11
  4. data/lib/action_controller.rb +9 -9
  5. data/lib/action_controller/assertions/response_assertions.rb +29 -78
  6. data/lib/action_controller/assertions/routing_assertions.rb +33 -33
  7. data/lib/action_controller/assertions/selector_assertions.rb +9 -5
  8. data/lib/action_controller/base.rb +227 -161
  9. data/lib/action_controller/benchmarking.rb +37 -24
  10. data/lib/action_controller/caching/actions.rb +53 -21
  11. data/lib/action_controller/caching/fragments.rb +10 -36
  12. data/lib/action_controller/caching/sweeping.rb +3 -3
  13. data/lib/action_controller/cgi_ext/session.rb +2 -22
  14. data/lib/action_controller/cgi_process.rb +8 -46
  15. data/lib/action_controller/components.rb +4 -1
  16. data/lib/action_controller/cookies.rb +10 -0
  17. data/lib/action_controller/dispatcher.rb +49 -15
  18. data/lib/action_controller/filters.rb +48 -10
  19. data/lib/action_controller/headers.rb +16 -14
  20. data/lib/action_controller/helpers.rb +2 -2
  21. data/lib/action_controller/http_authentication.rb +1 -1
  22. data/lib/action_controller/integration.rb +57 -60
  23. data/lib/action_controller/layout.rb +27 -53
  24. data/lib/action_controller/mime_responds.rb +5 -1
  25. data/lib/action_controller/mime_type.rb +64 -42
  26. data/lib/action_controller/mime_types.rb +2 -1
  27. data/lib/action_controller/performance_test.rb +16 -0
  28. data/lib/action_controller/polymorphic_routes.rb +16 -9
  29. data/lib/action_controller/rack_process.rb +303 -0
  30. data/lib/action_controller/request.rb +205 -97
  31. data/lib/action_controller/request_forgery_protection.rb +2 -2
  32. data/lib/action_controller/request_profiler.rb +0 -0
  33. data/lib/action_controller/rescue.rb +20 -115
  34. data/lib/action_controller/resources.rb +186 -83
  35. data/lib/action_controller/response.rb +140 -26
  36. data/lib/action_controller/routing.rb +28 -30
  37. data/lib/action_controller/routing/builder.rb +45 -54
  38. data/lib/action_controller/routing/optimisations.rb +31 -21
  39. data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
  40. data/lib/action_controller/routing/route.rb +162 -147
  41. data/lib/action_controller/routing/route_set.rb +8 -7
  42. data/lib/action_controller/routing/routing_ext.rb +4 -1
  43. data/lib/action_controller/routing/segments.rb +50 -21
  44. data/lib/action_controller/session/cookie_store.rb +3 -2
  45. data/lib/action_controller/session/drb_server.rb +7 -7
  46. data/lib/action_controller/session_management.rb +6 -2
  47. data/lib/action_controller/streaming.rb +15 -8
  48. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  49. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  50. data/lib/action_controller/test_case.rb +66 -2
  51. data/lib/action_controller/test_process.rb +71 -66
  52. data/lib/action_controller/translation.rb +13 -0
  53. data/lib/action_controller/url_rewriter.rb +90 -13
  54. data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
  55. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
  56. data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
  57. data/lib/action_controller/verification.rb +2 -2
  58. data/lib/action_pack/version.rb +1 -1
  59. data/lib/action_view.rb +19 -11
  60. data/lib/action_view/base.rb +184 -150
  61. data/lib/action_view/helpers.rb +38 -0
  62. data/lib/action_view/helpers/active_record_helper.rb +56 -27
  63. data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
  64. data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
  65. data/lib/action_view/helpers/benchmark_helper.rb +3 -3
  66. data/lib/action_view/helpers/cache_helper.rb +1 -2
  67. data/lib/action_view/helpers/capture_helper.rb +19 -44
  68. data/lib/action_view/helpers/date_helper.rb +486 -296
  69. data/lib/action_view/helpers/debug_helper.rb +20 -13
  70. data/lib/action_view/helpers/form_helper.rb +71 -30
  71. data/lib/action_view/helpers/form_options_helper.rb +15 -85
  72. data/lib/action_view/helpers/form_tag_helper.rb +61 -38
  73. data/lib/action_view/helpers/javascript_helper.rb +80 -89
  74. data/lib/action_view/helpers/number_helper.rb +179 -74
  75. data/lib/action_view/helpers/prototype_helper.rb +216 -201
  76. data/lib/action_view/helpers/record_tag_helper.rb +4 -5
  77. data/lib/action_view/helpers/sanitize_helper.rb +65 -33
  78. data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
  79. data/lib/action_view/helpers/tag_helper.rb +39 -22
  80. data/lib/action_view/helpers/text_helper.rb +212 -118
  81. data/lib/action_view/helpers/translation_helper.rb +21 -0
  82. data/lib/action_view/helpers/url_helper.rb +100 -58
  83. data/lib/action_view/inline_template.rb +13 -14
  84. data/lib/action_view/locale/en.yml +91 -0
  85. data/lib/action_view/partials.rb +100 -55
  86. data/lib/action_view/paths.rb +125 -0
  87. data/lib/action_view/renderable.rb +102 -0
  88. data/lib/action_view/renderable_partial.rb +48 -0
  89. data/lib/action_view/template.rb +90 -101
  90. data/lib/action_view/template_error.rb +11 -21
  91. data/lib/action_view/template_handler.rb +8 -28
  92. data/lib/action_view/template_handlers.rb +45 -0
  93. data/lib/action_view/template_handlers/builder.rb +5 -15
  94. data/lib/action_view/template_handlers/erb.rb +9 -6
  95. data/lib/action_view/template_handlers/rjs.rb +2 -17
  96. data/lib/action_view/test_case.rb +7 -4
  97. data/test/abstract_unit.rb +4 -1
  98. data/test/active_record_unit.rb +28 -30
  99. data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
  100. data/test/controller/action_pack_assertions_test.rb +8 -37
  101. data/test/controller/addresses_render_test.rb +0 -3
  102. data/test/controller/assert_select_test.rb +51 -24
  103. data/test/controller/base_test.rb +4 -4
  104. data/test/controller/caching_test.rb +136 -66
  105. data/test/controller/capture_test.rb +1 -21
  106. data/test/controller/cgi_test.rb +157 -10
  107. data/test/controller/components_test.rb +41 -25
  108. data/test/controller/content_type_test.rb +49 -17
  109. data/test/controller/cookie_test.rb +1 -1
  110. data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
  111. data/test/controller/dispatcher_test.rb +9 -1
  112. data/test/controller/filter_params_test.rb +2 -2
  113. data/test/controller/filters_test.rb +13 -13
  114. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  115. data/test/controller/html-scanner/node_test.rb +21 -0
  116. data/test/controller/html-scanner/sanitizer_test.rb +14 -0
  117. data/test/controller/integration_test.rb +167 -6
  118. data/test/controller/layout_test.rb +11 -68
  119. data/test/controller/logging_test.rb +46 -0
  120. data/test/controller/mime_responds_test.rb +61 -59
  121. data/test/controller/mime_type_test.rb +6 -6
  122. data/test/controller/polymorphic_routes_test.rb +37 -2
  123. data/test/controller/rack_test.rb +323 -0
  124. data/test/controller/redirect_test.rb +72 -71
  125. data/test/controller/render_test.rb +1120 -108
  126. data/test/controller/request_forgery_protection_test.rb +66 -52
  127. data/test/controller/request_test.rb +103 -146
  128. data/test/controller/rescue_test.rb +20 -24
  129. data/test/controller/resources_test.rb +408 -25
  130. data/test/controller/routing_test.rb +1774 -1774
  131. data/test/controller/send_file_test.rb +0 -4
  132. data/test/controller/session/cookie_store_test.rb +53 -1
  133. data/test/controller/test_test.rb +15 -37
  134. data/test/controller/translation_test.rb +26 -0
  135. data/test/controller/url_rewriter_test.rb +27 -28
  136. data/test/controller/view_paths_test.rb +48 -47
  137. data/test/fixtures/_top_level_partial.html.erb +1 -0
  138. data/test/fixtures/_top_level_partial_only.erb +1 -0
  139. data/test/fixtures/developers/_developer.erb +1 -0
  140. data/test/fixtures/fun/games/_game.erb +1 -0
  141. data/test/fixtures/fun/serious/games/_game.erb +1 -0
  142. data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
  143. data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
  144. data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
  145. data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
  146. data/test/fixtures/layouts/_column.html.erb +2 -0
  147. data/test/fixtures/projects/_project.erb +1 -0
  148. data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
  149. data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
  150. data/test/fixtures/replies/_reply.erb +1 -0
  151. data/test/fixtures/test/_counter.html.erb +1 -0
  152. data/test/fixtures/test/_customer.erb +1 -1
  153. data/test/fixtures/test/_customer_with_var.erb +1 -0
  154. data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
  155. data/test/fixtures/test/_local_inspector.html.erb +1 -0
  156. data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
  157. data/test/fixtures/test/hello.builder +1 -1
  158. data/test/fixtures/test/hyphen-ated.erb +1 -0
  159. data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
  160. data/test/fixtures/test/nested_layout.erb +3 -0
  161. data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
  162. data/test/fixtures/test/sub_template_raise.html.erb +1 -0
  163. data/test/fixtures/test/template.erb +1 -0
  164. data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
  165. data/test/template/active_record_helper_i18n_test.rb +46 -0
  166. data/test/template/active_record_helper_test.rb +24 -24
  167. data/test/template/asset_tag_helper_test.rb +161 -29
  168. data/test/template/atom_feed_helper_test.rb +114 -5
  169. data/test/template/compiled_templates_test.rb +59 -0
  170. data/test/template/date_helper_i18n_test.rb +113 -0
  171. data/test/template/date_helper_test.rb +403 -109
  172. data/test/template/form_helper_test.rb +213 -154
  173. data/test/template/form_options_helper_test.rb +249 -897
  174. data/test/template/form_tag_helper_test.rb +80 -32
  175. data/test/template/javascript_helper_test.rb +17 -18
  176. data/test/template/number_helper_i18n_test.rb +54 -0
  177. data/test/template/number_helper_test.rb +43 -13
  178. data/test/template/prototype_helper_test.rb +101 -84
  179. data/test/template/record_tag_helper_test.rb +24 -20
  180. data/test/template/render_test.rb +193 -0
  181. data/test/template/sanitize_helper_test.rb +3 -3
  182. data/test/template/tag_helper_test.rb +34 -14
  183. data/test/template/text_helper_test.rb +83 -9
  184. data/test/template/translation_helper_test.rb +28 -0
  185. data/test/template/url_helper_test.rb +55 -18
  186. metadata +57 -18
  187. data/lib/action_view/helpers/javascripts/controls.js +0 -963
  188. data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
  189. data/lib/action_view/helpers/javascripts/effects.js +0 -1120
  190. data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
  191. data/lib/action_view/partial_template.rb +0 -70
  192. data/lib/action_view/template_finder.rb +0 -177
  193. data/lib/action_view/template_handlers/compilable.rb +0 -128
  194. data/test/controller/custom_handler_test.rb +0 -45
  195. data/test/controller/new_render_test.rb +0 -945
  196. data/test/fixtures/test/block_content_for.erb +0 -2
  197. data/test/fixtures/test/erb_content_for.erb +0 -2
  198. data/test/template/deprecated_erb_variable_test.rb +0 -9
  199. data/test/template/template_finder_test.rb +0 -73
  200. data/test/template/template_object_test.rb +0 -95
@@ -0,0 +1,21 @@
1
+ require 'action_view/helpers/tag_helper'
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module TranslationHelper
6
+ def translate(key, options = {})
7
+ options[:raise] = true
8
+ I18n.translate(key, options)
9
+ rescue I18n::MissingTranslationData => e
10
+ keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
11
+ content_tag('span', keys.join(', '), :class => 'translation_missing')
12
+ end
13
+ alias :t :translate
14
+
15
+ def localize(*args)
16
+ I18n.localize *args
17
+ end
18
+ alias :l :localize
19
+ end
20
+ end
21
+ end
@@ -3,8 +3,8 @@ require 'action_view/helpers/javascript_helper'
3
3
  module ActionView
4
4
  module Helpers #:nodoc:
5
5
  # Provides a set of methods for making links and getting URLs that
6
- # depend on the routing subsystem (see ActionController::Routing).
7
- # This allows you to use the same format for links in views
6
+ # depend on the routing subsystem (see ActionController::Routing).
7
+ # This allows you to use the same format for links in views
8
8
  # and controllers.
9
9
  module UrlHelper
10
10
  include JavaScriptHelper
@@ -33,8 +33,8 @@ module ActionView
33
33
  #
34
34
  # If you instead of a hash pass a record (like an Active Record or Active Resource) as the options parameter,
35
35
  # you'll trigger the named route for that record. The lookup will happen on the name of the class. So passing
36
- # a Workshop object will attempt to use the workshop_path route. If you have a nested route, such as
37
- # admin_workshop_path you'll have to call that explicitly (it's impossible for url_for to guess that route).
36
+ # a Workshop object will attempt to use the workshop_path route. If you have a nested route, such as
37
+ # admin_workshop_path you'll have to call that explicitly (it's impossible for url_for to guess that route).
38
38
  #
39
39
  # ==== Examples
40
40
  # <%= url_for(:action => 'index') %>
@@ -62,19 +62,33 @@ module ActionView
62
62
  # <%= url_for(@workshop) %>
63
63
  # # calls @workshop.to_s
64
64
  # # => /workshops/5
65
+ #
66
+ # <%= url_for("http://www.example.com") %>
67
+ # # => http://www.example.com
68
+ #
69
+ # <%= url_for(:back) %>
70
+ # # if request.env["HTTP_REFERER"] is set to "http://www.example.com"
71
+ # # => http://www.example.com
72
+ #
73
+ # <%= url_for(:back) %>
74
+ # # if request.env["HTTP_REFERER"] is not set or is blank
75
+ # # => javascript:history.back()
65
76
  def url_for(options = {})
66
77
  options ||= {}
67
- case options
78
+ url = case options
79
+ when String
80
+ escape = true
81
+ options
68
82
  when Hash
69
83
  options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
70
84
  escape = options.key?(:escape) ? options.delete(:escape) : true
71
- url = @controller.send(:url_for, options)
72
- when String
73
- escape = true
74
- url = options
85
+ @controller.send(:url_for, options)
86
+ when :back
87
+ escape = false
88
+ @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
75
89
  else
76
90
  escape = false
77
- url = polymorphic_path(options)
91
+ polymorphic_path(options)
78
92
  end
79
93
 
80
94
  escape ? escape_once(url) : url
@@ -88,6 +102,13 @@ module ActionView
88
102
  # link will be used in place of a referrer if none exists. If nil is passed as
89
103
  # a name, the link itself will become the name.
90
104
  #
105
+ # ==== Signatures
106
+ #
107
+ # link_to(name, options = {}, html_options = nil)
108
+ # link_to(options = {}, html_options = nil) do
109
+ # # name
110
+ # end
111
+ #
91
112
  # ==== Options
92
113
  # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
93
114
  # prompt with the question specified. If the user accepts, the link is
@@ -109,8 +130,8 @@ module ActionView
109
130
  #
110
131
  # Note that if the user has JavaScript disabled, the request will fall back
111
132
  # to using GET. If <tt>:href => '#'</tt> is used and the user has JavaScript disabled
112
- # clicking the link will have no effect. If you are relying on the POST
113
- # behavior, your should check for it in your controller's action by using the
133
+ # clicking the link will have no effect. If you are relying on the POST
134
+ # behavior, your should check for it in your controller's action by using the
114
135
  # request object's methods for <tt>post?</tt>, <tt>delete?</tt> or <tt>put?</tt>.
115
136
  #
116
137
  # You can mix and match the +html_options+ with the exception of
@@ -134,8 +155,8 @@ module ActionView
134
155
  #
135
156
  # link_to "Profile", :controller => "profiles", :action => "show", :id => @profile
136
157
  # # => <a href="/profiles/show/1">Profile</a>
137
- #
138
- # Similarly,
158
+ #
159
+ # Similarly,
139
160
  #
140
161
  # link_to "Profiles", profiles_path
141
162
  # # => <a href="/profiles">Profiles</a>
@@ -145,6 +166,13 @@ module ActionView
145
166
  # link_to "Profiles", :controller => "profiles"
146
167
  # # => <a href="/profiles">Profiles</a>
147
168
  #
169
+ # You can use a block as well if your link target is hard to fit into the name parameter. ERb example:
170
+ #
171
+ # <% link_to(@profile) do %>
172
+ # <strong><%= @profile.name %></strong> -- <span>Check it out!!</span>
173
+ # <% end %>
174
+ # # => <a href="/profiles/1"><strong>David</strong> -- <span>Check it out!!</span></a>
175
+ #
148
176
  # Classes and ids for CSS are easy to produce:
149
177
  #
150
178
  # link_to "Articles", articles_path, :id => "news", :class => "article"
@@ -171,7 +199,7 @@ module ActionView
171
199
  # link_to "Nonsense search", searches_path(:foo => "bar", :baz => "quux")
172
200
  # # => <a href="/searches?foo=bar&amp;baz=quux">Nonsense search</a>
173
201
  #
174
- # The three options specfic to +link_to+ (<tt>:confirm</tt>, <tt>:popup</tt>, and <tt>:method</tt>) are used as follows:
202
+ # The three options specific to +link_to+ (<tt>:confirm</tt>, <tt>:popup</tt>, and <tt>:method</tt>) are used as follows:
175
203
  #
176
204
  # link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?"
177
205
  # # => <a href="http://www.rubyonrails.org/" onclick="return confirm('Are you sure?');">Visit Other Site</a>
@@ -183,31 +211,34 @@ module ActionView
183
211
  # # => <a href="/images/9" onclick="window.open(this.href,'new_window_name','height=300,width=600');return false;">View Image</a>
184
212
  #
185
213
  # link_to "Delete Image", @image, :confirm => "Are you sure?", :method => :delete
186
- # # => <a href="/images/9" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form');
214
+ # # => <a href="/images/9" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form');
187
215
  # f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;
188
- # var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
216
+ # var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method');
189
217
  # m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;">Delete Image</a>
190
- def link_to(name, options = {}, html_options = nil)
191
- url = case options
192
- when String
193
- options
194
- when :back
195
- @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
218
+ def link_to(*args, &block)
219
+ if block_given?
220
+ options = args.first || {}
221
+ html_options = args.second
222
+ concat(link_to(capture(&block), options, html_options))
223
+ else
224
+ name = args.first
225
+ options = args.second || {}
226
+ html_options = args.third
227
+
228
+ url = url_for(options)
229
+
230
+ if html_options
231
+ html_options = html_options.stringify_keys
232
+ href = html_options['href']
233
+ convert_options_to_javascript!(html_options, url)
234
+ tag_options = tag_options(html_options)
196
235
  else
197
- self.url_for(options)
236
+ tag_options = nil
198
237
  end
199
238
 
200
- if html_options
201
- html_options = html_options.stringify_keys
202
- href = html_options['href']
203
- convert_options_to_javascript!(html_options, url)
204
- tag_options = tag_options(html_options)
205
- else
206
- tag_options = nil
239
+ href_attr = "href=\"#{url}\"" unless href
240
+ "<a #{href_attr}#{tag_options}>#{name || url}</a>"
207
241
  end
208
-
209
- href_attr = "href=\"#{url}\"" unless href
210
- "<a #{href_attr}#{tag_options}>#{name || url}</a>"
211
242
  end
212
243
 
213
244
  # Generates a form containing a single button that submits to the URL created
@@ -236,7 +267,7 @@ module ActionView
236
267
  # * <tt>:confirm</tt> - This will add a JavaScript confirm
237
268
  # prompt with the question specified. If the user accepts, the link is
238
269
  # processed normally, otherwise no action is taken.
239
- #
270
+ #
240
271
  # ==== Examples
241
272
  # <%= button_to "New", :action => "new" %>
242
273
  # # => "<form method="post" action="/controller/new" class="button-to">
@@ -262,12 +293,12 @@ module ActionView
262
293
  end
263
294
 
264
295
  form_method = method.to_s == 'get' ? 'get' : 'post'
265
-
296
+
266
297
  request_token_tag = ''
267
298
  if form_method == 'post' && protect_against_forgery?
268
299
  request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
269
300
  end
270
-
301
+
271
302
  if confirm = html_options.delete("confirm")
272
303
  html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
273
304
  end
@@ -285,7 +316,7 @@ module ActionView
285
316
  # Creates a link tag of the given +name+ using a URL created by the set of
286
317
  # +options+ unless the current request URI is the same as the links, in
287
318
  # which case only the name is returned (or the given block is yielded, if
288
- # one exists). You can give link_to_unless_current a block which will
319
+ # one exists). You can give link_to_unless_current a block which will
289
320
  # specialize the default behavior (e.g., show a "Start Here" link rather
290
321
  # than the link's text).
291
322
  #
@@ -312,13 +343,13 @@ module ActionView
312
343
  # </ul>
313
344
  #
314
345
  # The implicit block given to link_to_unless_current is evaluated if the current
315
- # action is the action given. So, if we had a comments page and wanted to render a
346
+ # action is the action given. So, if we had a comments page and wanted to render a
316
347
  # "Go Back" link instead of a link to the comments page, we could do something like this...
317
- #
318
- # <%=
348
+ #
349
+ # <%=
319
350
  # link_to_unless_current("Comment", { :controller => 'comments', :action => 'new}) do
320
- # link_to("Go back", { :controller => 'posts', :action => 'index' })
321
- # end
351
+ # link_to("Go back", { :controller => 'posts', :action => 'index' })
352
+ # end
322
353
  # %>
323
354
  def link_to_unless_current(name, options = {}, html_options = {}, &block)
324
355
  link_to_unless current_page?(options), name, options, html_options, &block
@@ -335,10 +366,10 @@ module ActionView
335
366
  # # If the user is logged in...
336
367
  # # => <a href="/controller/reply/">Reply</a>
337
368
  #
338
- # <%=
369
+ # <%=
339
370
  # link_to_unless(@current_user.nil?, "Reply", { :action => "reply" }) do |name|
340
371
  # link_to(name, { :controller => "accounts", :action => "signup" })
341
- # end
372
+ # end
342
373
  # %>
343
374
  # # If the user is logged in...
344
375
  # # => <a href="/controller/reply/">Reply</a>
@@ -367,10 +398,10 @@ module ActionView
367
398
  # # If the user isn't logged in...
368
399
  # # => <a href="/sessions/new/">Login</a>
369
400
  #
370
- # <%=
401
+ # <%=
371
402
  # link_to_if(@current_user.nil?, "Login", { :controller => "sessions", :action => "new" }) do
372
403
  # link_to(@current_user.login, { :controller => "accounts", :action => "show", :id => @current_user })
373
- # end
404
+ # end
374
405
  # %>
375
406
  # # If the user isn't logged in...
376
407
  # # => <a href="/sessions/new/">Login</a>
@@ -407,20 +438,20 @@ module ActionView
407
438
  # * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
408
439
  #
409
440
  # ==== Examples
410
- # mail_to "me@domain.com"
441
+ # mail_to "me@domain.com"
411
442
  # # => <a href="mailto:me@domain.com">me@domain.com</a>
412
443
  #
413
- # mail_to "me@domain.com", "My email", :encode => "javascript"
414
- # # => <script type="text/javascript">eval(unescape('%64%6f%63...%6d%65%6e'))</script>
444
+ # mail_to "me@domain.com", "My email", :encode => "javascript"
445
+ # # => <script type="text/javascript">eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
415
446
  #
416
- # mail_to "me@domain.com", "My email", :encode => "hex"
447
+ # mail_to "me@domain.com", "My email", :encode => "hex"
417
448
  # # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
418
449
  #
419
- # mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email"
450
+ # mail_to "me@domain.com", nil, :replace_at => "_at_", :replace_dot => "_dot_", :class => "email"
420
451
  # # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
421
452
  #
422
453
  # mail_to "me@domain.com", "My email", :cc => "ccaddress@domain.com",
423
- # :subject => "This is an example email"
454
+ # :subject => "This is an example email"
424
455
  # # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
425
456
  def mail_to(email_address, name = nil, html_options = {})
426
457
  html_options = html_options.stringify_keys
@@ -445,7 +476,7 @@ module ActionView
445
476
  "document.write('#{content_tag("a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|
446
477
  string << sprintf("%%%x", c)
447
478
  end
448
- "<script type=\"#{Mime::JS}\">eval(unescape('#{string}'))</script>"
479
+ "<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>"
449
480
  elsif encode == "hex"
450
481
  email_address_encoded = ''
451
482
  email_address_obfuscated.each_byte do |c|
@@ -468,7 +499,7 @@ module ActionView
468
499
  # True if the current request URI was generated by the given +options+.
469
500
  #
470
501
  # ==== Examples
471
- # Let's say we're in the <tt>/shop/checkout</tt> action.
502
+ # Let's say we're in the <tt>/shop/checkout?order=desc</tt> action.
472
503
  #
473
504
  # current_page?(:action => 'process')
474
505
  # # => false
@@ -476,6 +507,9 @@ module ActionView
476
507
  # current_page?(:controller => 'shop', :action => 'checkout')
477
508
  # # => true
478
509
  #
510
+ # current_page?(:controller => 'shop', :action => 'checkout', :order => 'asc)
511
+ # # => false
512
+ #
479
513
  # current_page?(:action => 'checkout')
480
514
  # # => true
481
515
  #
@@ -484,10 +518,18 @@ module ActionView
484
518
  def current_page?(options)
485
519
  url_string = CGI.escapeHTML(url_for(options))
486
520
  request = @controller.request
521
+ # We ignore any extra parameters in the request_uri if the
522
+ # submitted url doesn't have any either. This lets the function
523
+ # work with things like ?order=asc
524
+ if url_string.index("?")
525
+ request_uri = request.request_uri
526
+ else
527
+ request_uri = request.request_uri.split('?').first
528
+ end
487
529
  if url_string =~ /^\w+:\/\//
488
- url_string == "#{request.protocol}#{request.host_with_port}#{request.request_uri}"
530
+ url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
489
531
  else
490
- url_string == request.request_uri
532
+ url_string == request_uri
491
533
  end
492
534
  end
493
535
 
@@ -509,7 +551,7 @@ module ActionView
509
551
  when method
510
552
  "#{method_javascript_function(method, url, href)}return false;"
511
553
  when popup
512
- popup_javascript_function(popup) + 'return false;'
554
+ "#{popup_javascript_function(popup)}return false;"
513
555
  else
514
556
  html_options["onclick"]
515
557
  end
@@ -1,20 +1,19 @@
1
1
  module ActionView #:nodoc:
2
- class InlineTemplate < Template #:nodoc:
3
-
4
- def initialize(view, source, locals = {}, type = nil)
5
- @view = view
6
- @finder = @view.finder
7
-
2
+ class InlineTemplate #:nodoc:
3
+ include Renderable
4
+
5
+ attr_reader :source, :extension, :method_segment
6
+
7
+ def initialize(source, type = nil)
8
8
  @source = source
9
9
  @extension = type
10
- @locals = locals || {}
11
-
12
- @handler = self.class.handler_class_for_extension(@extension).new(@view)
10
+ @method_segment = "inline_#{@source.hash.abs}"
13
11
  end
14
-
15
- def method_key
16
- @source
17
- end
18
-
12
+
13
+ private
14
+ # Always recompile inline templates
15
+ def recompile?(local_assigns)
16
+ true
17
+ end
19
18
  end
20
19
  end
@@ -0,0 +1,91 @@
1
+ "en":
2
+ number:
3
+ # Used in number_with_delimiter()
4
+ # These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
5
+ format:
6
+ # Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
7
+ separator: "."
8
+ # Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
9
+ delimiter: ","
10
+ # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
11
+ precision: 3
12
+
13
+ # Used in number_to_currency()
14
+ currency:
15
+ format:
16
+ # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
17
+ format: "%u%n"
18
+ unit: "$"
19
+ # These three are to override number.format and are optional
20
+ separator: "."
21
+ delimiter: ","
22
+ precision: 2
23
+
24
+ # Used in number_to_percentage()
25
+ percentage:
26
+ format:
27
+ # These three are to override number.format and are optional
28
+ # separator:
29
+ delimiter: ""
30
+ # precision:
31
+
32
+ # Used in number_to_precision()
33
+ precision:
34
+ format:
35
+ # These three are to override number.format and are optional
36
+ # separator:
37
+ delimiter: ""
38
+ # precision:
39
+
40
+ # Used in number_to_human_size()
41
+ human:
42
+ format:
43
+ # These three are to override number.format and are optional
44
+ # separator:
45
+ delimiter: ""
46
+ precision: 1
47
+
48
+ # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
49
+ datetime:
50
+ distance_in_words:
51
+ half_a_minute: "half a minute"
52
+ less_than_x_seconds:
53
+ one: "less than 1 second"
54
+ other: "less than {{count}} seconds"
55
+ x_seconds:
56
+ one: "1 second"
57
+ other: "{{count}} seconds"
58
+ less_than_x_minutes:
59
+ one: "less than a minute"
60
+ other: "less than {{count}} minutes"
61
+ x_minutes:
62
+ one: "1 minute"
63
+ other: "{{count}} minutes"
64
+ about_x_hours:
65
+ one: "about 1 hour"
66
+ other: "about {{count}} hours"
67
+ x_days:
68
+ one: "1 day"
69
+ other: "{{count}} days"
70
+ about_x_months:
71
+ one: "about 1 month"
72
+ other: "about {{count}} months"
73
+ x_months:
74
+ one: "1 month"
75
+ other: "{{count}} months"
76
+ about_x_years:
77
+ one: "about 1 year"
78
+ other: "about {{count}} years"
79
+ over_x_years:
80
+ one: "over 1 year"
81
+ other: "over {{count}} years"
82
+
83
+ activerecord:
84
+ errors:
85
+ template:
86
+ header:
87
+ one: "1 error prohibited this {{model}} from being saved"
88
+ other: "{{count}} errors prohibited this {{model}} from being saved"
89
+ # The variable :count is also available
90
+ body: "There were problems with the following fields:"
91
+