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.

Files changed (241) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +402 -1173
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +7 -7
  5. data/lib/abstract_controller/base.rb +39 -7
  6. data/lib/abstract_controller/callbacks.rb +32 -53
  7. data/lib/abstract_controller/collector.rb +11 -1
  8. data/lib/abstract_controller/helpers.rb +26 -16
  9. data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
  10. data/lib/abstract_controller/rendering.rb +57 -127
  11. data/lib/abstract_controller/url_for.rb +1 -1
  12. data/lib/abstract_controller.rb +1 -2
  13. data/lib/action_controller/base.rb +19 -10
  14. data/lib/action_controller/caching/fragments.rb +7 -1
  15. data/lib/action_controller/caching.rb +2 -12
  16. data/lib/action_controller/log_subscriber.rb +29 -20
  17. data/lib/action_controller/metal/conditional_get.rb +37 -12
  18. data/lib/action_controller/metal/data_streaming.rb +1 -1
  19. data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
  20. data/lib/action_controller/metal/exceptions.rb +1 -1
  21. data/lib/action_controller/metal/flash.rb +17 -0
  22. data/lib/action_controller/metal/force_ssl.rb +2 -2
  23. data/lib/action_controller/metal/head.rb +8 -6
  24. data/lib/action_controller/metal/helpers.rb +6 -2
  25. data/lib/action_controller/metal/http_authentication.rb +45 -23
  26. data/lib/action_controller/metal/instrumentation.rb +9 -6
  27. data/lib/action_controller/metal/live.rb +173 -20
  28. data/lib/action_controller/metal/mime_responds.rb +127 -232
  29. data/lib/action_controller/metal/params_wrapper.rb +16 -9
  30. data/lib/action_controller/metal/rack_delegation.rb +1 -1
  31. data/lib/action_controller/metal/redirecting.rb +34 -26
  32. data/lib/action_controller/metal/renderers.rb +39 -12
  33. data/lib/action_controller/metal/rendering.rb +41 -14
  34. data/lib/action_controller/metal/request_forgery_protection.rb +147 -19
  35. data/lib/action_controller/metal/streaming.rb +19 -21
  36. data/lib/action_controller/metal/strong_parameters.rb +166 -22
  37. data/lib/action_controller/metal/testing.rb +0 -1
  38. data/lib/action_controller/metal/url_for.rb +11 -12
  39. data/lib/action_controller/metal.rb +14 -8
  40. data/lib/action_controller/model_naming.rb +1 -1
  41. data/lib/action_controller/railtie.rb +5 -1
  42. data/lib/action_controller/test_case.rb +160 -94
  43. data/lib/action_controller.rb +2 -18
  44. data/lib/action_dispatch/http/cache.rb +5 -4
  45. data/lib/action_dispatch/http/filter_parameters.rb +2 -2
  46. data/lib/action_dispatch/http/filter_redirect.rb +5 -4
  47. data/lib/action_dispatch/http/headers.rb +46 -10
  48. data/lib/action_dispatch/http/mime_negotiation.rb +31 -4
  49. data/lib/action_dispatch/http/mime_type.rb +25 -26
  50. data/lib/action_dispatch/http/mime_types.rb +1 -0
  51. data/lib/action_dispatch/http/parameter_filter.rb +1 -1
  52. data/lib/action_dispatch/http/parameters.rb +25 -41
  53. data/lib/action_dispatch/http/request.rb +49 -32
  54. data/lib/action_dispatch/http/response.rb +127 -25
  55. data/lib/action_dispatch/http/upload.rb +9 -21
  56. data/lib/action_dispatch/http/url.rb +97 -70
  57. data/lib/action_dispatch/journey/formatter.rb +35 -19
  58. data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
  59. data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
  60. data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -33
  61. data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
  62. data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
  63. data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
  64. data/lib/action_dispatch/journey/nodes/node.rb +4 -0
  65. data/lib/action_dispatch/journey/parser.rb +51 -59
  66. data/lib/action_dispatch/journey/parser.y +12 -10
  67. data/lib/action_dispatch/journey/path/pattern.rb +16 -19
  68. data/lib/action_dispatch/journey/route.rb +8 -19
  69. data/lib/action_dispatch/journey/router/strexp.rb +9 -6
  70. data/lib/action_dispatch/journey/router/utils.rb +54 -18
  71. data/lib/action_dispatch/journey/router.rb +53 -75
  72. data/lib/action_dispatch/journey/routes.rb +4 -0
  73. data/lib/action_dispatch/journey/scanner.rb +5 -5
  74. data/lib/action_dispatch/journey/visitors.rb +81 -60
  75. data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
  76. data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
  77. data/lib/action_dispatch/middleware/callbacks.rb +7 -7
  78. data/lib/action_dispatch/middleware/cookies.rb +119 -43
  79. data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -13
  80. data/lib/action_dispatch/middleware/exception_wrapper.rb +60 -20
  81. data/lib/action_dispatch/middleware/flash.rb +37 -24
  82. data/lib/action_dispatch/middleware/params_parser.rb +2 -2
  83. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
  84. data/lib/action_dispatch/middleware/reloader.rb +11 -2
  85. data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
  86. data/lib/action_dispatch/middleware/request_id.rb +1 -1
  87. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  88. data/lib/action_dispatch/middleware/session/cookie_store.rb +8 -7
  89. data/lib/action_dispatch/middleware/show_exceptions.rb +6 -2
  90. data/lib/action_dispatch/middleware/ssl.rb +10 -7
  91. data/lib/action_dispatch/middleware/static.rb +79 -23
  92. data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
  93. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  94. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
  95. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  96. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  97. data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +1 -1
  98. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  99. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
  100. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  101. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  102. data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +3 -1
  103. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  104. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  105. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  106. data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
  107. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  108. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
  109. data/lib/action_dispatch/railtie.rb +5 -2
  110. data/lib/action_dispatch/request/session.rb +12 -0
  111. data/lib/action_dispatch/request/utils.rb +35 -0
  112. data/lib/action_dispatch/routing/endpoint.rb +10 -0
  113. data/lib/action_dispatch/routing/inspector.rb +11 -17
  114. data/lib/action_dispatch/routing/mapper.rb +519 -312
  115. data/lib/action_dispatch/routing/polymorphic_routes.rb +204 -79
  116. data/lib/action_dispatch/routing/redirection.rb +51 -26
  117. data/lib/action_dispatch/routing/route_set.rb +331 -206
  118. data/lib/action_dispatch/routing/routes_proxy.rb +5 -4
  119. data/lib/action_dispatch/routing/url_for.rb +19 -5
  120. data/lib/action_dispatch/routing.rb +9 -6
  121. data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
  122. data/lib/action_dispatch/testing/assertions/response.rb +9 -15
  123. data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
  124. data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
  125. data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
  126. data/lib/action_dispatch/testing/assertions.rb +11 -7
  127. data/lib/action_dispatch/testing/integration.rb +31 -29
  128. data/lib/action_dispatch/testing/test_request.rb +1 -1
  129. data/lib/action_dispatch/testing/test_response.rb +1 -5
  130. data/lib/action_dispatch.rb +5 -8
  131. data/lib/action_pack/gem_version.rb +15 -0
  132. data/lib/action_pack/version.rb +4 -7
  133. data/lib/action_pack.rb +1 -1
  134. metadata +77 -159
  135. data/lib/abstract_controller/layouts.rb +0 -423
  136. data/lib/abstract_controller/view_paths.rb +0 -96
  137. data/lib/action_controller/deprecated/integration_test.rb +0 -5
  138. data/lib/action_controller/deprecated.rb +0 -7
  139. data/lib/action_controller/metal/responder.rb +0 -287
  140. data/lib/action_controller/record_identifier.rb +0 -31
  141. data/lib/action_controller/vendor/html-scanner.rb +0 -5
  142. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -24
  143. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -7
  144. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -43
  145. data/lib/action_view/base.rb +0 -201
  146. data/lib/action_view/buffers.rb +0 -49
  147. data/lib/action_view/context.rb +0 -36
  148. data/lib/action_view/dependency_tracker.rb +0 -93
  149. data/lib/action_view/digestor.rb +0 -113
  150. data/lib/action_view/flows.rb +0 -76
  151. data/lib/action_view/helpers/active_model_helper.rb +0 -49
  152. data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
  153. data/lib/action_view/helpers/asset_url_helper.rb +0 -355
  154. data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
  155. data/lib/action_view/helpers/cache_helper.rb +0 -196
  156. data/lib/action_view/helpers/capture_helper.rb +0 -216
  157. data/lib/action_view/helpers/controller_helper.rb +0 -25
  158. data/lib/action_view/helpers/csrf_helper.rb +0 -30
  159. data/lib/action_view/helpers/date_helper.rb +0 -1083
  160. data/lib/action_view/helpers/debug_helper.rb +0 -39
  161. data/lib/action_view/helpers/form_helper.rb +0 -1880
  162. data/lib/action_view/helpers/form_options_helper.rb +0 -838
  163. data/lib/action_view/helpers/form_tag_helper.rb +0 -785
  164. data/lib/action_view/helpers/javascript_helper.rb +0 -117
  165. data/lib/action_view/helpers/number_helper.rb +0 -441
  166. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  167. data/lib/action_view/helpers/record_tag_helper.rb +0 -106
  168. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  169. data/lib/action_view/helpers/sanitize_helper.rb +0 -256
  170. data/lib/action_view/helpers/tag_helper.rb +0 -173
  171. data/lib/action_view/helpers/tags/base.rb +0 -148
  172. data/lib/action_view/helpers/tags/check_box.rb +0 -64
  173. data/lib/action_view/helpers/tags/checkable.rb +0 -16
  174. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -44
  175. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
  176. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
  177. data/lib/action_view/helpers/tags/collection_select.rb +0 -28
  178. data/lib/action_view/helpers/tags/color_field.rb +0 -25
  179. data/lib/action_view/helpers/tags/date_field.rb +0 -13
  180. data/lib/action_view/helpers/tags/date_select.rb +0 -72
  181. data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
  182. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
  183. data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
  184. data/lib/action_view/helpers/tags/email_field.rb +0 -8
  185. data/lib/action_view/helpers/tags/file_field.rb +0 -8
  186. data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
  187. data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
  188. data/lib/action_view/helpers/tags/label.rb +0 -66
  189. data/lib/action_view/helpers/tags/month_field.rb +0 -13
  190. data/lib/action_view/helpers/tags/number_field.rb +0 -18
  191. data/lib/action_view/helpers/tags/password_field.rb +0 -12
  192. data/lib/action_view/helpers/tags/radio_button.rb +0 -31
  193. data/lib/action_view/helpers/tags/range_field.rb +0 -8
  194. data/lib/action_view/helpers/tags/search_field.rb +0 -24
  195. data/lib/action_view/helpers/tags/select.rb +0 -40
  196. data/lib/action_view/helpers/tags/tel_field.rb +0 -8
  197. data/lib/action_view/helpers/tags/text_area.rb +0 -18
  198. data/lib/action_view/helpers/tags/text_field.rb +0 -29
  199. data/lib/action_view/helpers/tags/time_field.rb +0 -13
  200. data/lib/action_view/helpers/tags/time_select.rb +0 -8
  201. data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
  202. data/lib/action_view/helpers/tags/url_field.rb +0 -8
  203. data/lib/action_view/helpers/tags/week_field.rb +0 -13
  204. data/lib/action_view/helpers/tags.rb +0 -39
  205. data/lib/action_view/helpers/text_helper.rb +0 -443
  206. data/lib/action_view/helpers/translation_helper.rb +0 -107
  207. data/lib/action_view/helpers/url_helper.rb +0 -635
  208. data/lib/action_view/helpers.rb +0 -58
  209. data/lib/action_view/locale/en.yml +0 -56
  210. data/lib/action_view/log_subscriber.rb +0 -30
  211. data/lib/action_view/lookup_context.rb +0 -241
  212. data/lib/action_view/model_naming.rb +0 -12
  213. data/lib/action_view/path_set.rb +0 -77
  214. data/lib/action_view/railtie.rb +0 -43
  215. data/lib/action_view/record_identifier.rb +0 -84
  216. data/lib/action_view/renderer/abstract_renderer.rb +0 -47
  217. data/lib/action_view/renderer/partial_renderer.rb +0 -492
  218. data/lib/action_view/renderer/renderer.rb +0 -50
  219. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
  220. data/lib/action_view/renderer/template_renderer.rb +0 -96
  221. data/lib/action_view/routing_url_for.rb +0 -107
  222. data/lib/action_view/tasks/dependencies.rake +0 -17
  223. data/lib/action_view/template/error.rb +0 -138
  224. data/lib/action_view/template/handlers/builder.rb +0 -26
  225. data/lib/action_view/template/handlers/erb.rb +0 -146
  226. data/lib/action_view/template/handlers/raw.rb +0 -11
  227. data/lib/action_view/template/handlers.rb +0 -53
  228. data/lib/action_view/template/resolver.rb +0 -326
  229. data/lib/action_view/template/text.rb +0 -34
  230. data/lib/action_view/template/types.rb +0 -57
  231. data/lib/action_view/template.rb +0 -339
  232. data/lib/action_view/test_case.rb +0 -270
  233. data/lib/action_view/testing/resolvers.rb +0 -50
  234. data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
  235. data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
  236. data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
  237. data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
  238. data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
  239. data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
  240. data/lib/action_view/vendor/html-scanner.rb +0 -20
  241. data/lib/action_view.rb +0 -93
@@ -1,58 +0,0 @@
1
- require 'active_support/benchmarkable'
2
-
3
- module ActionView #:nodoc:
4
- module Helpers #:nodoc:
5
- extend ActiveSupport::Autoload
6
-
7
- autoload :ActiveModelHelper
8
- autoload :AssetTagHelper
9
- autoload :AssetUrlHelper
10
- autoload :AtomFeedHelper
11
- autoload :CacheHelper
12
- autoload :CaptureHelper
13
- autoload :ControllerHelper
14
- autoload :CsrfHelper
15
- autoload :DateHelper
16
- autoload :DebugHelper
17
- autoload :FormHelper
18
- autoload :FormOptionsHelper
19
- autoload :FormTagHelper
20
- autoload :JavaScriptHelper, "action_view/helpers/javascript_helper"
21
- autoload :NumberHelper
22
- autoload :OutputSafetyHelper
23
- autoload :RecordTagHelper
24
- autoload :RenderingHelper
25
- autoload :SanitizeHelper
26
- autoload :TagHelper
27
- autoload :TextHelper
28
- autoload :TranslationHelper
29
- autoload :UrlHelper
30
-
31
- extend ActiveSupport::Concern
32
-
33
- include ActiveSupport::Benchmarkable
34
- include ActiveModelHelper
35
- include AssetTagHelper
36
- include AssetUrlHelper
37
- include AtomFeedHelper
38
- include CacheHelper
39
- include CaptureHelper
40
- include ControllerHelper
41
- include CsrfHelper
42
- include DateHelper
43
- include DebugHelper
44
- include FormHelper
45
- include FormOptionsHelper
46
- include FormTagHelper
47
- include JavaScriptHelper
48
- include NumberHelper
49
- include OutputSafetyHelper
50
- include RecordTagHelper
51
- include RenderingHelper
52
- include SanitizeHelper
53
- include TagHelper
54
- include TextHelper
55
- include TranslationHelper
56
- include UrlHelper
57
- end
58
- end
@@ -1,56 +0,0 @@
1
- "en":
2
- # Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
3
- datetime:
4
- distance_in_words:
5
- half_a_minute: "half a minute"
6
- less_than_x_seconds:
7
- one: "less than 1 second"
8
- other: "less than %{count} seconds"
9
- x_seconds:
10
- one: "1 second"
11
- other: "%{count} seconds"
12
- less_than_x_minutes:
13
- one: "less than a minute"
14
- other: "less than %{count} minutes"
15
- x_minutes:
16
- one: "1 minute"
17
- other: "%{count} minutes"
18
- about_x_hours:
19
- one: "about 1 hour"
20
- other: "about %{count} hours"
21
- x_days:
22
- one: "1 day"
23
- other: "%{count} days"
24
- about_x_months:
25
- one: "about 1 month"
26
- other: "about %{count} months"
27
- x_months:
28
- one: "1 month"
29
- other: "%{count} months"
30
- about_x_years:
31
- one: "about 1 year"
32
- other: "about %{count} years"
33
- over_x_years:
34
- one: "over 1 year"
35
- other: "over %{count} years"
36
- almost_x_years:
37
- one: "almost 1 year"
38
- other: "almost %{count} years"
39
- prompts:
40
- year: "Year"
41
- month: "Month"
42
- day: "Day"
43
- hour: "Hour"
44
- minute: "Minute"
45
- second: "Seconds"
46
-
47
- helpers:
48
- select:
49
- # Default value for :prompt => true in FormOptionsHelper
50
- prompt: "Please select"
51
-
52
- # Default translation keys for submit and button FormHelper
53
- submit:
54
- create: 'Create %{model}'
55
- update: 'Update %{model}'
56
- submit: 'Save %{model}'
@@ -1,30 +0,0 @@
1
- module ActionView
2
- # = Action View Log Subscriber
3
- #
4
- # Provides functionality so that Rails can output logs from Action View.
5
- class LogSubscriber < ActiveSupport::LogSubscriber
6
- VIEWS_PATTERN = /^app\/views\//.freeze
7
-
8
- def render_template(event)
9
- return unless logger.info?
10
- message = " Rendered #{from_rails_root(event.payload[:identifier])}"
11
- message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
12
- message << " (#{event.duration.round(1)}ms)"
13
- info(message)
14
- end
15
- alias :render_partial :render_template
16
- alias :render_collection :render_template
17
-
18
- def logger
19
- ActionView::Base.logger
20
- end
21
-
22
- protected
23
-
24
- def from_rails_root(string)
25
- string.sub("#{Rails.root}/", "").sub(VIEWS_PATTERN, "")
26
- end
27
- end
28
- end
29
-
30
- ActionView::LogSubscriber.attach_to :action_view
@@ -1,241 +0,0 @@
1
- require 'thread_safe'
2
- require 'active_support/core_ext/module/remove_method'
3
- require 'active_support/core_ext/module/attribute_accessors'
4
-
5
- module ActionView
6
- # = Action View Lookup Context
7
- #
8
- # LookupContext is the object responsible to hold all information required to lookup
9
- # templates, i.e. view paths and details. The LookupContext is also responsible to
10
- # generate a key, given to view paths, used in the resolver cache lookup. Since
11
- # this key is generated just once during the request, it speeds up all cache accesses.
12
- class LookupContext #:nodoc:
13
- attr_accessor :prefixes, :rendered_format
14
-
15
- mattr_accessor :fallbacks
16
- @@fallbacks = FallbackFileSystemResolver.instances
17
-
18
- mattr_accessor :registered_details
19
- self.registered_details = []
20
-
21
- def self.register_detail(name, options = {}, &block)
22
- self.registered_details << name
23
- initialize = registered_details.map { |n| "@details[:#{n}] = details[:#{n}] || default_#{n}" }
24
-
25
- Accessors.send :define_method, :"default_#{name}", &block
26
- Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1
27
- def #{name}
28
- @details.fetch(:#{name}, [])
29
- end
30
-
31
- def #{name}=(value)
32
- value = value.present? ? Array(value) : default_#{name}
33
- _set_detail(:#{name}, value) if value != @details[:#{name}]
34
- end
35
-
36
- remove_possible_method :initialize_details
37
- def initialize_details(details)
38
- #{initialize.join("\n")}
39
- end
40
- METHOD
41
- end
42
-
43
- # Holds accessors for the registered details.
44
- module Accessors #:nodoc:
45
- end
46
-
47
- register_detail(:locale) do
48
- locales = [I18n.locale]
49
- locales.concat(I18n.fallbacks[I18n.locale]) if I18n.respond_to? :fallbacks
50
- locales << I18n.default_locale
51
- locales.uniq!
52
- locales
53
- end
54
- register_detail(:formats) { ActionView::Base.default_formats || [:html, :text, :js, :css, :xml, :json] }
55
- register_detail(:handlers){ Template::Handlers.extensions }
56
-
57
- class DetailsKey #:nodoc:
58
- alias :eql? :equal?
59
- alias :object_hash :hash
60
-
61
- attr_reader :hash
62
- @details_keys = ThreadSafe::Cache.new
63
-
64
- def self.get(details)
65
- @details_keys[details] ||= new
66
- end
67
-
68
- def self.clear
69
- @details_keys.clear
70
- end
71
-
72
- def initialize
73
- @hash = object_hash
74
- end
75
- end
76
-
77
- # Add caching behavior on top of Details.
78
- module DetailsCache
79
- attr_accessor :cache
80
-
81
- # Calculate the details key. Remove the handlers from calculation to improve performance
82
- # since the user cannot modify it explicitly.
83
- def details_key #:nodoc:
84
- @details_key ||= DetailsKey.get(@details) if @cache
85
- end
86
-
87
- # Temporary skip passing the details_key forward.
88
- def disable_cache
89
- old_value, @cache = @cache, false
90
- yield
91
- ensure
92
- @cache = old_value
93
- end
94
-
95
- protected
96
-
97
- def _set_detail(key, value)
98
- @details = @details.dup if @details_key
99
- @details_key = nil
100
- @details[key] = value
101
- end
102
- end
103
-
104
- # Helpers related to template lookup using the lookup context information.
105
- module ViewPaths
106
- attr_reader :view_paths, :html_fallback_for_js
107
-
108
- # Whenever setting view paths, makes a copy so we can manipulate then in
109
- # instance objects as we wish.
110
- def view_paths=(paths)
111
- @view_paths = ActionView::PathSet.new(Array(paths))
112
- end
113
-
114
- def find(name, prefixes = [], partial = false, keys = [], options = {})
115
- @view_paths.find(*args_for_lookup(name, prefixes, partial, keys, options))
116
- end
117
- alias :find_template :find
118
-
119
- def find_all(name, prefixes = [], partial = false, keys = [], options = {})
120
- @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options))
121
- end
122
-
123
- def exists?(name, prefixes = [], partial = false, keys = [], options = {})
124
- @view_paths.exists?(*args_for_lookup(name, prefixes, partial, keys, options))
125
- end
126
- alias :template_exists? :exists?
127
-
128
- # Add fallbacks to the view paths. Useful in cases you are rendering a :file.
129
- def with_fallbacks
130
- added_resolvers = 0
131
- self.class.fallbacks.each do |resolver|
132
- next if view_paths.include?(resolver)
133
- view_paths.push(resolver)
134
- added_resolvers += 1
135
- end
136
- yield
137
- ensure
138
- added_resolvers.times { view_paths.pop }
139
- end
140
-
141
- protected
142
-
143
- def args_for_lookup(name, prefixes, partial, keys, details_options) #:nodoc:
144
- name, prefixes = normalize_name(name, prefixes)
145
- details, details_key = detail_args_for(details_options)
146
- [name, prefixes, partial || false, details, details_key, keys]
147
- end
148
-
149
- # Compute details hash and key according to user options (e.g. passed from #render).
150
- def detail_args_for(options)
151
- return @details, details_key if options.empty? # most common path.
152
- user_details = @details.merge(options)
153
- [user_details, DetailsKey.get(user_details)]
154
- end
155
-
156
- # Support legacy foo.erb names even though we now ignore .erb
157
- # as well as incorrectly putting part of the path in the template
158
- # name instead of the prefix.
159
- def normalize_name(name, prefixes) #:nodoc:
160
- prefixes = prefixes.presence
161
- parts = name.to_s.split('/')
162
- parts.shift if parts.first.empty?
163
- name = parts.pop
164
-
165
- return name, prefixes || [""] if parts.empty?
166
-
167
- parts = parts.join('/')
168
- prefixes = prefixes ? prefixes.map { |p| "#{p}/#{parts}" } : [parts]
169
-
170
- return name, prefixes
171
- end
172
- end
173
-
174
- include Accessors
175
- include DetailsCache
176
- include ViewPaths
177
-
178
- def initialize(view_paths, details = {}, prefixes = [])
179
- @details, @details_key = {}, nil
180
- @skip_default_locale = false
181
- @cache = true
182
- @prefixes = prefixes
183
- @rendered_format = nil
184
-
185
- self.view_paths = view_paths
186
- initialize_details(details)
187
- end
188
-
189
- # Override formats= to expand ["*/*"] values and automatically
190
- # add :html as fallback to :js.
191
- def formats=(values)
192
- if values
193
- values.concat(default_formats) if values.delete "*/*"
194
- if values == [:js]
195
- values << :html
196
- @html_fallback_for_js = true
197
- end
198
- end
199
- super(values)
200
- end
201
-
202
- # Do not use the default locale on template lookup.
203
- def skip_default_locale!
204
- @skip_default_locale = true
205
- self.locale = nil
206
- end
207
-
208
- # Override locale to return a symbol instead of array.
209
- def locale
210
- @details[:locale].first
211
- end
212
-
213
- # Overload locale= to also set the I18n.locale. If the current I18n.config object responds
214
- # to original_config, it means that it's has a copy of the original I18n configuration and it's
215
- # acting as proxy, which we need to skip.
216
- def locale=(value)
217
- if value
218
- config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
219
- config.locale = value
220
- end
221
-
222
- super(@skip_default_locale ? I18n.locale : default_locale)
223
- end
224
-
225
- # A method which only uses the first format in the formats array for layout lookup.
226
- def with_layout_format
227
- if formats.size == 1
228
- yield
229
- else
230
- old_formats = formats
231
- _set_detail(:formats, formats[0,1])
232
-
233
- begin
234
- yield
235
- ensure
236
- _set_detail(:formats, old_formats)
237
- end
238
- end
239
- end
240
- end
241
- end
@@ -1,12 +0,0 @@
1
- module ActionView
2
- module ModelNaming
3
- # Converts the given object to an ActiveModel compliant one.
4
- def convert_to_model(object)
5
- object.respond_to?(:to_model) ? object.to_model : object
6
- end
7
-
8
- def model_name_from_record_or_class(record_or_class)
9
- (record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
10
- end
11
- end
12
- end
@@ -1,77 +0,0 @@
1
- module ActionView #:nodoc:
2
- # = Action View PathSet
3
- #
4
- # This class is used to store and access paths in Action View. A number of
5
- # operations are defined so that you can search among the paths in this
6
- # set and also perform operations on other +PathSet+ objects.
7
- #
8
- # A +LookupContext+ will use a +PathSet+ to store the paths in its context.
9
- class PathSet #:nodoc:
10
- include Enumerable
11
-
12
- attr_reader :paths
13
-
14
- delegate :[], :include?, :pop, :size, :each, to: :paths
15
-
16
- def initialize(paths = [])
17
- @paths = typecast paths
18
- end
19
-
20
- def initialize_copy(other)
21
- @paths = other.paths.dup
22
- self
23
- end
24
-
25
- def to_ary
26
- paths.dup
27
- end
28
-
29
- def compact
30
- PathSet.new paths.compact
31
- end
32
-
33
- def +(array)
34
- PathSet.new(paths + array)
35
- end
36
-
37
- %w(<< concat push insert unshift).each do |method|
38
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
39
- def #{method}(*args)
40
- paths.#{method}(*typecast(args))
41
- end
42
- METHOD
43
- end
44
-
45
- def find(*args)
46
- find_all(*args).first || raise(MissingTemplate.new(self, *args))
47
- end
48
-
49
- def find_all(path, prefixes = [], *args)
50
- prefixes = [prefixes] if String === prefixes
51
- prefixes.each do |prefix|
52
- paths.each do |resolver|
53
- templates = resolver.find_all(path, prefix, *args)
54
- return templates unless templates.empty?
55
- end
56
- end
57
- []
58
- end
59
-
60
- def exists?(path, prefixes, *args)
61
- find_all(path, prefixes, *args).any?
62
- end
63
-
64
- private
65
-
66
- def typecast(paths)
67
- paths.map do |path|
68
- case path
69
- when Pathname, String
70
- OptimizedFileSystemResolver.new path.to_s
71
- else
72
- path
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,43 +0,0 @@
1
- require "action_view"
2
- require "rails"
3
-
4
- module ActionView
5
- # = Action View Railtie
6
- class Railtie < Rails::Railtie # :nodoc:
7
- config.action_view = ActiveSupport::OrderedOptions.new
8
- config.action_view.embed_authenticity_token_in_remote_forms = false
9
-
10
- config.eager_load_namespaces << ActionView
11
-
12
- initializer "action_view.embed_authenticity_token_in_remote_forms" do |app|
13
- ActiveSupport.on_load(:action_view) do
14
- ActionView::Helpers::FormTagHelper.embed_authenticity_token_in_remote_forms =
15
- app.config.action_view.delete(:embed_authenticity_token_in_remote_forms)
16
- end
17
- end
18
-
19
- initializer "action_view.logger" do
20
- ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger }
21
- end
22
-
23
- initializer "action_view.set_configs" do |app|
24
- ActiveSupport.on_load(:action_view) do
25
- app.config.action_view.each do |k,v|
26
- send "#{k}=", v
27
- end
28
- end
29
- end
30
-
31
- initializer "action_view.caching" do |app|
32
- ActiveSupport.on_load(:action_view) do
33
- if app.config.action_view.cache_template_loading.nil?
34
- ActionView::Resolver.caching = app.config.cache_classes
35
- end
36
- end
37
- end
38
-
39
- rake_tasks do
40
- load "action_view/tasks/dependencies.rake"
41
- end
42
- end
43
- end
@@ -1,84 +0,0 @@
1
- require 'active_support/core_ext/module'
2
- require 'action_view/model_naming'
3
-
4
- module ActionView
5
- # The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
6
- # pretty much any other model type that has an id. These patterns are then used to try elevate the view actions to
7
- # a higher logical level.
8
- #
9
- # # routes
10
- # resources :posts
11
- #
12
- # # view
13
- # <%= div_for(post) do %> <div id="post_45" class="post">
14
- # <%= post.body %> What a wonderful world!
15
- # <% end %> </div>
16
- #
17
- # # controller
18
- # def update
19
- # post = Post.find(params[:id])
20
- # post.update(params[:post])
21
- #
22
- # redirect_to(post) # Calls polymorphic_url(post) which in turn calls post_url(post)
23
- # end
24
- #
25
- # As the example above shows, you can stop caring to a large extent what the actual id of the post is.
26
- # You just know that one is being assigned and that the subsequent calls in redirect_to expect that
27
- # same naming convention and allows you to write less code if you follow it.
28
- module RecordIdentifier
29
- extend self
30
- extend ModelNaming
31
-
32
- include ModelNaming
33
-
34
- JOIN = '_'.freeze
35
- NEW = 'new'.freeze
36
-
37
- # The DOM class convention is to use the singular form of an object or class.
38
- #
39
- # dom_class(post) # => "post"
40
- # dom_class(Person) # => "person"
41
- #
42
- # If you need to address multiple instances of the same class in the same view, you can prefix the dom_class:
43
- #
44
- # dom_class(post, :edit) # => "edit_post"
45
- # dom_class(Person, :edit) # => "edit_person"
46
- def dom_class(record_or_class, prefix = nil)
47
- singular = model_name_from_record_or_class(record_or_class).param_key
48
- prefix ? "#{prefix}#{JOIN}#{singular}" : singular
49
- end
50
-
51
- # The DOM id convention is to use the singular form of an object or class with the id following an underscore.
52
- # If no id is found, prefix with "new_" instead.
53
- #
54
- # dom_id(Post.find(45)) # => "post_45"
55
- # dom_id(Post.new) # => "new_post"
56
- #
57
- # If you need to address multiple instances of the same class in the same view, you can prefix the dom_id:
58
- #
59
- # dom_id(Post.find(45), :edit) # => "edit_post_45"
60
- # dom_id(Post.new, :custom) # => "custom_post"
61
- def dom_id(record, prefix = nil)
62
- if record_id = record_key_for_dom_id(record)
63
- "#{dom_class(record, prefix)}#{JOIN}#{record_id}"
64
- else
65
- dom_class(record, prefix || NEW)
66
- end
67
- end
68
-
69
- protected
70
-
71
- # Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
72
- # This can be overwritten to customize the default generated string representation if desired.
73
- # If you need to read back a key from a dom_id in order to query for the underlying database record,
74
- # you should write a helper like 'person_record_from_dom_id' that will extract the key either based
75
- # on the default implementation (which just joins all key attributes with '_') or on your own
76
- # overwritten version of the method. By default, this implementation passes the key string through a
77
- # method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to
78
- # make sure yourself that your dom ids are valid, in case you overwrite this method.
79
- def record_key_for_dom_id(record)
80
- key = convert_to_model(record).to_key
81
- key ? key.join('_') : key
82
- end
83
- end
84
- end
@@ -1,47 +0,0 @@
1
- module ActionView
2
- # This class defines the interface for a renderer. Each class that
3
- # subclasses +AbstractRenderer+ is used by the base +Renderer+ class to
4
- # render a specific type of object.
5
- #
6
- # The base +Renderer+ class uses its +render+ method to delegate to the
7
- # renderers. These currently consist of
8
- #
9
- # PartialRenderer - Used for rendering partials
10
- # TemplateRenderer - Used for rendering other types of templates
11
- # StreamingTemplateRenderer - Used for streaming
12
- #
13
- # Whenever the +render+ method is called on the base +Renderer+ class, a new
14
- # renderer object of the correct type is created, and the +render+ method on
15
- # that new object is called in turn. This abstracts the setup and rendering
16
- # into a separate classes for partials and templates.
17
- class AbstractRenderer #:nodoc:
18
- delegate :find_template, :template_exists?, :with_fallbacks, :with_layout_format, :formats, :to => :@lookup_context
19
-
20
- def initialize(lookup_context)
21
- @lookup_context = lookup_context
22
- end
23
-
24
- def render
25
- raise NotImplementedError
26
- end
27
-
28
- protected
29
-
30
- def extract_details(options)
31
- @lookup_context.registered_details.each_with_object({}) do |key, details|
32
- next unless value = options[key]
33
- details[key] = Array(value)
34
- end
35
- end
36
-
37
- def instrument(name, options={})
38
- ActiveSupport::Notifications.instrument("render_#{name}.action_view", options){ yield }
39
- end
40
-
41
- def prepend_formats(formats)
42
- formats = Array(formats)
43
- return if formats.empty? || @lookup_context.html_fallback_for_js
44
- @lookup_context.formats = formats | @lookup_context.formats
45
- end
46
- end
47
- end