actionpack 3.2.22.5 → 5.2.4
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +279 -603
- data/MIT-LICENSE +1 -1
- data/README.rdoc +13 -297
- data/lib/abstract_controller/asset_paths.rb +4 -2
- data/lib/abstract_controller/base.rb +82 -52
- data/lib/abstract_controller/caching/fragments.rb +166 -0
- data/lib/abstract_controller/caching.rb +66 -0
- data/lib/abstract_controller/callbacks.rb +117 -103
- data/lib/abstract_controller/collector.rb +18 -7
- data/lib/abstract_controller/error.rb +6 -0
- data/lib/abstract_controller/helpers.rb +65 -38
- data/lib/abstract_controller/logger.rb +3 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
- data/lib/abstract_controller/rendering.rb +77 -129
- data/lib/abstract_controller/translation.rb +21 -3
- data/lib/abstract_controller/url_for.rb +9 -7
- data/lib/abstract_controller.rb +12 -13
- data/lib/action_controller/api/api_rendering.rb +16 -0
- data/lib/action_controller/api.rb +149 -0
- data/lib/action_controller/base.rb +81 -40
- data/lib/action_controller/caching.rb +22 -62
- data/lib/action_controller/form_builder.rb +50 -0
- data/lib/action_controller/log_subscriber.rb +30 -18
- data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/lib/action_controller/metal/conditional_get.rb +190 -47
- data/lib/action_controller/metal/content_security_policy.rb +52 -0
- data/lib/action_controller/metal/cookies.rb +3 -3
- data/lib/action_controller/metal/data_streaming.rb +40 -65
- data/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
- data/lib/action_controller/metal/exceptions.rb +19 -12
- data/lib/action_controller/metal/flash.rb +42 -9
- data/lib/action_controller/metal/force_ssl.rb +79 -19
- data/lib/action_controller/metal/head.rb +35 -10
- data/lib/action_controller/metal/helpers.rb +31 -21
- data/lib/action_controller/metal/http_authentication.rb +182 -134
- data/lib/action_controller/metal/implicit_render.rb +62 -8
- data/lib/action_controller/metal/instrumentation.rb +28 -26
- data/lib/action_controller/metal/live.rb +312 -0
- data/lib/action_controller/metal/mime_responds.rb +159 -163
- data/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/lib/action_controller/metal/params_wrapper.rb +146 -93
- data/lib/action_controller/metal/redirecting.rb +80 -56
- data/lib/action_controller/metal/renderers.rb +119 -47
- data/lib/action_controller/metal/rendering.rb +89 -32
- data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
- data/lib/action_controller/metal/rescue.rb +9 -16
- data/lib/action_controller/metal/streaming.rb +39 -45
- data/lib/action_controller/metal/strong_parameters.rb +1086 -0
- data/lib/action_controller/metal/testing.rb +8 -29
- data/lib/action_controller/metal/url_for.rb +43 -32
- data/lib/action_controller/metal.rb +112 -106
- data/lib/action_controller/railtie.rb +56 -18
- data/lib/action_controller/railties/helpers.rb +24 -0
- data/lib/action_controller/renderer.rb +117 -0
- data/lib/action_controller/template_assertions.rb +11 -0
- data/lib/action_controller/test_case.rb +402 -347
- data/lib/action_controller.rb +31 -30
- data/lib/action_dispatch/http/cache.rb +133 -34
- data/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/lib/action_dispatch/http/filter_parameters.rb +40 -24
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +117 -16
- data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
- data/lib/action_dispatch/http/mime_type.rb +198 -146
- data/lib/action_dispatch/http/mime_types.rb +22 -7
- data/lib/action_dispatch/http/parameter_filter.rb +61 -49
- data/lib/action_dispatch/http/parameters.rb +94 -51
- data/lib/action_dispatch/http/rack_cache.rb +4 -3
- data/lib/action_dispatch/http/request.rb +262 -117
- data/lib/action_dispatch/http/response.rb +400 -86
- data/lib/action_dispatch/http/upload.rb +66 -29
- data/lib/action_dispatch/http/url.rb +232 -60
- data/lib/action_dispatch/journey/formatter.rb +189 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
- data/lib/action_dispatch/journey/nodes/node.rb +140 -0
- data/lib/action_dispatch/journey/parser.rb +199 -0
- data/lib/action_dispatch/journey/parser.y +50 -0
- data/lib/action_dispatch/journey/parser_extras.rb +31 -0
- data/lib/action_dispatch/journey/path/pattern.rb +199 -0
- data/lib/action_dispatch/journey/route.rb +203 -0
- data/lib/action_dispatch/journey/router/utils.rb +102 -0
- data/lib/action_dispatch/journey/router.rb +156 -0
- data/lib/action_dispatch/journey/routes.rb +82 -0
- data/lib/action_dispatch/journey/scanner.rb +64 -0
- data/lib/action_dispatch/journey/visitors.rb +268 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +30 -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 +7 -0
- data/lib/action_dispatch/middleware/callbacks.rb +17 -13
- data/lib/action_dispatch/middleware/cookies.rb +494 -162
- data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
- data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
- data/lib/action_dispatch/middleware/executor.rb +21 -0
- data/lib/action_dispatch/middleware/flash.rb +128 -91
- data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
- data/lib/action_dispatch/middleware/reloader.rb +6 -83
- data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
- data/lib/action_dispatch/middleware/request_id.rb +19 -15
- data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
- data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
- data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
- data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
- data/lib/action_dispatch/middleware/ssl.rb +150 -0
- data/lib/action_dispatch/middleware/stack.rb +33 -41
- data/lib/action_dispatch/middleware/static.rb +92 -48
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +134 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
- data/lib/action_dispatch/railtie.rb +29 -8
- data/lib/action_dispatch/request/session.rb +234 -0
- data/lib/action_dispatch/request/utils.rb +78 -0
- data/lib/action_dispatch/routing/endpoint.rb +17 -0
- data/lib/action_dispatch/routing/inspector.rb +225 -0
- data/lib/action_dispatch/routing/mapper.rb +1329 -582
- data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
- data/lib/action_dispatch/routing/redirection.rb +120 -50
- data/lib/action_dispatch/routing/route_set.rb +545 -322
- data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
- data/lib/action_dispatch/routing/url_for.rb +103 -34
- data/lib/action_dispatch/routing.rb +66 -99
- data/lib/action_dispatch/system_test_case.rb +147 -0
- data/lib/action_dispatch/system_testing/browser.rb +49 -0
- data/lib/action_dispatch/system_testing/driver.rb +59 -0
- data/lib/action_dispatch/system_testing/server.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +47 -0
- data/lib/action_dispatch/testing/assertions/response.rb +53 -42
- data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
- data/lib/action_dispatch/testing/assertions.rb +15 -9
- data/lib/action_dispatch/testing/integration.rb +361 -207
- data/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/lib/action_dispatch/testing/test_process.rb +28 -19
- data/lib/action_dispatch/testing/test_request.rb +30 -33
- data/lib/action_dispatch/testing/test_response.rb +35 -11
- data/lib/action_dispatch.rb +42 -32
- data/lib/action_pack/gem_version.rb +17 -0
- data/lib/action_pack/version.rb +7 -7
- data/lib/action_pack.rb +4 -2
- metadata +116 -175
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/fragments.rb +0 -127
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/integration_test.rb +0 -2
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/deprecated.rb +0 -3
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/hide_actions.rb +0 -41
- data/lib/action_controller/metal/rack_delegation.rb +0 -26
- data/lib/action_controller/metal/responder.rb +0 -286
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_controller/record_identifier.rb +0 -85
- data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_controller/vendor/html-scanner.rb +0 -20
- 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/params_parser.rb +0 -75
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -37
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/base.rb +0 -220
- data/lib/action_view/buffers.rb +0 -43
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/flows.rb +0 -79
- data/lib/action_view/helpers/active_model_helper.rb +0 -50
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
- 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/action_view/helpers/atom_feed_helper.rb +0 -200
- data/lib/action_view/helpers/cache_helper.rb +0 -64
- data/lib/action_view/helpers/capture_helper.rb +0 -203
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1062
- data/lib/action_view/helpers/debug_helper.rb +0 -40
- data/lib/action_view/helpers/form_helper.rb +0 -1486
- data/lib/action_view/helpers/form_options_helper.rb +0 -658
- data/lib/action_view/helpers/form_tag_helper.rb +0 -685
- data/lib/action_view/helpers/javascript_helper.rb +0 -110
- data/lib/action_view/helpers/number_helper.rb +0 -622
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -111
- data/lib/action_view/helpers/rendering_helper.rb +0 -92
- data/lib/action_view/helpers/sanitize_helper.rb +0 -259
- data/lib/action_view/helpers/tag_helper.rb +0 -167
- data/lib/action_view/helpers/text_helper.rb +0 -426
- data/lib/action_view/helpers/translation_helper.rb +0 -91
- data/lib/action_view/helpers/url_helper.rb +0 -693
- data/lib/action_view/helpers.rb +0 -60
- data/lib/action_view/locale/en.yml +0 -160
- data/lib/action_view/log_subscriber.rb +0 -28
- data/lib/action_view/lookup_context.rb +0 -258
- data/lib/action_view/path_set.rb +0 -101
- data/lib/action_view/railtie.rb +0 -55
- data/lib/action_view/renderer/abstract_renderer.rb +0 -41
- data/lib/action_view/renderer/partial_renderer.rb +0 -415
- data/lib/action_view/renderer/renderer.rb +0 -61
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
- data/lib/action_view/renderer/template_renderer.rb +0 -95
- data/lib/action_view/template/error.rb +0 -128
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -125
- data/lib/action_view/template/handlers.rb +0 -50
- data/lib/action_view/template/resolver.rb +0 -298
- data/lib/action_view/template/text.rb +0 -30
- data/lib/action_view/template.rb +0 -337
- data/lib/action_view/test_case.rb +0 -246
- data/lib/action_view/testing/resolvers.rb +0 -49
- data/lib/action_view.rb +0 -84
- 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,286 +0,0 @@
|
|
1
|
-
require 'active_support/json'
|
2
|
-
|
3
|
-
module ActionController #:nodoc:
|
4
|
-
# Responsible for exposing a resource to different mime requests,
|
5
|
-
# usually depending on the HTTP verb. The responder is triggered when
|
6
|
-
# <code>respond_with</code> is called. The simplest case to study is a GET request:
|
7
|
-
#
|
8
|
-
# class PeopleController < ApplicationController
|
9
|
-
# respond_to :html, :xml, :json
|
10
|
-
#
|
11
|
-
# def index
|
12
|
-
# @people = Person.all
|
13
|
-
# respond_with(@people)
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# When a request comes in, for example for an XML response, three steps happen:
|
18
|
-
#
|
19
|
-
# 1) the responder searches for a template at people/index.xml;
|
20
|
-
#
|
21
|
-
# 2) if the template is not available, it will invoke <code>#to_xml</code> on the given resource;
|
22
|
-
#
|
23
|
-
# 3) if the responder does not <code>respond_to :to_xml</code>, call <code>#to_format</code> on it.
|
24
|
-
#
|
25
|
-
# === Builtin HTTP verb semantics
|
26
|
-
#
|
27
|
-
# The default \Rails responder holds semantics for each HTTP verb. Depending on the
|
28
|
-
# content type, verb and the resource status, it will behave differently.
|
29
|
-
#
|
30
|
-
# Using \Rails default responder, a POST request for creating an object could
|
31
|
-
# be written as:
|
32
|
-
#
|
33
|
-
# def create
|
34
|
-
# @user = User.new(params[:user])
|
35
|
-
# flash[:notice] = 'User was successfully created.' if @user.save
|
36
|
-
# respond_with(@user)
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# Which is exactly the same as:
|
40
|
-
#
|
41
|
-
# def create
|
42
|
-
# @user = User.new(params[:user])
|
43
|
-
#
|
44
|
-
# respond_to do |format|
|
45
|
-
# if @user.save
|
46
|
-
# flash[:notice] = 'User was successfully created.'
|
47
|
-
# format.html { redirect_to(@user) }
|
48
|
-
# format.xml { render :xml => @user, :status => :created, :location => @user }
|
49
|
-
# else
|
50
|
-
# format.html { render :action => "new" }
|
51
|
-
# format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
|
52
|
-
# end
|
53
|
-
# end
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# The same happens for PUT and DELETE requests.
|
57
|
-
#
|
58
|
-
# === Nested resources
|
59
|
-
#
|
60
|
-
# You can supply nested resources as you do in <code>form_for</code> and <code>polymorphic_url</code>.
|
61
|
-
# Consider the project has many tasks example. The create action for
|
62
|
-
# TasksController would be like:
|
63
|
-
#
|
64
|
-
# def create
|
65
|
-
# @project = Project.find(params[:project_id])
|
66
|
-
# @task = @project.comments.build(params[:task])
|
67
|
-
# flash[:notice] = 'Task was successfully created.' if @task.save
|
68
|
-
# respond_with(@project, @task)
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
# Giving several resources ensures that the responder will redirect to
|
72
|
-
# <code>project_task_url</code> instead of <code>task_url</code>.
|
73
|
-
#
|
74
|
-
# Namespaced and singleton resources require a symbol to be given, as in
|
75
|
-
# polymorphic urls. If a project has one manager which has many tasks, it
|
76
|
-
# should be invoked as:
|
77
|
-
#
|
78
|
-
# respond_with(@project, :manager, @task)
|
79
|
-
#
|
80
|
-
# Note that if you give an array, it will be treated as a collection,
|
81
|
-
# so the following is not equivalent:
|
82
|
-
#
|
83
|
-
# respond_with [@project, :manager, @task]
|
84
|
-
#
|
85
|
-
# === Custom options
|
86
|
-
#
|
87
|
-
# <code>respond_with</code> also allows you to pass options that are forwarded
|
88
|
-
# to the underlying render call. Those options are only applied for success
|
89
|
-
# scenarios. For instance, you can do the following in the create method above:
|
90
|
-
#
|
91
|
-
# def create
|
92
|
-
# @project = Project.find(params[:project_id])
|
93
|
-
# @task = @project.comments.build(params[:task])
|
94
|
-
# flash[:notice] = 'Task was successfully created.' if @task.save
|
95
|
-
# respond_with(@project, @task, :status => 201)
|
96
|
-
# end
|
97
|
-
#
|
98
|
-
# This will return status 201 if the task was saved successfully. If not,
|
99
|
-
# it will simply ignore the given options and return status 422 and the
|
100
|
-
# resource errors. To customize the failure scenario, you can pass a
|
101
|
-
# a block to <code>respond_with</code>:
|
102
|
-
#
|
103
|
-
# def create
|
104
|
-
# @project = Project.find(params[:project_id])
|
105
|
-
# @task = @project.comments.build(params[:task])
|
106
|
-
# respond_with(@project, @task, :status => 201) do |format|
|
107
|
-
# if @task.save
|
108
|
-
# flash[:notice] = 'Task was successfully created.'
|
109
|
-
# else
|
110
|
-
# format.html { render "some_special_template" }
|
111
|
-
# end
|
112
|
-
# end
|
113
|
-
# end
|
114
|
-
#
|
115
|
-
# Using <code>respond_with</code> with a block follows the same syntax as <code>respond_to</code>.
|
116
|
-
class Responder
|
117
|
-
attr_reader :controller, :request, :format, :resource, :resources, :options
|
118
|
-
|
119
|
-
ACTIONS_FOR_VERBS = {
|
120
|
-
:post => :new,
|
121
|
-
:put => :edit
|
122
|
-
}
|
123
|
-
|
124
|
-
def initialize(controller, resources, options={})
|
125
|
-
@controller = controller
|
126
|
-
@request = @controller.request
|
127
|
-
@format = @controller.formats.first
|
128
|
-
@resource = resources.last
|
129
|
-
@resources = resources
|
130
|
-
@options = options
|
131
|
-
@action = options.delete(:action)
|
132
|
-
@default_response = options.delete(:default_response)
|
133
|
-
end
|
134
|
-
|
135
|
-
delegate :head, :render, :redirect_to, :to => :controller
|
136
|
-
delegate :get?, :post?, :put?, :delete?, :to => :request
|
137
|
-
|
138
|
-
# Undefine :to_json and :to_yaml since it's defined on Object
|
139
|
-
undef_method(:to_json) if method_defined?(:to_json)
|
140
|
-
undef_method(:to_yaml) if method_defined?(:to_yaml)
|
141
|
-
|
142
|
-
# Initializes a new responder an invoke the proper format. If the format is
|
143
|
-
# not defined, call to_format.
|
144
|
-
#
|
145
|
-
def self.call(*args)
|
146
|
-
new(*args).respond
|
147
|
-
end
|
148
|
-
|
149
|
-
# Main entry point for responder responsible to dispatch to the proper format.
|
150
|
-
#
|
151
|
-
def respond
|
152
|
-
method = "to_#{format}"
|
153
|
-
respond_to?(method) ? send(method) : to_format
|
154
|
-
end
|
155
|
-
|
156
|
-
# HTML format does not render the resource, it always attempt to render a
|
157
|
-
# template.
|
158
|
-
#
|
159
|
-
def to_html
|
160
|
-
default_render
|
161
|
-
rescue ActionView::MissingTemplate => e
|
162
|
-
navigation_behavior(e)
|
163
|
-
end
|
164
|
-
|
165
|
-
# to_js simply tries to render a template. If no template is found, raises the error.
|
166
|
-
def to_js
|
167
|
-
default_render
|
168
|
-
end
|
169
|
-
|
170
|
-
# All other formats follow the procedure below. First we try to render a
|
171
|
-
# template, if the template is not available, we verify if the resource
|
172
|
-
# responds to :to_format and display it.
|
173
|
-
#
|
174
|
-
def to_format
|
175
|
-
if get? || !has_errors? || response_overridden?
|
176
|
-
default_render
|
177
|
-
else
|
178
|
-
display_errors
|
179
|
-
end
|
180
|
-
rescue ActionView::MissingTemplate => e
|
181
|
-
api_behavior(e)
|
182
|
-
end
|
183
|
-
|
184
|
-
protected
|
185
|
-
|
186
|
-
# This is the common behavior for formats associated with browsing, like :html, :iphone and so forth.
|
187
|
-
def navigation_behavior(error)
|
188
|
-
if get?
|
189
|
-
raise error
|
190
|
-
elsif has_errors? && default_action
|
191
|
-
render :action => default_action
|
192
|
-
else
|
193
|
-
redirect_to navigation_location
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
# This is the common behavior for formats associated with APIs, such as :xml and :json.
|
198
|
-
def api_behavior(error)
|
199
|
-
raise error unless resourceful?
|
200
|
-
|
201
|
-
if get?
|
202
|
-
display resource
|
203
|
-
elsif post?
|
204
|
-
display resource, :status => :created, :location => api_location
|
205
|
-
else
|
206
|
-
head :no_content
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
# Checks whether the resource responds to the current format or not.
|
211
|
-
#
|
212
|
-
def resourceful?
|
213
|
-
resource.respond_to?("to_#{format}")
|
214
|
-
end
|
215
|
-
|
216
|
-
# Returns the resource location by retrieving it from the options or
|
217
|
-
# returning the resources array.
|
218
|
-
#
|
219
|
-
def resource_location
|
220
|
-
options[:location] || resources
|
221
|
-
end
|
222
|
-
alias :navigation_location :resource_location
|
223
|
-
alias :api_location :resource_location
|
224
|
-
|
225
|
-
# If a response block was given, use it, otherwise call render on
|
226
|
-
# controller.
|
227
|
-
#
|
228
|
-
def default_render
|
229
|
-
if @default_response
|
230
|
-
@default_response.call(options)
|
231
|
-
else
|
232
|
-
controller.default_render(options)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
# Display is just a shortcut to render a resource with the current format.
|
237
|
-
#
|
238
|
-
# display @user, :status => :ok
|
239
|
-
#
|
240
|
-
# For XML requests it's equivalent to:
|
241
|
-
#
|
242
|
-
# render :xml => @user, :status => :ok
|
243
|
-
#
|
244
|
-
# Options sent by the user are also used:
|
245
|
-
#
|
246
|
-
# respond_with(@user, :status => :created)
|
247
|
-
# display(@user, :status => :ok)
|
248
|
-
#
|
249
|
-
# Results in:
|
250
|
-
#
|
251
|
-
# render :xml => @user, :status => :created
|
252
|
-
#
|
253
|
-
def display(resource, given_options={})
|
254
|
-
controller.render given_options.merge!(options).merge!(format => resource)
|
255
|
-
end
|
256
|
-
|
257
|
-
def display_errors
|
258
|
-
controller.render format => resource_errors, :status => :unprocessable_entity
|
259
|
-
end
|
260
|
-
|
261
|
-
# Check whether the resource has errors.
|
262
|
-
#
|
263
|
-
def has_errors?
|
264
|
-
resource.respond_to?(:errors) && !resource.errors.empty?
|
265
|
-
end
|
266
|
-
|
267
|
-
# By default, render the <code>:edit</code> action for HTML requests with failure, unless
|
268
|
-
# the verb is POST.
|
269
|
-
#
|
270
|
-
def default_action
|
271
|
-
@action ||= ACTIONS_FOR_VERBS[request.request_method_symbol]
|
272
|
-
end
|
273
|
-
|
274
|
-
def resource_errors
|
275
|
-
respond_to?("#{format}_resource_errors", true) ? send("#{format}_resource_errors") : resource.errors
|
276
|
-
end
|
277
|
-
|
278
|
-
def json_resource_errors
|
279
|
-
{:errors => resource.errors}
|
280
|
-
end
|
281
|
-
|
282
|
-
def response_overridden?
|
283
|
-
@default_response.present?
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module ActionController #:nodoc:
|
2
|
-
module SessionManagement #:nodoc:
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
ActiveSupport::Deprecation.warn "ActionController::SessionManagement " \
|
7
|
-
"is deprecated because it has no contents since Rails 3.1", caller
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module ActionController
|
2
|
-
class Middleware < Metal
|
3
|
-
class ActionMiddleware
|
4
|
-
def initialize(controller, app)
|
5
|
-
@controller, @app = controller, app
|
6
|
-
end
|
7
|
-
|
8
|
-
def call(env)
|
9
|
-
request = ActionDispatch::Request.new(env)
|
10
|
-
@controller.build(@app).dispatch(:index, request)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class << self
|
15
|
-
alias build new
|
16
|
-
|
17
|
-
def new(app)
|
18
|
-
ActionMiddleware.new(self, app)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_internal :app
|
23
|
-
|
24
|
-
def process(action)
|
25
|
-
response = super
|
26
|
-
self.status, self.headers, self.response_body = response if response.is_a?(Array)
|
27
|
-
response
|
28
|
-
end
|
29
|
-
|
30
|
-
def initialize(app)
|
31
|
-
super()
|
32
|
-
@_app = app
|
33
|
-
end
|
34
|
-
|
35
|
-
def index
|
36
|
-
call(env)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module ActionController
|
2
|
-
module Railties
|
3
|
-
module Paths
|
4
|
-
def self.with(app)
|
5
|
-
Module.new do
|
6
|
-
define_method(:inherited) do |klass|
|
7
|
-
super(klass)
|
8
|
-
|
9
|
-
if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
|
10
|
-
paths = namespace.railtie_helpers_paths
|
11
|
-
else
|
12
|
-
paths = app.helpers_paths
|
13
|
-
end
|
14
|
-
|
15
|
-
klass.helpers_path = paths
|
16
|
-
|
17
|
-
if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
|
18
|
-
klass.helper :all
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module'
|
2
|
-
|
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
|
-
module RecordIdentifier
|
28
|
-
extend self
|
29
|
-
|
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
|
-
def dom_id(record, prefix = nil)
|
57
|
-
if record_id = record_key_for_dom_id(record)
|
58
|
-
"#{dom_class(record, prefix)}#{JOIN}#{record_id}"
|
59
|
-
else
|
60
|
-
dom_class(record, prefix || NEW)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
protected
|
65
|
-
|
66
|
-
# Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
|
67
|
-
# This can be overwritten to customize the default generated string representation if desired.
|
68
|
-
# If you need to read back a key from a dom_id in order to query for the underlying database record,
|
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
|
78
|
-
end
|
79
|
-
|
80
|
-
# Replaces characters that are invalid in HTML DOM ids with valid ones.
|
81
|
-
def sanitize_dom_id(candidate_id)
|
82
|
-
candidate_id # TODO implement conversion to valid DOM id values
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'html/tokenizer'
|
2
|
-
require 'html/node'
|
3
|
-
require 'html/selector'
|
4
|
-
require 'html/sanitizer'
|
5
|
-
|
6
|
-
module HTML #:nodoc:
|
7
|
-
# A top-level HTML document. You give it a body of text, and it will parse that
|
8
|
-
# text into a tree of nodes.
|
9
|
-
class Document #:nodoc:
|
10
|
-
|
11
|
-
# The root of the parsed document.
|
12
|
-
attr_reader :root
|
13
|
-
|
14
|
-
# Create a new Document from the given text.
|
15
|
-
def initialize(text, strict=false, xml=false)
|
16
|
-
tokenizer = Tokenizer.new(text)
|
17
|
-
@root = Node.new(nil)
|
18
|
-
node_stack = [ @root ]
|
19
|
-
while token = tokenizer.next
|
20
|
-
node = Node.parse(node_stack.last, tokenizer.line, tokenizer.position, token, strict)
|
21
|
-
|
22
|
-
node_stack.last.children << node unless node.tag? && node.closing == :close
|
23
|
-
if node.tag?
|
24
|
-
if node_stack.length > 1 && node.closing == :close
|
25
|
-
if node_stack.last.name == node.name
|
26
|
-
if node_stack.last.children.empty?
|
27
|
-
node_stack.last.children << Text.new(node_stack.last, node.line, node.position, "")
|
28
|
-
end
|
29
|
-
node_stack.pop
|
30
|
-
else
|
31
|
-
open_start = node_stack.last.position - 20
|
32
|
-
open_start = 0 if open_start < 0
|
33
|
-
close_start = node.position - 20
|
34
|
-
close_start = 0 if close_start < 0
|
35
|
-
msg = <<EOF.strip
|
36
|
-
ignoring attempt to close #{node_stack.last.name} with #{node.name}
|
37
|
-
opened at byte #{node_stack.last.position}, line #{node_stack.last.line}
|
38
|
-
closed at byte #{node.position}, line #{node.line}
|
39
|
-
attributes at open: #{node_stack.last.attributes.inspect}
|
40
|
-
text around open: #{text[open_start,40].inspect}
|
41
|
-
text around close: #{text[close_start,40].inspect}
|
42
|
-
EOF
|
43
|
-
strict ? raise(msg) : warn(msg)
|
44
|
-
end
|
45
|
-
elsif !node.childless?(xml) && node.closing != :close
|
46
|
-
node_stack.push node
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Search the tree for (and return) the first node that matches the given
|
53
|
-
# conditions. The conditions are interpreted differently for different node
|
54
|
-
# types, see HTML::Text#find and HTML::Tag#find.
|
55
|
-
def find(conditions)
|
56
|
-
@root.find(conditions)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Search the tree for (and return) all nodes that match the given
|
60
|
-
# conditions. The conditions are interpreted differently for different node
|
61
|
-
# types, see HTML::Text#find and HTML::Tag#find.
|
62
|
-
def find_all(conditions)
|
63
|
-
@root.find_all(conditions)
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|