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.
- data/CHANGELOG +223 -7
- data/README +6 -12
- data/Rakefile +11 -11
- data/lib/action_controller.rb +9 -9
- data/lib/action_controller/assertions/response_assertions.rb +29 -78
- data/lib/action_controller/assertions/routing_assertions.rb +33 -33
- data/lib/action_controller/assertions/selector_assertions.rb +9 -5
- data/lib/action_controller/base.rb +227 -161
- data/lib/action_controller/benchmarking.rb +37 -24
- data/lib/action_controller/caching/actions.rb +53 -21
- data/lib/action_controller/caching/fragments.rb +10 -36
- data/lib/action_controller/caching/sweeping.rb +3 -3
- data/lib/action_controller/cgi_ext/session.rb +2 -22
- data/lib/action_controller/cgi_process.rb +8 -46
- data/lib/action_controller/components.rb +4 -1
- data/lib/action_controller/cookies.rb +10 -0
- data/lib/action_controller/dispatcher.rb +49 -15
- data/lib/action_controller/filters.rb +48 -10
- data/lib/action_controller/headers.rb +16 -14
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +57 -60
- data/lib/action_controller/layout.rb +27 -53
- data/lib/action_controller/mime_responds.rb +5 -1
- data/lib/action_controller/mime_type.rb +64 -42
- data/lib/action_controller/mime_types.rb +2 -1
- data/lib/action_controller/performance_test.rb +16 -0
- data/lib/action_controller/polymorphic_routes.rb +16 -9
- data/lib/action_controller/rack_process.rb +303 -0
- data/lib/action_controller/request.rb +205 -97
- data/lib/action_controller/request_forgery_protection.rb +2 -2
- data/lib/action_controller/request_profiler.rb +0 -0
- data/lib/action_controller/rescue.rb +20 -115
- data/lib/action_controller/resources.rb +186 -83
- data/lib/action_controller/response.rb +140 -26
- data/lib/action_controller/routing.rb +28 -30
- data/lib/action_controller/routing/builder.rb +45 -54
- data/lib/action_controller/routing/optimisations.rb +31 -21
- data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
- data/lib/action_controller/routing/route.rb +162 -147
- data/lib/action_controller/routing/route_set.rb +8 -7
- data/lib/action_controller/routing/routing_ext.rb +4 -1
- data/lib/action_controller/routing/segments.rb +50 -21
- data/lib/action_controller/session/cookie_store.rb +3 -2
- data/lib/action_controller/session/drb_server.rb +7 -7
- data/lib/action_controller/session_management.rb +6 -2
- data/lib/action_controller/streaming.rb +15 -8
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +66 -2
- data/lib/action_controller/test_process.rb +71 -66
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +90 -13
- data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
- data/lib/action_controller/verification.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +19 -11
- data/lib/action_view/base.rb +184 -150
- data/lib/action_view/helpers.rb +38 -0
- data/lib/action_view/helpers/active_record_helper.rb +56 -27
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
- data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
- data/lib/action_view/helpers/benchmark_helper.rb +3 -3
- data/lib/action_view/helpers/cache_helper.rb +1 -2
- data/lib/action_view/helpers/capture_helper.rb +19 -44
- data/lib/action_view/helpers/date_helper.rb +486 -296
- data/lib/action_view/helpers/debug_helper.rb +20 -13
- data/lib/action_view/helpers/form_helper.rb +71 -30
- data/lib/action_view/helpers/form_options_helper.rb +15 -85
- data/lib/action_view/helpers/form_tag_helper.rb +61 -38
- data/lib/action_view/helpers/javascript_helper.rb +80 -89
- data/lib/action_view/helpers/number_helper.rb +179 -74
- data/lib/action_view/helpers/prototype_helper.rb +216 -201
- data/lib/action_view/helpers/record_tag_helper.rb +4 -5
- data/lib/action_view/helpers/sanitize_helper.rb +65 -33
- data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
- data/lib/action_view/helpers/tag_helper.rb +39 -22
- data/lib/action_view/helpers/text_helper.rb +212 -118
- data/lib/action_view/helpers/translation_helper.rb +21 -0
- data/lib/action_view/helpers/url_helper.rb +100 -58
- data/lib/action_view/inline_template.rb +13 -14
- data/lib/action_view/locale/en.yml +91 -0
- data/lib/action_view/partials.rb +100 -55
- data/lib/action_view/paths.rb +125 -0
- data/lib/action_view/renderable.rb +102 -0
- data/lib/action_view/renderable_partial.rb +48 -0
- data/lib/action_view/template.rb +90 -101
- data/lib/action_view/template_error.rb +11 -21
- data/lib/action_view/template_handler.rb +8 -28
- data/lib/action_view/template_handlers.rb +45 -0
- data/lib/action_view/template_handlers/builder.rb +5 -15
- data/lib/action_view/template_handlers/erb.rb +9 -6
- data/lib/action_view/template_handlers/rjs.rb +2 -17
- data/lib/action_view/test_case.rb +7 -4
- data/test/abstract_unit.rb +4 -1
- data/test/active_record_unit.rb +28 -30
- data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
- data/test/controller/action_pack_assertions_test.rb +8 -37
- data/test/controller/addresses_render_test.rb +0 -3
- data/test/controller/assert_select_test.rb +51 -24
- data/test/controller/base_test.rb +4 -4
- data/test/controller/caching_test.rb +136 -66
- data/test/controller/capture_test.rb +1 -21
- data/test/controller/cgi_test.rb +157 -10
- data/test/controller/components_test.rb +41 -25
- data/test/controller/content_type_test.rb +49 -17
- data/test/controller/cookie_test.rb +1 -1
- data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
- data/test/controller/dispatcher_test.rb +9 -1
- data/test/controller/filter_params_test.rb +2 -2
- data/test/controller/filters_test.rb +13 -13
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/node_test.rb +21 -0
- data/test/controller/html-scanner/sanitizer_test.rb +14 -0
- data/test/controller/integration_test.rb +167 -6
- data/test/controller/layout_test.rb +11 -68
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/mime_responds_test.rb +61 -59
- data/test/controller/mime_type_test.rb +6 -6
- data/test/controller/polymorphic_routes_test.rb +37 -2
- data/test/controller/rack_test.rb +323 -0
- data/test/controller/redirect_test.rb +72 -71
- data/test/controller/render_test.rb +1120 -108
- data/test/controller/request_forgery_protection_test.rb +66 -52
- data/test/controller/request_test.rb +103 -146
- data/test/controller/rescue_test.rb +20 -24
- data/test/controller/resources_test.rb +408 -25
- data/test/controller/routing_test.rb +1774 -1774
- data/test/controller/send_file_test.rb +0 -4
- data/test/controller/session/cookie_store_test.rb +53 -1
- data/test/controller/test_test.rb +15 -37
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +27 -28
- data/test/controller/view_paths_test.rb +48 -47
- data/test/fixtures/_top_level_partial.html.erb +1 -0
- data/test/fixtures/_top_level_partial_only.erb +1 -0
- data/test/fixtures/developers/_developer.erb +1 -0
- data/test/fixtures/fun/games/_game.erb +1 -0
- data/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/test/fixtures/layouts/_column.html.erb +2 -0
- data/test/fixtures/projects/_project.erb +1 -0
- data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/test/fixtures/replies/_reply.erb +1 -0
- data/test/fixtures/test/_counter.html.erb +1 -0
- data/test/fixtures/test/_customer.erb +1 -1
- data/test/fixtures/test/_customer_with_var.erb +1 -0
- data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hyphen-ated.erb +1 -0
- data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/test/fixtures/test/nested_layout.erb +3 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
- data/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/test/fixtures/test/template.erb +1 -0
- data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
- data/test/template/active_record_helper_i18n_test.rb +46 -0
- data/test/template/active_record_helper_test.rb +24 -24
- data/test/template/asset_tag_helper_test.rb +161 -29
- data/test/template/atom_feed_helper_test.rb +114 -5
- data/test/template/compiled_templates_test.rb +59 -0
- data/test/template/date_helper_i18n_test.rb +113 -0
- data/test/template/date_helper_test.rb +403 -109
- data/test/template/form_helper_test.rb +213 -154
- data/test/template/form_options_helper_test.rb +249 -897
- data/test/template/form_tag_helper_test.rb +80 -32
- data/test/template/javascript_helper_test.rb +17 -18
- data/test/template/number_helper_i18n_test.rb +54 -0
- data/test/template/number_helper_test.rb +43 -13
- data/test/template/prototype_helper_test.rb +101 -84
- data/test/template/record_tag_helper_test.rb +24 -20
- data/test/template/render_test.rb +193 -0
- data/test/template/sanitize_helper_test.rb +3 -3
- data/test/template/tag_helper_test.rb +34 -14
- data/test/template/text_helper_test.rb +83 -9
- data/test/template/translation_helper_test.rb +28 -0
- data/test/template/url_helper_test.rb +55 -18
- metadata +57 -18
- data/lib/action_view/helpers/javascripts/controls.js +0 -963
- data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
- data/lib/action_view/helpers/javascripts/effects.js +0 -1120
- data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
- data/lib/action_view/partial_template.rb +0 -70
- data/lib/action_view/template_finder.rb +0 -177
- data/lib/action_view/template_handlers/compilable.rb +0 -128
- data/test/controller/custom_handler_test.rb +0 -45
- data/test/controller/new_render_test.rb +0 -945
- data/test/fixtures/test/block_content_for.erb +0 -2
- data/test/fixtures/test/erb_content_for.erb +0 -2
- data/test/template/deprecated_erb_variable_test.rb +0 -9
- data/test/template/template_finder_test.rb +0 -73
- 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
|
-
|
72
|
-
when
|
73
|
-
escape =
|
74
|
-
|
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
|
-
|
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&baz=quux">Nonsense search</a>
|
173
201
|
#
|
174
|
-
# The three options
|
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(
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
236
|
+
tag_options = nil
|
198
237
|
end
|
199
238
|
|
200
|
-
|
201
|
-
|
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(
|
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(
|
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}#{
|
530
|
+
url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
|
489
531
|
else
|
490
|
-
url_string ==
|
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)
|
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
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
@
|
11
|
-
|
12
|
-
@handler = self.class.handler_class_for_extension(@extension).new(@view)
|
10
|
+
@method_segment = "inline_#{@source.hash.abs}"
|
13
11
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
+
|