actionpack 4.0.1 → 4.2.11.1
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 +402 -1173
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -7
- data/lib/abstract_controller/base.rb +39 -7
- data/lib/abstract_controller/callbacks.rb +32 -53
- data/lib/abstract_controller/collector.rb +11 -1
- data/lib/abstract_controller/helpers.rb +26 -16
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
- data/lib/abstract_controller/rendering.rb +57 -127
- data/lib/abstract_controller/url_for.rb +1 -1
- data/lib/abstract_controller.rb +1 -2
- data/lib/action_controller/base.rb +19 -10
- data/lib/action_controller/caching/fragments.rb +7 -1
- data/lib/action_controller/caching.rb +2 -12
- data/lib/action_controller/log_subscriber.rb +29 -20
- data/lib/action_controller/metal/conditional_get.rb +37 -12
- data/lib/action_controller/metal/data_streaming.rb +1 -1
- data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
- data/lib/action_controller/metal/exceptions.rb +1 -1
- data/lib/action_controller/metal/flash.rb +17 -0
- data/lib/action_controller/metal/force_ssl.rb +2 -2
- data/lib/action_controller/metal/head.rb +8 -6
- data/lib/action_controller/metal/helpers.rb +6 -2
- data/lib/action_controller/metal/http_authentication.rb +45 -23
- data/lib/action_controller/metal/instrumentation.rb +9 -6
- data/lib/action_controller/metal/live.rb +173 -20
- data/lib/action_controller/metal/mime_responds.rb +127 -232
- data/lib/action_controller/metal/params_wrapper.rb +16 -9
- data/lib/action_controller/metal/rack_delegation.rb +1 -1
- data/lib/action_controller/metal/redirecting.rb +34 -26
- data/lib/action_controller/metal/renderers.rb +39 -12
- data/lib/action_controller/metal/rendering.rb +41 -14
- data/lib/action_controller/metal/request_forgery_protection.rb +147 -19
- data/lib/action_controller/metal/streaming.rb +19 -21
- data/lib/action_controller/metal/strong_parameters.rb +166 -22
- data/lib/action_controller/metal/testing.rb +0 -1
- data/lib/action_controller/metal/url_for.rb +11 -12
- data/lib/action_controller/metal.rb +14 -8
- data/lib/action_controller/model_naming.rb +1 -1
- data/lib/action_controller/railtie.rb +5 -1
- data/lib/action_controller/test_case.rb +160 -94
- data/lib/action_controller.rb +2 -18
- data/lib/action_dispatch/http/cache.rb +5 -4
- data/lib/action_dispatch/http/filter_parameters.rb +2 -2
- data/lib/action_dispatch/http/filter_redirect.rb +5 -4
- data/lib/action_dispatch/http/headers.rb +46 -10
- data/lib/action_dispatch/http/mime_negotiation.rb +31 -4
- data/lib/action_dispatch/http/mime_type.rb +25 -26
- data/lib/action_dispatch/http/mime_types.rb +1 -0
- data/lib/action_dispatch/http/parameter_filter.rb +1 -1
- data/lib/action_dispatch/http/parameters.rb +25 -41
- data/lib/action_dispatch/http/request.rb +49 -32
- data/lib/action_dispatch/http/response.rb +127 -25
- data/lib/action_dispatch/http/upload.rb +9 -21
- data/lib/action_dispatch/http/url.rb +97 -70
- data/lib/action_dispatch/journey/formatter.rb +35 -19
- data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
- data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -33
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
- data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
- data/lib/action_dispatch/journey/nodes/node.rb +4 -0
- data/lib/action_dispatch/journey/parser.rb +51 -59
- data/lib/action_dispatch/journey/parser.y +12 -10
- data/lib/action_dispatch/journey/path/pattern.rb +16 -19
- data/lib/action_dispatch/journey/route.rb +8 -19
- data/lib/action_dispatch/journey/router/strexp.rb +9 -6
- data/lib/action_dispatch/journey/router/utils.rb +54 -18
- data/lib/action_dispatch/journey/router.rb +53 -75
- data/lib/action_dispatch/journey/routes.rb +4 -0
- data/lib/action_dispatch/journey/scanner.rb +5 -5
- data/lib/action_dispatch/journey/visitors.rb +81 -60
- data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
- data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
- data/lib/action_dispatch/middleware/callbacks.rb +7 -7
- data/lib/action_dispatch/middleware/cookies.rb +119 -43
- data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -13
- data/lib/action_dispatch/middleware/exception_wrapper.rb +60 -20
- data/lib/action_dispatch/middleware/flash.rb +37 -24
- data/lib/action_dispatch/middleware/params_parser.rb +2 -2
- data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
- data/lib/action_dispatch/middleware/reloader.rb +11 -2
- data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
- data/lib/action_dispatch/middleware/request_id.rb +1 -1
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +8 -7
- data/lib/action_dispatch/middleware/show_exceptions.rb +6 -2
- data/lib/action_dispatch/middleware/ssl.rb +10 -7
- data/lib/action_dispatch/middleware/static.rb +79 -23
- data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
- 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.erb → diagnostics.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
- 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.erb → routing_error.html.erb} +3 -1
- 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.erb → unknown_action.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
- data/lib/action_dispatch/railtie.rb +5 -2
- data/lib/action_dispatch/request/session.rb +12 -0
- data/lib/action_dispatch/request/utils.rb +35 -0
- data/lib/action_dispatch/routing/endpoint.rb +10 -0
- data/lib/action_dispatch/routing/inspector.rb +11 -17
- data/lib/action_dispatch/routing/mapper.rb +519 -312
- data/lib/action_dispatch/routing/polymorphic_routes.rb +204 -79
- data/lib/action_dispatch/routing/redirection.rb +51 -26
- data/lib/action_dispatch/routing/route_set.rb +331 -206
- data/lib/action_dispatch/routing/routes_proxy.rb +5 -4
- data/lib/action_dispatch/routing/url_for.rb +19 -5
- data/lib/action_dispatch/routing.rb +9 -6
- data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
- data/lib/action_dispatch/testing/assertions/response.rb +9 -15
- data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
- data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
- data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
- data/lib/action_dispatch/testing/assertions.rb +11 -7
- data/lib/action_dispatch/testing/integration.rb +31 -29
- data/lib/action_dispatch/testing/test_request.rb +1 -1
- data/lib/action_dispatch/testing/test_response.rb +1 -5
- data/lib/action_dispatch.rb +5 -8
- data/lib/action_pack/gem_version.rb +15 -0
- data/lib/action_pack/version.rb +4 -7
- data/lib/action_pack.rb +1 -1
- metadata +77 -159
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/deprecated/integration_test.rb +0 -5
- data/lib/action_controller/deprecated.rb +0 -7
- data/lib/action_controller/metal/responder.rb +0 -287
- data/lib/action_controller/record_identifier.rb +0 -31
- data/lib/action_controller/vendor/html-scanner.rb +0 -5
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -24
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -7
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -43
- data/lib/action_view/base.rb +0 -201
- data/lib/action_view/buffers.rb +0 -49
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/dependency_tracker.rb +0 -93
- data/lib/action_view/digestor.rb +0 -113
- data/lib/action_view/flows.rb +0 -76
- data/lib/action_view/helpers/active_model_helper.rb +0 -49
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
- data/lib/action_view/helpers/asset_url_helper.rb +0 -355
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
- data/lib/action_view/helpers/cache_helper.rb +0 -196
- data/lib/action_view/helpers/capture_helper.rb +0 -216
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -30
- data/lib/action_view/helpers/date_helper.rb +0 -1083
- data/lib/action_view/helpers/debug_helper.rb +0 -39
- data/lib/action_view/helpers/form_helper.rb +0 -1880
- data/lib/action_view/helpers/form_options_helper.rb +0 -838
- data/lib/action_view/helpers/form_tag_helper.rb +0 -785
- data/lib/action_view/helpers/javascript_helper.rb +0 -117
- data/lib/action_view/helpers/number_helper.rb +0 -441
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -106
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -256
- data/lib/action_view/helpers/tag_helper.rb +0 -173
- data/lib/action_view/helpers/tags/base.rb +0 -148
- data/lib/action_view/helpers/tags/check_box.rb +0 -64
- data/lib/action_view/helpers/tags/checkable.rb +0 -16
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -44
- data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
- data/lib/action_view/helpers/tags/collection_select.rb +0 -28
- data/lib/action_view/helpers/tags/color_field.rb +0 -25
- data/lib/action_view/helpers/tags/date_field.rb +0 -13
- data/lib/action_view/helpers/tags/date_select.rb +0 -72
- data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
- data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
- data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
- data/lib/action_view/helpers/tags/email_field.rb +0 -8
- data/lib/action_view/helpers/tags/file_field.rb +0 -8
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
- data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
- data/lib/action_view/helpers/tags/label.rb +0 -66
- data/lib/action_view/helpers/tags/month_field.rb +0 -13
- data/lib/action_view/helpers/tags/number_field.rb +0 -18
- data/lib/action_view/helpers/tags/password_field.rb +0 -12
- data/lib/action_view/helpers/tags/radio_button.rb +0 -31
- data/lib/action_view/helpers/tags/range_field.rb +0 -8
- data/lib/action_view/helpers/tags/search_field.rb +0 -24
- data/lib/action_view/helpers/tags/select.rb +0 -40
- data/lib/action_view/helpers/tags/tel_field.rb +0 -8
- data/lib/action_view/helpers/tags/text_area.rb +0 -18
- data/lib/action_view/helpers/tags/text_field.rb +0 -29
- data/lib/action_view/helpers/tags/time_field.rb +0 -13
- data/lib/action_view/helpers/tags/time_select.rb +0 -8
- data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
- data/lib/action_view/helpers/tags/url_field.rb +0 -8
- data/lib/action_view/helpers/tags/week_field.rb +0 -13
- data/lib/action_view/helpers/tags.rb +0 -39
- data/lib/action_view/helpers/text_helper.rb +0 -443
- data/lib/action_view/helpers/translation_helper.rb +0 -107
- data/lib/action_view/helpers/url_helper.rb +0 -635
- data/lib/action_view/helpers.rb +0 -58
- data/lib/action_view/locale/en.yml +0 -56
- data/lib/action_view/log_subscriber.rb +0 -30
- data/lib/action_view/lookup_context.rb +0 -241
- data/lib/action_view/model_naming.rb +0 -12
- data/lib/action_view/path_set.rb +0 -77
- data/lib/action_view/railtie.rb +0 -43
- data/lib/action_view/record_identifier.rb +0 -84
- data/lib/action_view/renderer/abstract_renderer.rb +0 -47
- data/lib/action_view/renderer/partial_renderer.rb +0 -492
- data/lib/action_view/renderer/renderer.rb +0 -50
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
- data/lib/action_view/renderer/template_renderer.rb +0 -96
- data/lib/action_view/routing_url_for.rb +0 -107
- data/lib/action_view/tasks/dependencies.rake +0 -17
- data/lib/action_view/template/error.rb +0 -138
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -146
- data/lib/action_view/template/handlers/raw.rb +0 -11
- data/lib/action_view/template/handlers.rb +0 -53
- data/lib/action_view/template/resolver.rb +0 -326
- data/lib/action_view/template/text.rb +0 -34
- data/lib/action_view/template/types.rb +0 -57
- data/lib/action_view/template.rb +0 -339
- data/lib/action_view/test_case.rb +0 -270
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
- data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_view/vendor/html-scanner.rb +0 -20
- data/lib/action_view.rb +0 -93
@@ -1,287 +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 PATCH/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.tasks.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.tasks.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.tasks.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
|
-
DEFAULT_ACTIONS_FOR_VERBS = {
|
120
|
-
:post => :new,
|
121
|
-
:patch => :edit,
|
122
|
-
:put => :edit
|
123
|
-
}
|
124
|
-
|
125
|
-
def initialize(controller, resources, options={})
|
126
|
-
@controller = controller
|
127
|
-
@request = @controller.request
|
128
|
-
@format = @controller.formats.first
|
129
|
-
@resource = resources.last
|
130
|
-
@resources = resources
|
131
|
-
@options = options
|
132
|
-
@action = options.delete(:action)
|
133
|
-
@default_response = options.delete(:default_response)
|
134
|
-
end
|
135
|
-
|
136
|
-
delegate :head, :render, :redirect_to, :to => :controller
|
137
|
-
delegate :get?, :post?, :patch?, :put?, :delete?, :to => :request
|
138
|
-
|
139
|
-
# Undefine :to_json and :to_yaml since it's defined on Object
|
140
|
-
undef_method(:to_json) if method_defined?(:to_json)
|
141
|
-
undef_method(:to_yaml) if method_defined?(:to_yaml)
|
142
|
-
|
143
|
-
# Initializes a new responder an invoke the proper format. If the format is
|
144
|
-
# not defined, call to_format.
|
145
|
-
#
|
146
|
-
def self.call(*args)
|
147
|
-
new(*args).respond
|
148
|
-
end
|
149
|
-
|
150
|
-
# Main entry point for responder responsible to dispatch to the proper format.
|
151
|
-
#
|
152
|
-
def respond
|
153
|
-
method = "to_#{format}"
|
154
|
-
respond_to?(method) ? send(method) : to_format
|
155
|
-
end
|
156
|
-
|
157
|
-
# HTML format does not render the resource, it always attempt to render a
|
158
|
-
# template.
|
159
|
-
#
|
160
|
-
def to_html
|
161
|
-
default_render
|
162
|
-
rescue ActionView::MissingTemplate => e
|
163
|
-
navigation_behavior(e)
|
164
|
-
end
|
165
|
-
|
166
|
-
# to_js simply tries to render a template. If no template is found, raises the error.
|
167
|
-
def to_js
|
168
|
-
default_render
|
169
|
-
end
|
170
|
-
|
171
|
-
# All other formats follow the procedure below. First we try to render a
|
172
|
-
# template, if the template is not available, we verify if the resource
|
173
|
-
# responds to :to_format and display it.
|
174
|
-
#
|
175
|
-
def to_format
|
176
|
-
if get? || !has_errors? || response_overridden?
|
177
|
-
default_render
|
178
|
-
else
|
179
|
-
display_errors
|
180
|
-
end
|
181
|
-
rescue ActionView::MissingTemplate => e
|
182
|
-
api_behavior(e)
|
183
|
-
end
|
184
|
-
|
185
|
-
protected
|
186
|
-
|
187
|
-
# This is the common behavior for formats associated with browsing, like :html, :iphone and so forth.
|
188
|
-
def navigation_behavior(error)
|
189
|
-
if get?
|
190
|
-
raise error
|
191
|
-
elsif has_errors? && default_action
|
192
|
-
render :action => default_action
|
193
|
-
else
|
194
|
-
redirect_to navigation_location
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
# This is the common behavior for formats associated with APIs, such as :xml and :json.
|
199
|
-
def api_behavior(error)
|
200
|
-
raise error unless resourceful?
|
201
|
-
|
202
|
-
if get?
|
203
|
-
display resource
|
204
|
-
elsif post?
|
205
|
-
display resource, :status => :created, :location => api_location
|
206
|
-
else
|
207
|
-
head :no_content
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
# Checks whether the resource responds to the current format or not.
|
212
|
-
#
|
213
|
-
def resourceful?
|
214
|
-
resource.respond_to?("to_#{format}")
|
215
|
-
end
|
216
|
-
|
217
|
-
# Returns the resource location by retrieving it from the options or
|
218
|
-
# returning the resources array.
|
219
|
-
#
|
220
|
-
def resource_location
|
221
|
-
options[:location] || resources
|
222
|
-
end
|
223
|
-
alias :navigation_location :resource_location
|
224
|
-
alias :api_location :resource_location
|
225
|
-
|
226
|
-
# If a response block was given, use it, otherwise call render on
|
227
|
-
# controller.
|
228
|
-
#
|
229
|
-
def default_render
|
230
|
-
if @default_response
|
231
|
-
@default_response.call(options)
|
232
|
-
else
|
233
|
-
controller.default_render(options)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
# Display is just a shortcut to render a resource with the current format.
|
238
|
-
#
|
239
|
-
# display @user, status: :ok
|
240
|
-
#
|
241
|
-
# For XML requests it's equivalent to:
|
242
|
-
#
|
243
|
-
# render xml: @user, status: :ok
|
244
|
-
#
|
245
|
-
# Options sent by the user are also used:
|
246
|
-
#
|
247
|
-
# respond_with(@user, status: :created)
|
248
|
-
# display(@user, status: :ok)
|
249
|
-
#
|
250
|
-
# Results in:
|
251
|
-
#
|
252
|
-
# render xml: @user, status: :created
|
253
|
-
#
|
254
|
-
def display(resource, given_options={})
|
255
|
-
controller.render given_options.merge!(options).merge!(format => resource)
|
256
|
-
end
|
257
|
-
|
258
|
-
def display_errors
|
259
|
-
controller.render format => resource_errors, :status => :unprocessable_entity
|
260
|
-
end
|
261
|
-
|
262
|
-
# Check whether the resource has errors.
|
263
|
-
#
|
264
|
-
def has_errors?
|
265
|
-
resource.respond_to?(:errors) && !resource.errors.empty?
|
266
|
-
end
|
267
|
-
|
268
|
-
# By default, render the <code>:edit</code> action for HTML requests with errors, unless
|
269
|
-
# the verb was POST.
|
270
|
-
#
|
271
|
-
def default_action
|
272
|
-
@action ||= DEFAULT_ACTIONS_FOR_VERBS[request.request_method_symbol]
|
273
|
-
end
|
274
|
-
|
275
|
-
def resource_errors
|
276
|
-
respond_to?("#{format}_resource_errors", true) ? send("#{format}_resource_errors") : resource.errors
|
277
|
-
end
|
278
|
-
|
279
|
-
def json_resource_errors
|
280
|
-
{:errors => resource.errors}
|
281
|
-
end
|
282
|
-
|
283
|
-
def response_overridden?
|
284
|
-
@default_response.present?
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'action_view/record_identifier'
|
2
|
-
|
3
|
-
module ActionController
|
4
|
-
module RecordIdentifier
|
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.'
|
10
|
-
|
11
|
-
def dom_id(record, prefix = nil)
|
12
|
-
ActiveSupport::Deprecation.warn(INSTANCE_MESSAGE % 'dom_id')
|
13
|
-
ActionView::RecordIdentifier.dom_id(record, prefix)
|
14
|
-
end
|
15
|
-
|
16
|
-
def dom_class(record, prefix = nil)
|
17
|
-
ActiveSupport::Deprecation.warn(INSTANCE_MESSAGE % 'dom_class')
|
18
|
-
ActionView::RecordIdentifier.dom_class(record, prefix)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.dom_id(record, prefix = nil)
|
22
|
-
ActiveSupport::Deprecation.warn(MODULE_MESSAGE % 'dom_id')
|
23
|
-
ActionView::RecordIdentifier.dom_id(record, prefix)
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.dom_class(record, prefix = nil)
|
27
|
-
ActiveSupport::Deprecation.warn(MODULE_MESSAGE % 'dom_class')
|
28
|
-
ActionView::RecordIdentifier.dom_class(record, prefix)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
<%
|
2
|
-
traces = { "Application Trace" => @application_trace,
|
3
|
-
"Framework Trace" => @framework_trace,
|
4
|
-
"Full Trace" => @full_trace }
|
5
|
-
names = traces.keys
|
6
|
-
%>
|
7
|
-
|
8
|
-
<p><code>Rails.root: <%= defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : "unset" %></code></p>
|
9
|
-
|
10
|
-
<div id="traces">
|
11
|
-
<% names.each do |name| %>
|
12
|
-
<%
|
13
|
-
show = "show('#{name.gsub(/\s/, '-')}');"
|
14
|
-
hide = (names - [name]).collect {|hide_name| "hide('#{hide_name.gsub(/\s/, '-')}');"}
|
15
|
-
%>
|
16
|
-
<a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %>
|
17
|
-
<% end %>
|
18
|
-
|
19
|
-
<% traces.each do |name, trace| %>
|
20
|
-
<div id="<%= name.gsub(/\s/, '-') %>" style="display: <%= (name == "Application Trace") ? 'block' : 'none' %>;">
|
21
|
-
<pre><code><%= trace.join "\n" %></code></pre>
|
22
|
-
</div>
|
23
|
-
<% end %>
|
24
|
-
</div>
|
@@ -1,43 +0,0 @@
|
|
1
|
-
<% @source_extract = @exception.source_extract(0, :html) %>
|
2
|
-
<header>
|
3
|
-
<h1>
|
4
|
-
<%= @exception.original_exception.class.to_s %> in
|
5
|
-
<%= @request.parameters["controller"].camelize if @request.parameters["controller"] %>#<%= @request.parameters["action"] %>
|
6
|
-
</h1>
|
7
|
-
</header>
|
8
|
-
|
9
|
-
<div id="container">
|
10
|
-
<p>
|
11
|
-
Showing <i><%= @exception.file_name %></i> where line <b>#<%= @exception.line_number %></b> raised:
|
12
|
-
</p>
|
13
|
-
<pre><code><%= @exception.message %></code></pre>
|
14
|
-
|
15
|
-
<div class="source">
|
16
|
-
<div class="info">
|
17
|
-
<p>Extracted source (around line <strong>#<%= @exception.line_number %></strong>):</p>
|
18
|
-
</div>
|
19
|
-
<div class="data">
|
20
|
-
<table cellpadding="0" cellspacing="0" class="lines">
|
21
|
-
<tr>
|
22
|
-
<td>
|
23
|
-
<pre class="line_numbers">
|
24
|
-
<% @source_extract.keys.each do |line_number| %>
|
25
|
-
<span><%= line_number -%></span>
|
26
|
-
<% end %>
|
27
|
-
</pre>
|
28
|
-
</td>
|
29
|
-
<td width="100%">
|
30
|
-
<pre>
|
31
|
-
<% @source_extract.each do |line, source| -%><div class="line<%= " active" if line == @exception.line_number -%>"><%= source -%></div><% end -%>
|
32
|
-
</pre>
|
33
|
-
</td>
|
34
|
-
</tr>
|
35
|
-
</table>
|
36
|
-
</div>
|
37
|
-
</div>
|
38
|
-
|
39
|
-
<p><%= @exception.sub_template_message %></p>
|
40
|
-
|
41
|
-
<%= render template: "rescues/_trace" %>
|
42
|
-
<%= render template: "rescues/_request_and_response" %>
|
43
|
-
</div>
|
data/lib/action_view/base.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module/attr_internal'
|
2
|
-
require 'active_support/core_ext/class/attribute_accessors'
|
3
|
-
require 'active_support/ordered_options'
|
4
|
-
require 'action_view/log_subscriber'
|
5
|
-
|
6
|
-
module ActionView #:nodoc:
|
7
|
-
# = Action View Base
|
8
|
-
#
|
9
|
-
# Action View templates can be written in several ways. If the template file has a <tt>.erb</tt> extension then it uses a mixture of ERB
|
10
|
-
# (included in Ruby) and HTML. If the template file has a <tt>.builder</tt> extension then Jim Weirich's Builder::XmlMarkup library is used.
|
11
|
-
#
|
12
|
-
# == ERB
|
13
|
-
#
|
14
|
-
# You trigger ERB by using embeddings such as <% %>, <% -%>, and <%= %>. The <%= %> tag set is used when you want output. Consider the
|
15
|
-
# following loop for names:
|
16
|
-
#
|
17
|
-
# <b>Names of all the people</b>
|
18
|
-
# <% @people.each do |person| %>
|
19
|
-
# Name: <%= person.name %><br/>
|
20
|
-
# <% end %>
|
21
|
-
#
|
22
|
-
# The loop is setup in regular embedding tags <% %> and the name is written using the output embedding tag <%= %>. Note that this
|
23
|
-
# is not just a usage suggestion. Regular output functions like print or puts won't work with ERB templates. So this would be wrong:
|
24
|
-
#
|
25
|
-
# <%# WRONG %>
|
26
|
-
# Hi, Mr. <% puts "Frodo" %>
|
27
|
-
#
|
28
|
-
# If you absolutely must write from within a function use +concat+.
|
29
|
-
#
|
30
|
-
# <%- and -%> suppress leading and trailing whitespace, including the trailing newline, and can be used interchangeably with <% and %>.
|
31
|
-
#
|
32
|
-
# === Using sub templates
|
33
|
-
#
|
34
|
-
# Using sub templates allows you to sidestep tedious replication and extract common display structures in shared templates. The
|
35
|
-
# classic example is the use of a header and footer (even though the Action Pack-way would be to use Layouts):
|
36
|
-
#
|
37
|
-
# <%= render "shared/header" %>
|
38
|
-
# Something really specific and terrific
|
39
|
-
# <%= render "shared/footer" %>
|
40
|
-
#
|
41
|
-
# As you see, we use the output embeddings for the render methods. The render call itself will just return a string holding the
|
42
|
-
# result of the rendering. The output embedding writes it to the current template.
|
43
|
-
#
|
44
|
-
# But you don't have to restrict yourself to static includes. Templates can share variables amongst themselves by using instance
|
45
|
-
# variables defined using the regular embedding tags. Like this:
|
46
|
-
#
|
47
|
-
# <% @page_title = "A Wonderful Hello" %>
|
48
|
-
# <%= render "shared/header" %>
|
49
|
-
#
|
50
|
-
# Now the header can pick up on the <tt>@page_title</tt> variable and use it for outputting a title tag:
|
51
|
-
#
|
52
|
-
# <title><%= @page_title %></title>
|
53
|
-
#
|
54
|
-
# === Passing local variables to sub templates
|
55
|
-
#
|
56
|
-
# You can pass local variables to sub templates by using a hash with the variable names as keys and the objects as values:
|
57
|
-
#
|
58
|
-
# <%= render "shared/header", { headline: "Welcome", person: person } %>
|
59
|
-
#
|
60
|
-
# These can now be accessed in <tt>shared/header</tt> with:
|
61
|
-
#
|
62
|
-
# Headline: <%= headline %>
|
63
|
-
# First name: <%= person.first_name %>
|
64
|
-
#
|
65
|
-
# If you need to find out whether a certain local variable has been assigned a value in a particular render call,
|
66
|
-
# you need to use the following pattern:
|
67
|
-
#
|
68
|
-
# <% if local_assigns.has_key? :headline %>
|
69
|
-
# Headline: <%= headline %>
|
70
|
-
# <% end %>
|
71
|
-
#
|
72
|
-
# Testing using <tt>defined? headline</tt> will not work. This is an implementation restriction.
|
73
|
-
#
|
74
|
-
# === Template caching
|
75
|
-
#
|
76
|
-
# By default, Rails will compile each template to a method in order to render it. When you alter a template,
|
77
|
-
# Rails will check the file's modification time and recompile it in development mode.
|
78
|
-
#
|
79
|
-
# == Builder
|
80
|
-
#
|
81
|
-
# Builder templates are a more programmatic alternative to ERB. They are especially useful for generating XML content. An XmlMarkup object
|
82
|
-
# named +xml+ is automatically made available to templates with a <tt>.builder</tt> extension.
|
83
|
-
#
|
84
|
-
# Here are some basic examples:
|
85
|
-
#
|
86
|
-
# xml.em("emphasized") # => <em>emphasized</em>
|
87
|
-
# xml.em { xml.b("emph & bold") } # => <em><b>emph & bold</b></em>
|
88
|
-
# xml.a("A Link", "href" => "http://onestepback.org") # => <a href="http://onestepback.org">A Link</a>
|
89
|
-
# xml.target("name" => "compile", "option" => "fast") # => <target option="fast" name="compile"\>
|
90
|
-
# # NOTE: order of attributes is not specified.
|
91
|
-
#
|
92
|
-
# Any method with a block will be treated as an XML markup tag with nested markup in the block. For example, the following:
|
93
|
-
#
|
94
|
-
# xml.div do
|
95
|
-
# xml.h1(@person.name)
|
96
|
-
# xml.p(@person.bio)
|
97
|
-
# end
|
98
|
-
#
|
99
|
-
# would produce something like:
|
100
|
-
#
|
101
|
-
# <div>
|
102
|
-
# <h1>David Heinemeier Hansson</h1>
|
103
|
-
# <p>A product of Danish Design during the Winter of '79...</p>
|
104
|
-
# </div>
|
105
|
-
#
|
106
|
-
# A full-length RSS example actually used on Basecamp:
|
107
|
-
#
|
108
|
-
# xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
|
109
|
-
# xml.channel do
|
110
|
-
# xml.title(@feed_title)
|
111
|
-
# xml.link(@url)
|
112
|
-
# xml.description "Basecamp: Recent items"
|
113
|
-
# xml.language "en-us"
|
114
|
-
# xml.ttl "40"
|
115
|
-
#
|
116
|
-
# @recent_items.each do |item|
|
117
|
-
# xml.item do
|
118
|
-
# xml.title(item_title(item))
|
119
|
-
# xml.description(item_description(item)) if item_description(item)
|
120
|
-
# xml.pubDate(item_pubDate(item))
|
121
|
-
# xml.guid(@person.firm.account.url + @recent_items.url(item))
|
122
|
-
# xml.link(@person.firm.account.url + @recent_items.url(item))
|
123
|
-
#
|
124
|
-
# xml.tag!("dc:creator", item.author_name) if item_has_creator?(item)
|
125
|
-
# end
|
126
|
-
# end
|
127
|
-
# end
|
128
|
-
# end
|
129
|
-
#
|
130
|
-
# More builder documentation can be found at http://builder.rubyforge.org.
|
131
|
-
class Base
|
132
|
-
include Helpers, ::ERB::Util, Context
|
133
|
-
|
134
|
-
# Specify the proc used to decorate input tags that refer to attributes with errors.
|
135
|
-
cattr_accessor :field_error_proc
|
136
|
-
@@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
|
137
|
-
|
138
|
-
# How to complete the streaming when an exception occurs.
|
139
|
-
# This is our best guess: first try to close the attribute, then the tag.
|
140
|
-
cattr_accessor :streaming_completion_on_exception
|
141
|
-
@@streaming_completion_on_exception = %("><script>window.location = "/500.html"</script></html>)
|
142
|
-
|
143
|
-
# Specify whether rendering within namespaced controllers should prefix
|
144
|
-
# the partial paths for ActiveModel objects with the namespace.
|
145
|
-
# (e.g., an Admin::PostsController would render @post using /admin/posts/_post.erb)
|
146
|
-
cattr_accessor :prefix_partial_path_with_controller_namespace
|
147
|
-
@@prefix_partial_path_with_controller_namespace = true
|
148
|
-
|
149
|
-
# Specify default_formats that can be rendered.
|
150
|
-
cattr_accessor :default_formats
|
151
|
-
|
152
|
-
class_attribute :_routes
|
153
|
-
class_attribute :logger
|
154
|
-
|
155
|
-
class << self
|
156
|
-
delegate :erb_trim_mode=, :to => 'ActionView::Template::Handlers::ERB'
|
157
|
-
|
158
|
-
def cache_template_loading
|
159
|
-
ActionView::Resolver.caching?
|
160
|
-
end
|
161
|
-
|
162
|
-
def cache_template_loading=(value)
|
163
|
-
ActionView::Resolver.caching = value
|
164
|
-
end
|
165
|
-
|
166
|
-
def xss_safe? #:nodoc:
|
167
|
-
true
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
attr_accessor :view_renderer
|
172
|
-
attr_internal :config, :assigns
|
173
|
-
|
174
|
-
delegate :lookup_context, :to => :view_renderer
|
175
|
-
delegate :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, :to => :lookup_context
|
176
|
-
|
177
|
-
def assign(new_assigns) # :nodoc:
|
178
|
-
@_assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
|
179
|
-
end
|
180
|
-
|
181
|
-
def initialize(context = nil, assigns = {}, controller = nil, formats = nil) #:nodoc:
|
182
|
-
@_config = ActiveSupport::InheritableOptions.new
|
183
|
-
|
184
|
-
if context.is_a?(ActionView::Renderer)
|
185
|
-
@view_renderer = context
|
186
|
-
else
|
187
|
-
lookup_context = context.is_a?(ActionView::LookupContext) ?
|
188
|
-
context : ActionView::LookupContext.new(context)
|
189
|
-
lookup_context.formats = formats if formats
|
190
|
-
lookup_context.prefixes = controller._prefixes if controller
|
191
|
-
@view_renderer = ActionView::Renderer.new(lookup_context)
|
192
|
-
end
|
193
|
-
|
194
|
-
assign(assigns)
|
195
|
-
assign_controller(controller)
|
196
|
-
_prepare_context
|
197
|
-
end
|
198
|
-
|
199
|
-
ActiveSupport.run_load_hooks(:action_view, self)
|
200
|
-
end
|
201
|
-
end
|
data/lib/action_view/buffers.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/string/output_safety'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
class OutputBuffer < ActiveSupport::SafeBuffer #:nodoc:
|
5
|
-
def initialize(*)
|
6
|
-
super
|
7
|
-
encode!
|
8
|
-
end
|
9
|
-
|
10
|
-
def <<(value)
|
11
|
-
return self if value.nil?
|
12
|
-
super(value.to_s)
|
13
|
-
end
|
14
|
-
alias :append= :<<
|
15
|
-
|
16
|
-
def safe_concat(value)
|
17
|
-
return self if value.nil?
|
18
|
-
super(value.to_s)
|
19
|
-
end
|
20
|
-
alias :safe_append= :safe_concat
|
21
|
-
end
|
22
|
-
|
23
|
-
class StreamingBuffer #:nodoc:
|
24
|
-
def initialize(block)
|
25
|
-
@block = block
|
26
|
-
end
|
27
|
-
|
28
|
-
def <<(value)
|
29
|
-
value = value.to_s
|
30
|
-
value = ERB::Util.h(value) unless value.html_safe?
|
31
|
-
@block.call(value)
|
32
|
-
end
|
33
|
-
alias :concat :<<
|
34
|
-
alias :append= :<<
|
35
|
-
|
36
|
-
def safe_concat(value)
|
37
|
-
@block.call(value.to_s)
|
38
|
-
end
|
39
|
-
alias :safe_append= :safe_concat
|
40
|
-
|
41
|
-
def html_safe?
|
42
|
-
true
|
43
|
-
end
|
44
|
-
|
45
|
-
def html_safe
|
46
|
-
self
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/action_view/context.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module ActionView
|
2
|
-
module CompiledTemplates #:nodoc:
|
3
|
-
# holds compiled template code
|
4
|
-
end
|
5
|
-
|
6
|
-
# = Action View Context
|
7
|
-
#
|
8
|
-
# Action View contexts are supplied to Action Controller to render a template.
|
9
|
-
# The default Action View context is ActionView::Base.
|
10
|
-
#
|
11
|
-
# In order to work with ActionController, a Context must just include this module.
|
12
|
-
# The initialization of the variables used by the context (@output_buffer, @view_flow,
|
13
|
-
# and @virtual_path) is responsibility of the object that includes this module
|
14
|
-
# (although you can call _prepare_context defined below).
|
15
|
-
module Context
|
16
|
-
include CompiledTemplates
|
17
|
-
attr_accessor :output_buffer, :view_flow
|
18
|
-
|
19
|
-
# Prepares the context by setting the appropriate instance variables.
|
20
|
-
# :api: plugin
|
21
|
-
def _prepare_context
|
22
|
-
@view_flow = OutputFlow.new
|
23
|
-
@output_buffer = nil
|
24
|
-
@virtual_path = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
# Encapsulates the interaction with the view flow so it
|
28
|
-
# returns the correct buffer on +yield+. This is usually
|
29
|
-
# overwritten by helpers to add more behavior.
|
30
|
-
# :api: plugin
|
31
|
-
def _layout_for(name=nil)
|
32
|
-
name ||= :layout
|
33
|
-
view_flow.get(name).html_safe
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|