halorgium-actionpack 3.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/CHANGELOG +5179 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +409 -0
  4. data/lib/abstract_controller.rb +16 -0
  5. data/lib/abstract_controller/base.rb +158 -0
  6. data/lib/abstract_controller/callbacks.rb +113 -0
  7. data/lib/abstract_controller/exceptions.rb +12 -0
  8. data/lib/abstract_controller/helpers.rb +151 -0
  9. data/lib/abstract_controller/layouts.rb +250 -0
  10. data/lib/abstract_controller/localized_cache.rb +49 -0
  11. data/lib/abstract_controller/logger.rb +61 -0
  12. data/lib/abstract_controller/rendering_controller.rb +188 -0
  13. data/lib/action_controller.rb +72 -0
  14. data/lib/action_controller/base.rb +168 -0
  15. data/lib/action_controller/caching.rb +80 -0
  16. data/lib/action_controller/caching/actions.rb +163 -0
  17. data/lib/action_controller/caching/fragments.rb +116 -0
  18. data/lib/action_controller/caching/pages.rb +154 -0
  19. data/lib/action_controller/caching/sweeping.rb +97 -0
  20. data/lib/action_controller/deprecated.rb +4 -0
  21. data/lib/action_controller/deprecated/integration_test.rb +2 -0
  22. data/lib/action_controller/deprecated/performance_test.rb +1 -0
  23. data/lib/action_controller/dispatch/dispatcher.rb +57 -0
  24. data/lib/action_controller/metal.rb +129 -0
  25. data/lib/action_controller/metal/benchmarking.rb +73 -0
  26. data/lib/action_controller/metal/compatibility.rb +145 -0
  27. data/lib/action_controller/metal/conditional_get.rb +86 -0
  28. data/lib/action_controller/metal/configuration.rb +28 -0
  29. data/lib/action_controller/metal/cookies.rb +105 -0
  30. data/lib/action_controller/metal/exceptions.rb +55 -0
  31. data/lib/action_controller/metal/filter_parameter_logging.rb +77 -0
  32. data/lib/action_controller/metal/flash.rb +162 -0
  33. data/lib/action_controller/metal/head.rb +27 -0
  34. data/lib/action_controller/metal/helpers.rb +115 -0
  35. data/lib/action_controller/metal/hide_actions.rb +47 -0
  36. data/lib/action_controller/metal/http_authentication.rb +312 -0
  37. data/lib/action_controller/metal/layouts.rb +171 -0
  38. data/lib/action_controller/metal/mime_responds.rb +317 -0
  39. data/lib/action_controller/metal/rack_convenience.rb +27 -0
  40. data/lib/action_controller/metal/redirector.rb +22 -0
  41. data/lib/action_controller/metal/render_options.rb +103 -0
  42. data/lib/action_controller/metal/rendering_controller.rb +57 -0
  43. data/lib/action_controller/metal/request_forgery_protection.rb +108 -0
  44. data/lib/action_controller/metal/rescuable.rb +13 -0
  45. data/lib/action_controller/metal/responder.rb +200 -0
  46. data/lib/action_controller/metal/session.rb +15 -0
  47. data/lib/action_controller/metal/session_management.rb +45 -0
  48. data/lib/action_controller/metal/streaming.rb +188 -0
  49. data/lib/action_controller/metal/testing.rb +39 -0
  50. data/lib/action_controller/metal/url_for.rb +41 -0
  51. data/lib/action_controller/metal/verification.rb +130 -0
  52. data/lib/action_controller/middleware.rb +38 -0
  53. data/lib/action_controller/notifications.rb +10 -0
  54. data/lib/action_controller/polymorphic_routes.rb +183 -0
  55. data/lib/action_controller/record_identifier.rb +91 -0
  56. data/lib/action_controller/testing/process.rb +111 -0
  57. data/lib/action_controller/testing/test_case.rb +345 -0
  58. data/lib/action_controller/translation.rb +13 -0
  59. data/lib/action_controller/url_rewriter.rb +204 -0
  60. data/lib/action_controller/vendor/html-scanner.rb +16 -0
  61. data/lib/action_controller/vendor/html-scanner/html/document.rb +68 -0
  62. data/lib/action_controller/vendor/html-scanner/html/node.rb +537 -0
  63. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +176 -0
  64. data/lib/action_controller/vendor/html-scanner/html/selector.rb +828 -0
  65. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +105 -0
  66. data/lib/action_controller/vendor/html-scanner/html/version.rb +11 -0
  67. data/lib/action_dispatch.rb +70 -0
  68. data/lib/action_dispatch/http/headers.rb +33 -0
  69. data/lib/action_dispatch/http/mime_type.rb +231 -0
  70. data/lib/action_dispatch/http/mime_types.rb +23 -0
  71. data/lib/action_dispatch/http/request.rb +539 -0
  72. data/lib/action_dispatch/http/response.rb +290 -0
  73. data/lib/action_dispatch/http/status_codes.rb +42 -0
  74. data/lib/action_dispatch/http/utils.rb +20 -0
  75. data/lib/action_dispatch/middleware/callbacks.rb +50 -0
  76. data/lib/action_dispatch/middleware/params_parser.rb +79 -0
  77. data/lib/action_dispatch/middleware/rescue.rb +26 -0
  78. data/lib/action_dispatch/middleware/session/abstract_store.rb +208 -0
  79. data/lib/action_dispatch/middleware/session/cookie_store.rb +235 -0
  80. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +47 -0
  81. data/lib/action_dispatch/middleware/show_exceptions.rb +143 -0
  82. data/lib/action_dispatch/middleware/stack.rb +116 -0
  83. data/lib/action_dispatch/middleware/static.rb +44 -0
  84. data/lib/action_dispatch/middleware/string_coercion.rb +29 -0
  85. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +24 -0
  86. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +26 -0
  87. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +10 -0
  88. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +29 -0
  89. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +2 -0
  90. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +10 -0
  91. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +21 -0
  92. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +2 -0
  93. data/lib/action_dispatch/routing.rb +381 -0
  94. data/lib/action_dispatch/routing/deprecated_mapper.rb +878 -0
  95. data/lib/action_dispatch/routing/mapper.rb +327 -0
  96. data/lib/action_dispatch/routing/route.rb +49 -0
  97. data/lib/action_dispatch/routing/route_set.rb +497 -0
  98. data/lib/action_dispatch/testing/assertions.rb +8 -0
  99. data/lib/action_dispatch/testing/assertions/dom.rb +35 -0
  100. data/lib/action_dispatch/testing/assertions/model.rb +19 -0
  101. data/lib/action_dispatch/testing/assertions/response.rb +145 -0
  102. data/lib/action_dispatch/testing/assertions/routing.rb +144 -0
  103. data/lib/action_dispatch/testing/assertions/selector.rb +639 -0
  104. data/lib/action_dispatch/testing/assertions/tag.rb +123 -0
  105. data/lib/action_dispatch/testing/integration.rb +504 -0
  106. data/lib/action_dispatch/testing/performance_test.rb +15 -0
  107. data/lib/action_dispatch/testing/test_request.rb +83 -0
  108. data/lib/action_dispatch/testing/test_response.rb +131 -0
  109. data/lib/action_pack.rb +24 -0
  110. data/lib/action_pack/version.rb +9 -0
  111. data/lib/action_view.rb +58 -0
  112. data/lib/action_view/base.rb +308 -0
  113. data/lib/action_view/context.rb +44 -0
  114. data/lib/action_view/erb/util.rb +48 -0
  115. data/lib/action_view/helpers.rb +62 -0
  116. data/lib/action_view/helpers/active_model_helper.rb +306 -0
  117. data/lib/action_view/helpers/ajax_helper.rb +68 -0
  118. data/lib/action_view/helpers/asset_tag_helper.rb +830 -0
  119. data/lib/action_view/helpers/atom_feed_helper.rb +198 -0
  120. data/lib/action_view/helpers/cache_helper.rb +39 -0
  121. data/lib/action_view/helpers/capture_helper.rb +168 -0
  122. data/lib/action_view/helpers/date_helper.rb +988 -0
  123. data/lib/action_view/helpers/debug_helper.rb +38 -0
  124. data/lib/action_view/helpers/form_helper.rb +1102 -0
  125. data/lib/action_view/helpers/form_options_helper.rb +600 -0
  126. data/lib/action_view/helpers/form_tag_helper.rb +495 -0
  127. data/lib/action_view/helpers/javascript_helper.rb +208 -0
  128. data/lib/action_view/helpers/number_helper.rb +311 -0
  129. data/lib/action_view/helpers/prototype_helper.rb +1309 -0
  130. data/lib/action_view/helpers/raw_output_helper.rb +9 -0
  131. data/lib/action_view/helpers/record_identification_helper.rb +20 -0
  132. data/lib/action_view/helpers/record_tag_helper.rb +58 -0
  133. data/lib/action_view/helpers/sanitize_helper.rb +259 -0
  134. data/lib/action_view/helpers/scriptaculous_helper.rb +226 -0
  135. data/lib/action_view/helpers/tag_helper.rb +151 -0
  136. data/lib/action_view/helpers/text_helper.rb +594 -0
  137. data/lib/action_view/helpers/translation_helper.rb +39 -0
  138. data/lib/action_view/helpers/url_helper.rb +639 -0
  139. data/lib/action_view/locale/en.yml +117 -0
  140. data/lib/action_view/paths.rb +80 -0
  141. data/lib/action_view/render/partials.rb +342 -0
  142. data/lib/action_view/render/rendering.rb +134 -0
  143. data/lib/action_view/safe_buffer.rb +28 -0
  144. data/lib/action_view/template/error.rb +101 -0
  145. data/lib/action_view/template/handler.rb +36 -0
  146. data/lib/action_view/template/handlers.rb +52 -0
  147. data/lib/action_view/template/handlers/builder.rb +17 -0
  148. data/lib/action_view/template/handlers/erb.rb +53 -0
  149. data/lib/action_view/template/handlers/rjs.rb +18 -0
  150. data/lib/action_view/template/resolver.rb +165 -0
  151. data/lib/action_view/template/template.rb +131 -0
  152. data/lib/action_view/template/text.rb +38 -0
  153. data/lib/action_view/test_case.rb +163 -0
  154. metadata +236 -0
@@ -0,0 +1,49 @@
1
+ module AbstractController
2
+ class HashKey
3
+ @hash_keys = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {} } }
4
+
5
+ def self.get(klass, formats, locale)
6
+ @hash_keys[klass][formats][locale] ||= new(klass, formats, locale)
7
+ end
8
+
9
+ attr_accessor :hash
10
+ def initialize(klass, formats, locale)
11
+ @formats, @locale = formats, locale
12
+ @hash = [formats, locale].hash
13
+ end
14
+
15
+ alias_method :eql?, :equal?
16
+
17
+ def inspect
18
+ "#<HashKey -- formats: #{@formats.inspect} locale: #{@locale.inspect}>"
19
+ end
20
+ end
21
+
22
+ module LocalizedCache
23
+ extend ActiveSupport::Concern
24
+
25
+ module ClassMethods
26
+ def clear_template_caches!
27
+ ActionView::Partials::PartialRenderer::TEMPLATES.clear
28
+ template_cache.clear
29
+ super
30
+ end
31
+
32
+ def template_cache
33
+ @template_cache ||= Hash.new {|h,k| h[k] = {} }
34
+ end
35
+ end
36
+
37
+ def render(options)
38
+ Thread.current[:format_locale_key] = HashKey.get(self.class, formats, I18n.locale)
39
+ super
40
+ end
41
+
42
+ private
43
+
44
+ def with_template_cache(name)
45
+ self.class.template_cache[Thread.current[:format_locale_key]][name] ||= super
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,61 @@
1
+ require 'active_support/core_ext/logger'
2
+ require 'active_support/benchmarkable'
3
+
4
+ module AbstractController
5
+ module Logger
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ cattr_accessor :logger
10
+ extend ActiveSupport::Benchmarkable
11
+ end
12
+
13
+ # A class that allows you to defer expensive processing
14
+ # until the logger actually tries to log. Otherwise, you are
15
+ # forced to do the processing in advance, and send the
16
+ # entire processed String to the logger, which might
17
+ # just discard the String if the log level is too low.
18
+ #
19
+ # TODO: Require that Rails loggers accept a block.
20
+ class DelayedLog < ActiveSupport::BasicObject
21
+ def initialize(&block)
22
+ @str, @block = nil, block
23
+ end
24
+
25
+ def method_missing(*args, &block)
26
+ unless @str
27
+ @str, @block = @block.call, nil
28
+ end
29
+ @str.send(*args, &block)
30
+ end
31
+ end
32
+
33
+ # Override process_action in the AbstractController::Base
34
+ # to log details about the method.
35
+ def process_action(action)
36
+ result = ActiveSupport::Notifications.instrument(:process_action,
37
+ :controller => self, :action => action) do
38
+ super
39
+ end
40
+
41
+ if logger
42
+ log = DelayedLog.new do
43
+ "\n\nProcessing #{self.class.name}\##{action_name} " \
44
+ "to #{request.formats} (for #{request_origin}) " \
45
+ "[#{request.method.to_s.upcase}]"
46
+ end
47
+
48
+ logger.info(log)
49
+ end
50
+
51
+ result
52
+ end
53
+
54
+ private
55
+ # Returns the request origin with the IP and time. This needs to be cached,
56
+ # otherwise we would get different results for each time it calls.
57
+ def request_origin
58
+ @request_origin ||= "#{request.remote_ip} at #{Time.now.to_s(:db)}"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,188 @@
1
+ require "abstract_controller/logger"
2
+
3
+ module AbstractController
4
+ module RenderingController
5
+ extend ActiveSupport::Concern
6
+
7
+ include AbstractController::Logger
8
+
9
+ included do
10
+ attr_internal :formats
11
+ extlib_inheritable_accessor :_view_paths
12
+ self._view_paths ||= ActionView::PathSet.new
13
+ end
14
+
15
+ # An instance of a view class. The default view class is ActionView::Base
16
+ #
17
+ # The view class must have the following methods:
18
+ # View.for_controller[controller] Create a new ActionView instance for a
19
+ # controller
20
+ # View#render_partial[options]
21
+ # - responsible for setting options[:_template]
22
+ # - Returns String with the rendered partial
23
+ # options<Hash>:: see _render_partial in ActionView::Base
24
+ # View#render_template[template, layout, options, partial]
25
+ # - Returns String with the rendered template
26
+ # template<ActionView::Template>:: The template to render
27
+ # layout<ActionView::Template>:: The layout to render around the template
28
+ # options<Hash>:: See _render_template_with_layout in ActionView::Base
29
+ # partial<Boolean>:: Whether or not the template to render is a partial
30
+ #
31
+ # Override this method in a to change the default behavior.
32
+ def view_context
33
+ @_view_context ||= ActionView::Base.for_controller(self)
34
+ end
35
+
36
+ # Mostly abstracts the fact that calling render twice is a DoubleRenderError.
37
+ # Delegates render_to_body and sticks the result in self.response_body.
38
+ def render(*args)
39
+ if response_body
40
+ raise AbstractController::DoubleRenderError, "OMG"
41
+ end
42
+
43
+ self.response_body = render_to_body(*args)
44
+ end
45
+
46
+ # Raw rendering of a template to a Rack-compatible body.
47
+ #
48
+ # ==== Options
49
+ # _partial_object<Object>:: The object that is being rendered. If this
50
+ # exists, we are in the special case of rendering an object as a partial.
51
+ #
52
+ # :api: plugin
53
+ def render_to_body(options = {})
54
+ # TODO: Refactor so we can just use the normal template logic for this
55
+ if options.key?(:partial)
56
+ view_context.render_partial(options)
57
+ else
58
+ _determine_template(options)
59
+ _render_template(options)
60
+ end
61
+ end
62
+
63
+ # Raw rendering of a template to a string. Just convert the results of
64
+ # render_to_body into a String.
65
+ #
66
+ # :api: plugin
67
+ def render_to_string(options = {})
68
+ AbstractController::RenderingController.body_to_s(render_to_body(options))
69
+ end
70
+
71
+ # Renders the template from an object.
72
+ #
73
+ # ==== Options
74
+ # _template<ActionView::Template>:: The template to render
75
+ # _layout<ActionView::Template>:: The layout to wrap the template in (optional)
76
+ # _partial<TrueClass, FalseClass>:: Whether or not the template to be rendered is a partial
77
+ def _render_template(options)
78
+ view_context.render_template(options)
79
+ end
80
+
81
+ # The list of view paths for this controller. See ActionView::ViewPathSet for
82
+ # more details about writing custom view paths.
83
+ def view_paths
84
+ _view_paths
85
+ end
86
+
87
+ # Return a string representation of a Rack-compatible response body.
88
+ def self.body_to_s(body)
89
+ if body.respond_to?(:to_str)
90
+ body
91
+ else
92
+ strings = []
93
+ body.each { |part| strings << part.to_s }
94
+ body.close if body.respond_to?(:close)
95
+ strings.join
96
+ end
97
+ end
98
+
99
+ private
100
+
101
+ # Take in a set of options and determine the template to render
102
+ #
103
+ # ==== Options
104
+ # _template<ActionView::Template>:: If this is provided, the search is over
105
+ # _template_name<#to_s>:: The name of the template to look up. Otherwise,
106
+ # use the current action name.
107
+ # _prefix<String>:: The prefix to look inside of. In a file system, this corresponds
108
+ # to a directory.
109
+ # _partial<TrueClass, FalseClass>:: Whether or not the file to look up is a partial
110
+ def _determine_template(options)
111
+ if options.key?(:text)
112
+ options[:_template] = ActionView::TextTemplate.new(options[:text], format_for_text)
113
+ elsif options.key?(:inline)
114
+ handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
115
+ template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
116
+ options[:_template] = template
117
+ elsif options.key?(:template)
118
+ options[:_template_name] = options[:template]
119
+ elsif options.key?(:file)
120
+ options[:_template_name] = options[:file]
121
+ end
122
+
123
+ name = (options[:_template_name] || action_name).to_s
124
+
125
+ options[:_template] ||= with_template_cache(name) do
126
+ find_template(name, { :formats => formats }, options)
127
+ end
128
+ end
129
+
130
+ def find_template(name, details, options)
131
+ view_paths.find(name, details, options[:_prefix], options[:_partial])
132
+ end
133
+
134
+ def template_exists?(name, details, options)
135
+ view_paths.exists?(name, details, options[:_prefix], options[:_partial])
136
+ end
137
+
138
+ def with_template_cache(name)
139
+ yield
140
+ end
141
+
142
+ def format_for_text
143
+ Mime[:text]
144
+ end
145
+
146
+ module ClassMethods
147
+ def clear_template_caches!
148
+ end
149
+
150
+ # Append a path to the list of view paths for this controller.
151
+ #
152
+ # ==== Parameters
153
+ # path<String, ViewPath>:: If a String is provided, it gets converted into
154
+ # the default view path. You may also provide a custom view path
155
+ # (see ActionView::ViewPathSet for more information)
156
+ def append_view_path(path)
157
+ self.view_paths << path
158
+ end
159
+
160
+ # Prepend a path to the list of view paths for this controller.
161
+ #
162
+ # ==== Parameters
163
+ # path<String, ViewPath>:: If a String is provided, it gets converted into
164
+ # the default view path. You may also provide a custom view path
165
+ # (see ActionView::ViewPathSet for more information)
166
+ def prepend_view_path(path)
167
+ clear_template_caches!
168
+ self.view_paths.unshift(path)
169
+ end
170
+
171
+ # A list of all of the default view paths for this controller.
172
+ def view_paths
173
+ self._view_paths
174
+ end
175
+
176
+ # Set the view paths.
177
+ #
178
+ # ==== Parameters
179
+ # paths<ViewPathSet, Object>:: If a ViewPathSet is provided, use that;
180
+ # otherwise, process the parameter into a ViewPathSet.
181
+ def view_paths=(paths)
182
+ clear_template_caches!
183
+ self._view_paths = paths.is_a?(ActionView::PathSet) ?
184
+ paths : ActionView::Base.process_view_paths(paths)
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,72 @@
1
+ module ActionController
2
+ autoload :Base, "action_controller/base"
3
+ autoload :Benchmarking, "action_controller/metal/benchmarking"
4
+ autoload :ConditionalGet, "action_controller/metal/conditional_get"
5
+ autoload :Configuration, "action_controller/metal/configuration"
6
+ autoload :Head, "action_controller/metal/head"
7
+ autoload :Helpers, "action_controller/metal/helpers"
8
+ autoload :HideActions, "action_controller/metal/hide_actions"
9
+ autoload :Layouts, "action_controller/metal/layouts"
10
+ autoload :Metal, "action_controller/metal"
11
+ autoload :Middleware, "action_controller/middleware"
12
+ autoload :RackConvenience, "action_controller/metal/rack_convenience"
13
+ autoload :Rails2Compatibility, "action_controller/metal/compatibility"
14
+ autoload :Redirector, "action_controller/metal/redirector"
15
+ autoload :RenderingController, "action_controller/metal/rendering_controller"
16
+ autoload :RenderOptions, "action_controller/metal/render_options"
17
+ autoload :Rescue, "action_controller/metal/rescuable"
18
+ autoload :Responder, "action_controller/metal/responder"
19
+ autoload :Session, "action_controller/metal/session"
20
+ autoload :Testing, "action_controller/metal/testing"
21
+ autoload :UrlFor, "action_controller/metal/url_for"
22
+
23
+ autoload :Caching, 'action_controller/caching'
24
+ autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
25
+ autoload :Integration, 'action_controller/deprecated/integration_test'
26
+ autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
27
+ autoload :MimeResponds, 'action_controller/metal/mime_responds'
28
+ autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
29
+ autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
30
+ autoload :RecordIdentifier, 'action_controller/record_identifier'
31
+ autoload :Routing, 'action_controller/deprecated'
32
+ autoload :SessionManagement, 'action_controller/metal/session_management'
33
+ autoload :TestCase, 'action_controller/testing/test_case'
34
+ autoload :TestProcess, 'action_controller/testing/process'
35
+ autoload :UrlRewriter, 'action_controller/url_rewriter'
36
+ autoload :UrlWriter, 'action_controller/url_rewriter'
37
+
38
+ autoload :Verification, 'action_controller/metal/verification'
39
+ autoload :Flash, 'action_controller/metal/flash'
40
+ autoload :RequestForgeryProtection, 'action_controller/metal/request_forgery_protection'
41
+ autoload :Streaming, 'action_controller/metal/streaming'
42
+ autoload :HttpAuthentication, 'action_controller/metal/http_authentication'
43
+ autoload :FilterParameterLogging, 'action_controller/metal/filter_parameter_logging'
44
+ autoload :Translation, 'action_controller/translation'
45
+ autoload :Cookies, 'action_controller/metal/cookies'
46
+
47
+ autoload :ActionControllerError, 'action_controller/metal/exceptions'
48
+ autoload :RenderError, 'action_controller/metal/exceptions'
49
+ autoload :RoutingError, 'action_controller/metal/exceptions'
50
+ autoload :MethodNotAllowed, 'action_controller/metal/exceptions'
51
+ autoload :NotImplemented, 'action_controller/metal/exceptions'
52
+ autoload :UnknownController, 'action_controller/metal/exceptions'
53
+ autoload :MissingFile, 'action_controller/metal/exceptions'
54
+ autoload :RenderError, 'action_controller/metal/exceptions'
55
+ autoload :SessionOverflowError, 'action_controller/metal/exceptions'
56
+ autoload :UnknownHttpMethod, 'action_controller/metal/exceptions'
57
+ end
58
+
59
+ autoload :HTML, 'action_controller/vendor/html-scanner'
60
+ autoload :AbstractController, 'abstract_controller'
61
+
62
+ require 'action_dispatch'
63
+ require 'action_view'
64
+
65
+ # Common ActiveSupport usage in ActionController
66
+ require "active_support/concern"
67
+ require 'active_support/core_ext/class/attribute_accessors'
68
+ require 'active_support/core_ext/load_error'
69
+ require 'active_support/core_ext/module/attr_internal'
70
+ require 'active_support/core_ext/module/delegation'
71
+ require 'active_support/core_ext/name_error'
72
+ require 'active_support/inflector'
@@ -0,0 +1,168 @@
1
+ module ActionController
2
+ class Base < Metal
3
+ abstract!
4
+
5
+ include AbstractController::Callbacks
6
+ include AbstractController::Logger
7
+
8
+ include ActionController::Helpers
9
+ include ActionController::HideActions
10
+ include ActionController::UrlFor
11
+ include ActionController::Redirector
12
+ include ActionController::RenderingController
13
+ include ActionController::RenderOptions::All
14
+ include ActionController::Layouts
15
+ include ActionController::ConditionalGet
16
+ include ActionController::RackConvenience
17
+ include ActionController::Benchmarking
18
+ include ActionController::Configuration
19
+
20
+ # Legacy modules
21
+ include SessionManagement
22
+ include ActionDispatch::StatusCodes
23
+ include ActionController::Caching
24
+ include ActionController::MimeResponds
25
+
26
+ # Rails 2.x compatibility
27
+ include ActionController::Rails2Compatibility
28
+
29
+ include ActionController::Cookies
30
+ include ActionController::Session
31
+ include ActionController::Flash
32
+ include ActionController::Verification
33
+ include ActionController::RequestForgeryProtection
34
+ include ActionController::Streaming
35
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
36
+ include ActionController::HttpAuthentication::Digest::ControllerMethods
37
+ include ActionController::FilterParameterLogging
38
+ include ActionController::Translation
39
+
40
+ # TODO: Extract into its own module
41
+ # This should be moved together with other normalizing behavior
42
+ module ImplicitRender
43
+ def send_action(*)
44
+ ret = super
45
+ default_render unless response_body
46
+ ret
47
+ end
48
+
49
+ def default_render
50
+ render
51
+ end
52
+
53
+ def method_for_action(action_name)
54
+ super || begin
55
+ if template_exists?(action_name.to_s, {:formats => formats}, :_prefix => controller_path)
56
+ "default_render"
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ include ImplicitRender
63
+
64
+ include ActionController::Rescue
65
+
66
+ def self.inherited(klass)
67
+ ::ActionController::Base.subclasses << klass.to_s
68
+ super
69
+ end
70
+
71
+ def self.subclasses
72
+ @subclasses ||= []
73
+ end
74
+
75
+ def _normalize_options(action = nil, options = {}, &blk)
76
+ if action.is_a?(Hash)
77
+ options, action = action, nil
78
+ elsif action.is_a?(String) || action.is_a?(Symbol)
79
+ key = case action = action.to_s
80
+ when %r{^/} then :file
81
+ when %r{/} then :template
82
+ else :action
83
+ end
84
+ options.merge! key => action
85
+ elsif action
86
+ options.merge! :partial => action
87
+ end
88
+
89
+ if options.key?(:action) && options[:action].to_s.index("/")
90
+ options[:template] = options.delete(:action)
91
+ end
92
+
93
+ if options[:status]
94
+ options[:status] = interpret_status(options[:status]).to_i
95
+ end
96
+
97
+ options[:update] = blk if block_given?
98
+ options
99
+ end
100
+
101
+ def render(action = nil, options = {}, &blk)
102
+ options = _normalize_options(action, options, &blk)
103
+ super(options)
104
+ end
105
+
106
+ def render_to_string(action = nil, options = {}, &blk)
107
+ options = _normalize_options(action, options, &blk)
108
+ super(options)
109
+ end
110
+
111
+ # Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
112
+ #
113
+ # * <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
114
+ # * <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
115
+ # * <tt>String</tt> starting with <tt>protocol://</tt> (like <tt>http://</tt>) - Is passed straight through as the target for redirection.
116
+ # * <tt>String</tt> not containing a protocol - The current protocol and host is prepended to the string.
117
+ # * <tt>:back</tt> - Back to the page that issued the request. Useful for forms that are triggered from multiple places.
118
+ # Short-hand for <tt>redirect_to(request.env["HTTP_REFERER"])</tt>
119
+ #
120
+ # Examples:
121
+ # redirect_to :action => "show", :id => 5
122
+ # redirect_to post
123
+ # redirect_to "http://www.rubyonrails.org"
124
+ # redirect_to "/images/screenshot.jpg"
125
+ # redirect_to articles_url
126
+ # redirect_to :back
127
+ #
128
+ # The redirection happens as a "302 Moved" header unless otherwise specified.
129
+ #
130
+ # Examples:
131
+ # redirect_to post_url(@post), :status=>:found
132
+ # redirect_to :action=>'atom', :status=>:moved_permanently
133
+ # redirect_to post_url(@post), :status=>301
134
+ # redirect_to :action=>'atom', :status=>302
135
+ #
136
+ # When using <tt>redirect_to :back</tt>, if there is no referrer,
137
+ # RedirectBackError will be raised. You may specify some fallback
138
+ # behavior for this case by rescuing RedirectBackError.
139
+ def redirect_to(options = {}, response_status = {}) #:doc:
140
+ raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
141
+
142
+ status = if options.is_a?(Hash) && options.key?(:status)
143
+ interpret_status(options.delete(:status))
144
+ elsif response_status.key?(:status)
145
+ interpret_status(response_status[:status])
146
+ else
147
+ 302
148
+ end
149
+
150
+ url = case options
151
+ # The scheme name consist of a letter followed by any combination of
152
+ # letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
153
+ # characters; and is terminated by a colon (":").
154
+ when %r{^\w[\w\d+.-]*:.*}
155
+ options
156
+ when String
157
+ request.protocol + request.host_with_port + options
158
+ when :back
159
+ raise RedirectBackError unless refer = request.headers["Referer"]
160
+ refer
161
+ else
162
+ url_for(options)
163
+ end
164
+
165
+ super(url, status)
166
+ end
167
+ end
168
+ end