actionpack 3.2.19 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +850 -401
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -288
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +39 -37
- data/lib/abstract_controller/callbacks.rb +101 -82
- data/lib/abstract_controller/collector.rb +7 -3
- data/lib/abstract_controller/helpers.rb +25 -13
- data/lib/abstract_controller/layouts.rb +74 -74
- data/lib/abstract_controller/logger.rb +1 -2
- data/lib/abstract_controller/rendering.rb +30 -13
- data/lib/abstract_controller/translation.rb +16 -1
- data/lib/abstract_controller/url_for.rb +6 -6
- data/lib/abstract_controller/view_paths.rb +1 -1
- data/lib/abstract_controller.rb +1 -8
- data/lib/action_controller/base.rb +46 -22
- data/lib/action_controller/caching/fragments.rb +23 -53
- data/lib/action_controller/caching.rb +46 -33
- data/lib/action_controller/deprecated/integration_test.rb +3 -0
- data/lib/action_controller/deprecated.rb +5 -1
- data/lib/action_controller/log_subscriber.rb +16 -8
- data/lib/action_controller/metal/conditional_get.rb +76 -32
- data/lib/action_controller/metal/data_streaming.rb +20 -26
- data/lib/action_controller/metal/exceptions.rb +19 -6
- data/lib/action_controller/metal/flash.rb +24 -9
- data/lib/action_controller/metal/force_ssl.rb +70 -12
- data/lib/action_controller/metal/head.rb +25 -4
- data/lib/action_controller/metal/helpers.rb +5 -9
- data/lib/action_controller/metal/hide_actions.rb +0 -1
- data/lib/action_controller/metal/http_authentication.rb +107 -83
- data/lib/action_controller/metal/implicit_render.rb +1 -1
- data/lib/action_controller/metal/instrumentation.rb +2 -1
- data/lib/action_controller/metal/live.rb +175 -0
- data/lib/action_controller/metal/mime_responds.rb +161 -47
- data/lib/action_controller/metal/params_wrapper.rb +112 -74
- data/lib/action_controller/metal/rack_delegation.rb +9 -3
- data/lib/action_controller/metal/redirecting.rb +15 -20
- data/lib/action_controller/metal/renderers.rb +11 -9
- data/lib/action_controller/metal/rendering.rb +9 -1
- data/lib/action_controller/metal/request_forgery_protection.rb +112 -19
- data/lib/action_controller/metal/responder.rb +20 -19
- data/lib/action_controller/metal/streaming.rb +12 -18
- data/lib/action_controller/metal/strong_parameters.rb +520 -0
- data/lib/action_controller/metal/testing.rb +13 -18
- data/lib/action_controller/metal/url_for.rb +28 -25
- data/lib/action_controller/metal.rb +17 -32
- data/lib/action_controller/model_naming.rb +12 -0
- data/lib/action_controller/railtie.rb +33 -17
- data/lib/action_controller/railties/helpers.rb +22 -0
- data/lib/action_controller/record_identifier.rb +18 -72
- data/lib/action_controller/test_case.rb +251 -131
- data/lib/action_controller/vendor/html-scanner.rb +4 -19
- data/lib/action_controller.rb +15 -6
- data/lib/action_dispatch/http/cache.rb +63 -11
- data/lib/action_dispatch/http/filter_parameters.rb +18 -8
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +49 -17
- data/lib/action_dispatch/http/mime_negotiation.rb +24 -1
- data/lib/action_dispatch/http/mime_type.rb +154 -100
- data/lib/action_dispatch/http/mime_types.rb +1 -1
- data/lib/action_dispatch/http/parameter_filter.rb +44 -46
- data/lib/action_dispatch/http/parameters.rb +28 -28
- data/lib/action_dispatch/http/rack_cache.rb +2 -3
- data/lib/action_dispatch/http/request.rb +64 -18
- data/lib/action_dispatch/http/response.rb +130 -35
- data/lib/action_dispatch/http/upload.rb +63 -20
- data/lib/action_dispatch/http/url.rb +98 -35
- data/lib/action_dispatch/journey/backwards.rb +5 -0
- data/lib/action_dispatch/journey/formatter.rb +146 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +44 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +156 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
- data/lib/action_dispatch/journey/nodes/node.rb +124 -0
- data/lib/action_dispatch/journey/parser.rb +206 -0
- data/lib/action_dispatch/journey/parser.y +47 -0
- data/lib/action_dispatch/journey/parser_extras.rb +23 -0
- data/lib/action_dispatch/journey/path/pattern.rb +196 -0
- data/lib/action_dispatch/journey/route.rb +124 -0
- data/lib/action_dispatch/journey/router/strexp.rb +24 -0
- data/lib/action_dispatch/journey/router/utils.rb +54 -0
- data/lib/action_dispatch/journey/router.rb +166 -0
- data/lib/action_dispatch/journey/routes.rb +75 -0
- data/lib/action_dispatch/journey/scanner.rb +61 -0
- data/lib/action_dispatch/journey/visitors.rb +197 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +34 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +5 -0
- data/lib/action_dispatch/middleware/callbacks.rb +9 -4
- data/lib/action_dispatch/middleware/cookies.rb +259 -114
- data/lib/action_dispatch/middleware/debug_exceptions.rb +26 -17
- data/lib/action_dispatch/middleware/exception_wrapper.rb +29 -3
- data/lib/action_dispatch/middleware/flash.rb +58 -58
- data/lib/action_dispatch/middleware/params_parser.rb +14 -29
- data/lib/action_dispatch/middleware/public_exceptions.rb +30 -14
- data/lib/action_dispatch/middleware/reloader.rb +6 -6
- data/lib/action_dispatch/middleware/remote_ip.rb +145 -39
- data/lib/action_dispatch/middleware/request_id.rb +2 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
- data/lib/action_dispatch/middleware/session/cookie_store.rb +82 -28
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +12 -45
- data/lib/action_dispatch/middleware/ssl.rb +70 -0
- data/lib/action_dispatch/middleware/stack.rb +6 -1
- data/lib/action_dispatch/middleware/static.rb +2 -1
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +14 -11
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +25 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +7 -9
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +15 -9
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +127 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +7 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +30 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +39 -13
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +6 -2
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +144 -0
- data/lib/action_dispatch/railtie.rb +16 -6
- data/lib/action_dispatch/request/session.rb +181 -0
- data/lib/action_dispatch/routing/inspector.rb +240 -0
- data/lib/action_dispatch/routing/mapper.rb +540 -291
- data/lib/action_dispatch/routing/polymorphic_routes.rb +16 -20
- data/lib/action_dispatch/routing/redirection.rb +46 -29
- data/lib/action_dispatch/routing/route_set.rb +207 -164
- data/lib/action_dispatch/routing/routes_proxy.rb +2 -0
- data/lib/action_dispatch/routing/url_for.rb +48 -33
- data/lib/action_dispatch/routing.rb +48 -83
- data/lib/action_dispatch/testing/assertions/dom.rb +3 -13
- data/lib/action_dispatch/testing/assertions/response.rb +32 -40
- data/lib/action_dispatch/testing/assertions/routing.rb +42 -41
- data/lib/action_dispatch/testing/assertions/selector.rb +17 -22
- data/lib/action_dispatch/testing/assertions/tag.rb +20 -23
- data/lib/action_dispatch/testing/integration.rb +65 -51
- data/lib/action_dispatch/testing/test_process.rb +9 -6
- data/lib/action_dispatch/testing/test_request.rb +7 -3
- data/lib/action_dispatch.rb +21 -15
- data/lib/action_pack/version.rb +7 -6
- data/lib/action_pack.rb +1 -1
- data/lib/action_view/base.rb +15 -34
- data/lib/action_view/buffers.rb +7 -1
- data/lib/action_view/context.rb +4 -4
- data/lib/action_view/dependency_tracker.rb +93 -0
- data/lib/action_view/digestor.rb +85 -0
- data/lib/action_view/flows.rb +1 -4
- data/lib/action_view/helpers/active_model_helper.rb +3 -4
- data/lib/action_view/helpers/asset_tag_helper.rb +215 -352
- data/lib/action_view/helpers/asset_url_helper.rb +355 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +13 -10
- data/lib/action_view/helpers/cache_helper.rb +150 -18
- data/lib/action_view/helpers/capture_helper.rb +44 -31
- data/lib/action_view/helpers/csrf_helper.rb +0 -2
- data/lib/action_view/helpers/date_helper.rb +269 -248
- data/lib/action_view/helpers/debug_helper.rb +10 -11
- data/lib/action_view/helpers/form_helper.rb +931 -537
- data/lib/action_view/helpers/form_options_helper.rb +341 -166
- data/lib/action_view/helpers/form_tag_helper.rb +190 -90
- data/lib/action_view/helpers/javascript_helper.rb +23 -16
- data/lib/action_view/helpers/number_helper.rb +148 -329
- data/lib/action_view/helpers/output_safety_helper.rb +3 -3
- data/lib/action_view/helpers/record_tag_helper.rb +17 -22
- data/lib/action_view/helpers/rendering_helper.rb +2 -2
- data/lib/action_view/helpers/sanitize_helper.rb +3 -6
- data/lib/action_view/helpers/tag_helper.rb +46 -33
- data/lib/action_view/helpers/tags/base.rb +147 -0
- data/lib/action_view/helpers/tags/check_box.rb +64 -0
- data/lib/action_view/helpers/tags/checkable.rb +16 -0
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +43 -0
- data/lib/action_view/helpers/tags/collection_helpers.rb +83 -0
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +36 -0
- data/lib/action_view/helpers/tags/collection_select.rb +28 -0
- data/lib/action_view/helpers/tags/color_field.rb +25 -0
- data/lib/action_view/helpers/tags/date_field.rb +13 -0
- data/lib/action_view/helpers/tags/date_select.rb +72 -0
- data/lib/action_view/helpers/tags/datetime_field.rb +22 -0
- data/lib/action_view/helpers/tags/datetime_local_field.rb +19 -0
- data/lib/action_view/helpers/tags/datetime_select.rb +8 -0
- data/lib/action_view/helpers/tags/email_field.rb +8 -0
- data/lib/action_view/helpers/tags/file_field.rb +8 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +29 -0
- data/lib/action_view/helpers/tags/hidden_field.rb +8 -0
- data/lib/action_view/helpers/tags/label.rb +65 -0
- data/lib/action_view/helpers/tags/month_field.rb +13 -0
- data/lib/action_view/helpers/tags/number_field.rb +18 -0
- data/lib/action_view/helpers/tags/password_field.rb +12 -0
- data/lib/action_view/helpers/tags/radio_button.rb +31 -0
- data/lib/action_view/helpers/tags/range_field.rb +8 -0
- data/lib/action_view/helpers/tags/search_field.rb +24 -0
- data/lib/action_view/helpers/tags/select.rb +40 -0
- data/lib/action_view/helpers/tags/tel_field.rb +8 -0
- data/lib/action_view/helpers/tags/text_area.rb +18 -0
- data/lib/action_view/helpers/tags/text_field.rb +29 -0
- data/lib/action_view/helpers/tags/time_field.rb +13 -0
- data/lib/action_view/helpers/tags/time_select.rb +8 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +20 -0
- data/lib/action_view/helpers/tags/url_field.rb +8 -0
- data/lib/action_view/helpers/tags/week_field.rb +13 -0
- data/lib/action_view/helpers/tags.rb +39 -0
- data/lib/action_view/helpers/text_helper.rb +130 -114
- data/lib/action_view/helpers/translation_helper.rb +32 -16
- data/lib/action_view/helpers/url_helper.rb +211 -270
- data/lib/action_view/helpers.rb +2 -4
- data/lib/action_view/locale/en.yml +1 -105
- data/lib/action_view/log_subscriber.rb +6 -4
- data/lib/action_view/lookup_context.rb +15 -28
- data/lib/action_view/model_naming.rb +12 -0
- data/lib/action_view/path_set.rb +8 -20
- data/lib/action_view/railtie.rb +6 -22
- data/lib/action_view/record_identifier.rb +84 -0
- data/lib/action_view/renderer/abstract_renderer.rb +25 -19
- data/lib/action_view/renderer/partial_renderer.rb +158 -81
- data/lib/action_view/renderer/renderer.rb +8 -12
- data/lib/action_view/renderer/streaming_template_renderer.rb +2 -5
- data/lib/action_view/renderer/template_renderer.rb +12 -10
- data/lib/action_view/routing_url_for.rb +107 -0
- data/lib/action_view/template/error.rb +22 -12
- data/lib/action_view/template/handlers/builder.rb +1 -1
- data/lib/action_view/template/handlers/erb.rb +40 -19
- data/lib/action_view/template/handlers/raw.rb +11 -0
- data/lib/action_view/template/handlers.rb +12 -9
- data/lib/action_view/template/resolver.rb +107 -53
- data/lib/action_view/template/text.rb +12 -8
- data/lib/action_view/template/types.rb +57 -0
- data/lib/action_view/template.rb +25 -23
- data/lib/action_view/test_case.rb +67 -42
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/document.rb +0 -0
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/node.rb +12 -12
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/sanitizer.rb +13 -2
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/selector.rb +9 -9
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/version.rb +0 -0
- data/lib/action_view/vendor/html-scanner.rb +20 -0
- data/lib/action_view.rb +17 -8
- metadata +184 -214
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require 'active_support/core_ext/
|
|
2
|
-
require 'active_support/core_ext/object/blank'
|
|
1
|
+
require 'active_support/core_ext/array/extract_options'
|
|
3
2
|
require 'action_dispatch/middleware/stack'
|
|
4
3
|
|
|
5
4
|
module ActionController
|
|
@@ -7,7 +6,7 @@ module ActionController
|
|
|
7
6
|
# allowing the following syntax in controllers:
|
|
8
7
|
#
|
|
9
8
|
# class PostsController < ApplicationController
|
|
10
|
-
# use AuthenticationMiddleware, :
|
|
9
|
+
# use AuthenticationMiddleware, except: [:index, :show]
|
|
11
10
|
# end
|
|
12
11
|
#
|
|
13
12
|
class MiddlewareStack < ActionDispatch::MiddlewareStack #:nodoc:
|
|
@@ -37,8 +36,7 @@ module ActionController
|
|
|
37
36
|
raise "MiddlewareStack#build requires an app" unless app
|
|
38
37
|
|
|
39
38
|
middlewares.reverse.inject(app) do |a, middleware|
|
|
40
|
-
middleware.valid?(action) ?
|
|
41
|
-
middleware.build(a) : a
|
|
39
|
+
middleware.valid?(action) ? middleware.build(a) : a
|
|
42
40
|
end
|
|
43
41
|
end
|
|
44
42
|
end
|
|
@@ -58,7 +56,7 @@ module ActionController
|
|
|
58
56
|
# And then to route requests to your metal controller, you would add
|
|
59
57
|
# something like this to <tt>config/routes.rb</tt>:
|
|
60
58
|
#
|
|
61
|
-
#
|
|
59
|
+
# get 'hello', to: HelloController.action(:index)
|
|
62
60
|
#
|
|
63
61
|
# The +action+ method returns a valid Rack application for the \Rails
|
|
64
62
|
# router to dispatch to.
|
|
@@ -114,7 +112,7 @@ module ActionController
|
|
|
114
112
|
# ==== Returns
|
|
115
113
|
# * <tt>string</tt>
|
|
116
114
|
def self.controller_name
|
|
117
|
-
@controller_name ||=
|
|
115
|
+
@controller_name ||= name.demodulize.sub(/Controller$/, '').underscore
|
|
118
116
|
end
|
|
119
117
|
|
|
120
118
|
# Delegates to the class' <tt>controller_name</tt>
|
|
@@ -181,19 +179,13 @@ module ActionController
|
|
|
181
179
|
@_status = Rack::Utils.status_code(status)
|
|
182
180
|
end
|
|
183
181
|
|
|
184
|
-
def response_body=(
|
|
185
|
-
body =
|
|
186
|
-
|
|
187
|
-
elsif val.nil? || val.respond_to?(:each)
|
|
188
|
-
val
|
|
189
|
-
else
|
|
190
|
-
[val]
|
|
191
|
-
end
|
|
192
|
-
super body
|
|
182
|
+
def response_body=(body)
|
|
183
|
+
body = [body] unless body.nil? || body.respond_to?(:each)
|
|
184
|
+
super
|
|
193
185
|
end
|
|
194
186
|
|
|
195
187
|
def performed?
|
|
196
|
-
response_body
|
|
188
|
+
response_body || (response && response.committed?)
|
|
197
189
|
end
|
|
198
190
|
|
|
199
191
|
def dispatch(name, request) #:nodoc:
|
|
@@ -211,36 +203,29 @@ module ActionController
|
|
|
211
203
|
class_attribute :middleware_stack
|
|
212
204
|
self.middleware_stack = ActionController::MiddlewareStack.new
|
|
213
205
|
|
|
214
|
-
def self.inherited(base) #nodoc:
|
|
215
|
-
base.middleware_stack =
|
|
206
|
+
def self.inherited(base) # :nodoc:
|
|
207
|
+
base.middleware_stack = middleware_stack.dup
|
|
216
208
|
super
|
|
217
209
|
end
|
|
218
210
|
|
|
219
|
-
#
|
|
211
|
+
# Pushes the given Rack middleware and its arguments to the bottom of the
|
|
212
|
+
# middleware stack.
|
|
220
213
|
def self.use(*args, &block)
|
|
221
214
|
middleware_stack.use(*args, &block)
|
|
222
215
|
end
|
|
223
216
|
|
|
224
|
-
# Alias for middleware_stack
|
|
217
|
+
# Alias for +middleware_stack+.
|
|
225
218
|
def self.middleware
|
|
226
219
|
middleware_stack
|
|
227
220
|
end
|
|
228
221
|
|
|
229
|
-
# Makes the controller a
|
|
230
|
-
#
|
|
222
|
+
# Makes the controller a Rack endpoint that runs the action in the given
|
|
223
|
+
# +env+'s +action_dispatch.request.path_parameters+ key.
|
|
231
224
|
def self.call(env)
|
|
232
225
|
action(env['action_dispatch.request.path_parameters'][:action]).call(env)
|
|
233
226
|
end
|
|
234
227
|
|
|
235
|
-
#
|
|
236
|
-
# multiple calls into MyController.action will return the same object
|
|
237
|
-
# for the same action.
|
|
238
|
-
#
|
|
239
|
-
# ==== Parameters
|
|
240
|
-
# * <tt>action</tt> - An action name
|
|
241
|
-
#
|
|
242
|
-
# ==== Returns
|
|
243
|
-
# * <tt>proc</tt> - A rack application
|
|
228
|
+
# Returns a Rack endpoint for the given action name.
|
|
244
229
|
def self.action(name, klass = ActionDispatch::Request)
|
|
245
230
|
middleware_stack.build(name.to_s) do |env|
|
|
246
231
|
new.dispatch(name, klass.new(env))
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module ActionController
|
|
2
|
+
module ModelNaming
|
|
3
|
+
# Converts the given object to an ActiveModel compliant one.
|
|
4
|
+
def convert_to_model(object)
|
|
5
|
+
object.respond_to?(:to_model) ? object.to_model : object
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def model_name_from_record_or_class(record_or_class)
|
|
9
|
+
(record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -3,42 +3,58 @@ require "action_controller"
|
|
|
3
3
|
require "action_dispatch/railtie"
|
|
4
4
|
require "action_view/railtie"
|
|
5
5
|
require "abstract_controller/railties/routes_helpers"
|
|
6
|
-
require "action_controller/railties/
|
|
6
|
+
require "action_controller/railties/helpers"
|
|
7
7
|
|
|
8
8
|
module ActionController
|
|
9
|
-
class Railtie < Rails::Railtie
|
|
9
|
+
class Railtie < Rails::Railtie #:nodoc:
|
|
10
10
|
config.action_controller = ActiveSupport::OrderedOptions.new
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
config.eager_load_namespaces << ActionController
|
|
13
|
+
|
|
14
|
+
initializer "action_controller.assets_config", :group => :all do |app|
|
|
15
|
+
app.config.action_controller.assets_dir ||= app.config.paths["public"].first
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
initializer "action_controller.
|
|
17
|
-
|
|
18
|
+
initializer "action_controller.set_helpers_path" do |app|
|
|
19
|
+
ActionController::Helpers.helpers_path = app.helpers_paths
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
initializer "action_controller.
|
|
21
|
-
|
|
22
|
+
initializer "action_controller.parameters_config" do |app|
|
|
23
|
+
options = app.config.action_controller
|
|
24
|
+
|
|
25
|
+
ActionController::Parameters.permit_all_parameters = options.delete(:permit_all_parameters) { false }
|
|
26
|
+
ActionController::Parameters.action_on_unpermitted_parameters = options.delete(:action_on_unpermitted_parameters) do
|
|
27
|
+
(Rails.env.test? || Rails.env.development?) ? :log : false
|
|
28
|
+
end
|
|
22
29
|
end
|
|
23
30
|
|
|
24
31
|
initializer "action_controller.set_configs" do |app|
|
|
25
32
|
paths = app.config.paths
|
|
26
33
|
options = app.config.action_controller
|
|
27
34
|
|
|
28
|
-
options.
|
|
29
|
-
options.
|
|
30
|
-
options.page_cache_directory ||= paths["public"].first
|
|
35
|
+
options.logger ||= Rails.logger
|
|
36
|
+
options.cache_store ||= Rails.cache
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
options.
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
options.javascripts_dir ||= paths["public/javascripts"].first
|
|
39
|
+
options.stylesheets_dir ||= paths["public/stylesheets"].first
|
|
40
|
+
|
|
41
|
+
# Ensure readers methods get compiled
|
|
42
|
+
options.asset_host ||= app.config.asset_host
|
|
43
|
+
options.relative_url_root ||= app.config.relative_url_root
|
|
36
44
|
|
|
37
45
|
ActiveSupport.on_load(:action_controller) do
|
|
38
46
|
include app.routes.mounted_helpers
|
|
39
47
|
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
|
|
40
|
-
extend ::ActionController::Railties::
|
|
41
|
-
|
|
48
|
+
extend ::ActionController::Railties::Helpers
|
|
49
|
+
|
|
50
|
+
options.each do |k,v|
|
|
51
|
+
k = "#{k}="
|
|
52
|
+
if respond_to?(k)
|
|
53
|
+
send(k, v)
|
|
54
|
+
elsif !Base.respond_to?(k)
|
|
55
|
+
raise "Invalid option key: #{k}"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
42
58
|
end
|
|
43
59
|
end
|
|
44
60
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module ActionController
|
|
2
|
+
module Railties
|
|
3
|
+
module Helpers
|
|
4
|
+
def inherited(klass)
|
|
5
|
+
super
|
|
6
|
+
return unless klass.respond_to?(:helpers_path=)
|
|
7
|
+
|
|
8
|
+
if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
|
|
9
|
+
paths = namespace.railtie_helpers_paths
|
|
10
|
+
else
|
|
11
|
+
paths = ActionController::Helpers.helpers_path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
klass.helpers_path = paths
|
|
15
|
+
|
|
16
|
+
if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
|
|
17
|
+
klass.helper :all
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,85 +1,31 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'action_view/record_identifier'
|
|
2
2
|
|
|
3
3
|
module ActionController
|
|
4
|
-
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
|
|
5
|
-
# Active Resources or pretty much any other model type that has an id. These patterns are then used to try elevate
|
|
6
|
-
# the view actions to a higher logical level. Example:
|
|
7
|
-
#
|
|
8
|
-
# # routes
|
|
9
|
-
# resources :posts
|
|
10
|
-
#
|
|
11
|
-
# # view
|
|
12
|
-
# <%= div_for(post) do %> <div id="post_45" class="post">
|
|
13
|
-
# <%= post.body %> What a wonderful world!
|
|
14
|
-
# <% end %> </div>
|
|
15
|
-
#
|
|
16
|
-
# # controller
|
|
17
|
-
# def update
|
|
18
|
-
# post = Post.find(params[:id])
|
|
19
|
-
# post.update_attributes(params[:post])
|
|
20
|
-
#
|
|
21
|
-
# redirect_to(post) # Calls polymorphic_url(post) which in turn calls post_url(post)
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
24
|
-
# As the example above shows, you can stop caring to a large extent what the actual id of the post is.
|
|
25
|
-
# You just know that one is being assigned and that the subsequent calls in redirect_to expect that
|
|
26
|
-
# same naming convention and allows you to write less code if you follow it.
|
|
27
4
|
module RecordIdentifier
|
|
28
|
-
|
|
5
|
+
MODULE_MESSAGE = 'Calling ActionController::RecordIdentifier.%s is deprecated and ' \
|
|
6
|
+
'will be removed in Rails 4.1, please call using ActionView::RecordIdentifier instead.'
|
|
7
|
+
INSTANCE_MESSAGE = '%s method will no longer be included by default in controllers ' \
|
|
8
|
+
'since Rails 4.1. If you would like to use it in controllers, please include ' \
|
|
9
|
+
'ActionView::RecordIdentifier module.'
|
|
29
10
|
|
|
30
|
-
JOIN = '_'.freeze
|
|
31
|
-
NEW = 'new'.freeze
|
|
32
|
-
|
|
33
|
-
# The DOM class convention is to use the singular form of an object or class. Examples:
|
|
34
|
-
#
|
|
35
|
-
# dom_class(post) # => "post"
|
|
36
|
-
# dom_class(Person) # => "person"
|
|
37
|
-
#
|
|
38
|
-
# If you need to address multiple instances of the same class in the same view, you can prefix the dom_class:
|
|
39
|
-
#
|
|
40
|
-
# dom_class(post, :edit) # => "edit_post"
|
|
41
|
-
# dom_class(Person, :edit) # => "edit_person"
|
|
42
|
-
def dom_class(record_or_class, prefix = nil)
|
|
43
|
-
singular = ActiveModel::Naming.param_key(record_or_class)
|
|
44
|
-
prefix ? "#{prefix}#{JOIN}#{singular}" : singular
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# The DOM id convention is to use the singular form of an object or class with the id following an underscore.
|
|
48
|
-
# If no id is found, prefix with "new_" instead. Examples:
|
|
49
|
-
#
|
|
50
|
-
# dom_id(Post.find(45)) # => "post_45"
|
|
51
|
-
# dom_id(Post.new) # => "new_post"
|
|
52
|
-
#
|
|
53
|
-
# If you need to address multiple instances of the same class in the same view, you can prefix the dom_id:
|
|
54
|
-
#
|
|
55
|
-
# dom_id(Post.find(45), :edit) # => "edit_post_45"
|
|
56
11
|
def dom_id(record, prefix = nil)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
else
|
|
60
|
-
dom_class(record, prefix || NEW)
|
|
61
|
-
end
|
|
12
|
+
ActiveSupport::Deprecation.warn(INSTANCE_MESSAGE % 'dom_id')
|
|
13
|
+
ActionView::RecordIdentifier.dom_id(record, prefix)
|
|
62
14
|
end
|
|
63
15
|
|
|
64
|
-
|
|
16
|
+
def dom_class(record, prefix = nil)
|
|
17
|
+
ActiveSupport::Deprecation.warn(INSTANCE_MESSAGE % 'dom_class')
|
|
18
|
+
ActionView::RecordIdentifier.dom_class(record, prefix)
|
|
19
|
+
end
|
|
65
20
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
# you should write a helper like 'person_record_from_dom_id' that will extract the key either based
|
|
70
|
-
# on the default implementation (which just joins all key attributes with '_') or on your own
|
|
71
|
-
# overwritten version of the method. By default, this implementation passes the key string through a
|
|
72
|
-
# method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to
|
|
73
|
-
# make sure yourself that your dom ids are valid, in case you overwrite this method.
|
|
74
|
-
def record_key_for_dom_id(record)
|
|
75
|
-
record = record.to_model if record.respond_to?(:to_model)
|
|
76
|
-
key = record.to_key
|
|
77
|
-
key ? sanitize_dom_id(key.join('_')) : key
|
|
21
|
+
def self.dom_id(record, prefix = nil)
|
|
22
|
+
ActiveSupport::Deprecation.warn(MODULE_MESSAGE % 'dom_id')
|
|
23
|
+
ActionView::RecordIdentifier.dom_id(record, prefix)
|
|
78
24
|
end
|
|
79
25
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
26
|
+
def self.dom_class(record, prefix = nil)
|
|
27
|
+
ActiveSupport::Deprecation.warn(MODULE_MESSAGE % 'dom_class')
|
|
28
|
+
ActionView::RecordIdentifier.dom_class(record, prefix)
|
|
83
29
|
end
|
|
84
30
|
end
|
|
85
31
|
end
|