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,96 +0,0 @@
1
- require 'active_support/core_ext/object/try'
2
-
3
- module ActionView
4
- class TemplateRenderer < AbstractRenderer #:nodoc:
5
- def render(context, options)
6
- @view = context
7
- @details = extract_details(options)
8
- template = determine_template(options)
9
- context = @lookup_context
10
-
11
- prepend_formats(template.formats)
12
-
13
- unless context.rendered_format
14
- context.rendered_format = template.formats.first || formats.first
15
- end
16
-
17
- render_template(template, options[:layout], options[:locals])
18
- end
19
-
20
- # Determine the template to be rendered using the given options.
21
- def determine_template(options) #:nodoc:
22
- keys = options.fetch(:locals, {}).keys
23
-
24
- if options.key?(:text)
25
- Template::Text.new(options[:text], formats.first)
26
- elsif options.key?(:file)
27
- with_fallbacks { find_template(options[:file], nil, false, keys, @details) }
28
- elsif options.key?(:inline)
29
- handler = Template.handler_for_extension(options[:type] || "erb")
30
- Template.new(options[:inline], "inline template", handler, :locals => keys)
31
- elsif options.key?(:template)
32
- if options[:template].respond_to?(:render)
33
- options[:template]
34
- else
35
- find_template(options[:template], options[:prefixes], false, keys, @details)
36
- end
37
- else
38
- raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file or :text option."
39
- end
40
- end
41
-
42
- # Renders the given template. A string representing the layout can be
43
- # supplied as well.
44
- def render_template(template, layout_name = nil, locals = nil) #:nodoc:
45
- view, locals = @view, locals || {}
46
-
47
- render_with_layout(layout_name, locals) do |layout|
48
- instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
49
- template.render(view, locals) { |*name| view._layout_for(*name) }
50
- end
51
- end
52
- end
53
-
54
- def render_with_layout(path, locals) #:nodoc:
55
- layout = path && find_layout(path, locals.keys)
56
- content = yield(layout)
57
-
58
- if layout
59
- view = @view
60
- view.view_flow.set(:layout, content)
61
- layout.render(view, locals){ |*name| view._layout_for(*name) }
62
- else
63
- content
64
- end
65
- end
66
-
67
- # This is the method which actually finds the layout using details in the lookup
68
- # context object. If no layout is found, it checks if at least a layout with
69
- # the given name exists across all details before raising the error.
70
- def find_layout(layout, keys)
71
- with_layout_format { resolve_layout(layout, keys) }
72
- end
73
-
74
- def resolve_layout(layout, keys)
75
- case layout
76
- when String
77
- begin
78
- if layout =~ /^\//
79
- with_fallbacks { find_template(layout, nil, false, keys, @details) }
80
- else
81
- find_template(layout, nil, false, keys, @details)
82
- end
83
- rescue ActionView::MissingTemplate
84
- all_details = @details.merge(:formats => @lookup_context.default_formats)
85
- raise unless template_exists?(layout, nil, false, keys, all_details)
86
- end
87
- when Proc
88
- resolve_layout(layout.call, keys)
89
- when FalseClass
90
- nil
91
- else
92
- layout
93
- end
94
- end
95
- end
96
- end
@@ -1,107 +0,0 @@
1
- module ActionView
2
- module RoutingUrlFor
3
-
4
- # Returns the URL for the set of +options+ provided. This takes the
5
- # same options as +url_for+ in Action Controller (see the
6
- # documentation for <tt>ActionController::Base#url_for</tt>). Note that by default
7
- # <tt>:only_path</tt> is <tt>true</tt> so you'll get the relative "/controller/action"
8
- # instead of the fully qualified URL like "http://example.com/controller/action".
9
- #
10
- # ==== Options
11
- # * <tt>:anchor</tt> - Specifies the anchor name to be appended to the path.
12
- # * <tt>:only_path</tt> - If true, returns the relative URL (omitting the protocol, host name, and port) (<tt>true</tt> by default unless <tt>:host</tt> is specified).
13
- # * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2005/". Note that this
14
- # is currently not recommended since it breaks caching.
15
- # * <tt>:host</tt> - Overrides the default (current) host if provided.
16
- # * <tt>:protocol</tt> - Overrides the default (current) protocol if provided.
17
- # * <tt>:user</tt> - Inline HTTP authentication (only plucked out if <tt>:password</tt> is also present).
18
- # * <tt>:password</tt> - Inline HTTP authentication (only plucked out if <tt>:user</tt> is also present).
19
- #
20
- # ==== Relying on named routes
21
- #
22
- # Passing a record (like an Active Record) instead of a hash as the options parameter will
23
- # trigger the named route for that record. The lookup will happen on the name of the class. So passing a
24
- # Workshop object will attempt to use the +workshop_path+ route. If you have a nested route, such as
25
- # +admin_workshop_path+ you'll have to call that explicitly (it's impossible for +url_for+ to guess that route).
26
- #
27
- # ==== Implicit Controller Namespacing
28
- #
29
- # Controllers passed in using the +:controller+ option will retain their namespace unless it is an absolute one.
30
- #
31
- # ==== Examples
32
- # <%= url_for(action: 'index') %>
33
- # # => /blog/
34
- #
35
- # <%= url_for(action: 'find', controller: 'books') %>
36
- # # => /books/find
37
- #
38
- # <%= url_for(action: 'login', controller: 'members', only_path: false, protocol: 'https') %>
39
- # # => https://www.example.com/members/login/
40
- #
41
- # <%= url_for(action: 'play', anchor: 'player') %>
42
- # # => /messages/play/#player
43
- #
44
- # <%= url_for(action: 'jump', anchor: 'tax&ship') %>
45
- # # => /testing/jump/#tax&ship
46
- #
47
- # <%= url_for(Workshop.new) %>
48
- # # relies on Workshop answering a persisted? call (and in this case returning false)
49
- # # => /workshops
50
- #
51
- # <%= url_for(@workshop) %>
52
- # # calls @workshop.to_param which by default returns the id
53
- # # => /workshops/5
54
- #
55
- # # to_param can be re-defined in a model to provide different URL names:
56
- # # => /workshops/1-workshop-name
57
- #
58
- # <%= url_for("http://www.example.com") %>
59
- # # => http://www.example.com
60
- #
61
- # <%= url_for(:back) %>
62
- # # if request.env["HTTP_REFERER"] is set to "http://www.example.com"
63
- # # => http://www.example.com
64
- #
65
- # <%= url_for(:back) %>
66
- # # if request.env["HTTP_REFERER"] is not set or is blank
67
- # # => javascript:history.back()
68
- #
69
- # <%= url_for(action: 'index', controller: 'users') %>
70
- # # Assuming an "admin" namespace
71
- # # => /admin/users
72
- #
73
- # <%= url_for(action: 'index', controller: '/users') %>
74
- # # Specify absolute path with beginning slash
75
- # # => /users
76
- def url_for(options = nil)
77
- case options
78
- when String
79
- options
80
- when nil, Hash
81
- options ||= {}
82
- options = { :only_path => options[:host].nil? }.merge!(options.symbolize_keys)
83
- super
84
- when :back
85
- _back_url
86
- else
87
- polymorphic_path(options)
88
- end
89
- end
90
-
91
- def url_options #:nodoc:
92
- return super unless controller.respond_to?(:url_options)
93
- controller.url_options
94
- end
95
-
96
- def _routes_context #:nodoc:
97
- controller
98
- end
99
- protected :_routes_context
100
-
101
- def optimize_routes_generation? #:nodoc:
102
- controller.respond_to?(:optimize_routes_generation?, true) ?
103
- controller.optimize_routes_generation? : super
104
- end
105
- protected :optimize_routes_generation?
106
- end
107
- end
@@ -1,17 +0,0 @@
1
- namespace :cache_digests do
2
- desc 'Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)'
3
- task :nested_dependencies => :environment do
4
- abort 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present?
5
- template, format = ENV['TEMPLATE'].split(".")
6
- format ||= :html
7
- puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).nested_dependencies
8
- end
9
-
10
- desc 'Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)'
11
- task :dependencies => :environment do
12
- abort 'You must provide TEMPLATE for the task to run' unless ENV['TEMPLATE'].present?
13
- template, format = ENV['TEMPLATE'].split(".")
14
- format ||= :html
15
- puts JSON.pretty_generate ActionView::Digestor.new(template, format, ApplicationController.new.lookup_context).dependencies
16
- end
17
- end
@@ -1,138 +0,0 @@
1
- require "active_support/core_ext/enumerable"
2
-
3
- module ActionView
4
- # = Action View Errors
5
- class ActionViewError < StandardError #:nodoc:
6
- end
7
-
8
- class EncodingError < StandardError #:nodoc:
9
- end
10
-
11
- class MissingRequestError < StandardError #:nodoc:
12
- end
13
-
14
- class WrongEncodingError < EncodingError #:nodoc:
15
- def initialize(string, encoding)
16
- @string, @encoding = string, encoding
17
- end
18
-
19
- def message
20
- @string.force_encoding(Encoding::ASCII_8BIT)
21
- "Your template was not saved as valid #{@encoding}. Please " \
22
- "either specify #{@encoding} as the encoding for your template " \
23
- "in your text editor, or mark the template with its " \
24
- "encoding by inserting the following as the first line " \
25
- "of the template:\n\n# encoding: <name of correct encoding>.\n\n" \
26
- "The source of your template was:\n\n#{@string}"
27
- end
28
- end
29
-
30
- class MissingTemplate < ActionViewError #:nodoc:
31
- attr_reader :path
32
-
33
- def initialize(paths, path, prefixes, partial, details, *)
34
- @path = path
35
- prefixes = Array(prefixes)
36
- template_type = if partial
37
- "partial"
38
- elsif path =~ /layouts/i
39
- 'layout'
40
- else
41
- 'template'
42
- end
43
-
44
- searched_paths = prefixes.map { |prefix| [prefix, path].join("/") }
45
-
46
- out = "Missing #{template_type} #{searched_paths.join(", ")} with #{details.inspect}. Searched in:\n"
47
- out += paths.compact.map { |p| " * #{p.to_s.inspect}\n" }.join
48
- super out
49
- end
50
- end
51
-
52
- class Template
53
- # The Template::Error exception is raised when the compilation or rendering of the template
54
- # fails. This exception then gathers a bunch of intimate details and uses it to report a
55
- # precise exception message.
56
- class Error < ActionViewError #:nodoc:
57
- SOURCE_CODE_RADIUS = 3
58
-
59
- attr_reader :original_exception, :backtrace
60
-
61
- def initialize(template, original_exception)
62
- super(original_exception.message)
63
- @template, @original_exception = template, original_exception
64
- @sub_templates = nil
65
- @backtrace = original_exception.backtrace
66
- end
67
-
68
- def file_name
69
- @template.identifier
70
- end
71
-
72
- def sub_template_message
73
- if @sub_templates
74
- "Trace of template inclusion: " +
75
- @sub_templates.collect { |template| template.inspect }.join(", ")
76
- else
77
- ""
78
- end
79
- end
80
-
81
- def source_extract(indentation = 0, output = :console)
82
- return unless num = line_number
83
- num = num.to_i
84
-
85
- source_code = @template.source.split("\n")
86
-
87
- start_on_line = [ num - SOURCE_CODE_RADIUS - 1, 0 ].max
88
- end_on_line = [ num + SOURCE_CODE_RADIUS - 1, source_code.length].min
89
-
90
- indent = end_on_line.to_s.size + indentation
91
- return unless source_code = source_code[start_on_line..end_on_line]
92
-
93
- formatted_code_for(source_code, start_on_line, indent, output)
94
- end
95
-
96
- def sub_template_of(template_path)
97
- @sub_templates ||= []
98
- @sub_templates << template_path
99
- end
100
-
101
- def line_number
102
- @line_number ||=
103
- if file_name
104
- regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
105
- $1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
106
- end
107
- end
108
-
109
- def annoted_source_code
110
- source_extract(4)
111
- end
112
-
113
- private
114
-
115
- def source_location
116
- if line_number
117
- "on line ##{line_number} of "
118
- else
119
- 'in '
120
- end + file_name
121
- end
122
-
123
- def formatted_code_for(source_code, line_counter, indent, output)
124
- start_value = (output == :html) ? {} : ""
125
- source_code.inject(start_value) do |result, line|
126
- line_counter += 1
127
- if output == :html
128
- result.update(line_counter.to_s => "%#{indent}s %s\n" % ["", line])
129
- else
130
- result << "%#{indent}s: %s\n" % [line_counter, line]
131
- end
132
- end
133
- end
134
- end
135
- end
136
-
137
- TemplateError = Template::Error
138
- end
@@ -1,26 +0,0 @@
1
- module ActionView
2
- module Template::Handlers
3
- class Builder
4
- # Default format used by Builder.
5
- class_attribute :default_format
6
- self.default_format = :xml
7
-
8
- def call(template)
9
- require_engine
10
- "xml = ::Builder::XmlMarkup.new(:indent => 2);" +
11
- "self.output_buffer = xml.target!;" +
12
- template.source +
13
- ";xml.target!;"
14
- end
15
-
16
- protected
17
-
18
- def require_engine
19
- @required ||= begin
20
- require "builder"
21
- true
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,146 +0,0 @@
1
- require 'action_dispatch/http/mime_type'
2
- require 'erubis'
3
-
4
- module ActionView
5
- class Template
6
- module Handlers
7
- class Erubis < ::Erubis::Eruby
8
- def add_preamble(src)
9
- @newline_pending = 0
10
- src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
11
- end
12
-
13
- def add_text(src, text)
14
- return if text.empty?
15
-
16
- if text == "\n"
17
- @newline_pending += 1
18
- else
19
- src << "@output_buffer.safe_append='"
20
- src << "\n" * @newline_pending if @newline_pending > 0
21
- src << escape_text(text)
22
- src << "';"
23
-
24
- @newline_pending = 0
25
- end
26
- end
27
-
28
- # Erubis toggles <%= and <%== behavior when escaping is enabled.
29
- # We override to always treat <%== as escaped.
30
- def add_expr(src, code, indicator)
31
- case indicator
32
- when '=='
33
- add_expr_escaped(src, code)
34
- else
35
- super
36
- end
37
- end
38
-
39
- BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
40
-
41
- def add_expr_literal(src, code)
42
- flush_newline_if_pending(src)
43
- if code =~ BLOCK_EXPR
44
- src << '@output_buffer.append= ' << code
45
- else
46
- src << '@output_buffer.append=(' << code << ');'
47
- end
48
- end
49
-
50
- def add_expr_escaped(src, code)
51
- flush_newline_if_pending(src)
52
- if code =~ BLOCK_EXPR
53
- src << "@output_buffer.safe_append= " << code
54
- else
55
- src << "@output_buffer.safe_append=(" << code << ");"
56
- end
57
- end
58
-
59
- def add_stmt(src, code)
60
- flush_newline_if_pending(src)
61
- super
62
- end
63
-
64
- def add_postamble(src)
65
- flush_newline_if_pending(src)
66
- src << '@output_buffer.to_s'
67
- end
68
-
69
- def flush_newline_if_pending(src)
70
- if @newline_pending > 0
71
- src << "@output_buffer.safe_append='#{"\n" * @newline_pending}';"
72
- @newline_pending = 0
73
- end
74
- end
75
- end
76
-
77
- class ERB
78
- # Specify trim mode for the ERB compiler. Defaults to '-'.
79
- # See ERB documentation for suitable values.
80
- class_attribute :erb_trim_mode
81
- self.erb_trim_mode = '-'
82
-
83
- # Default implementation used.
84
- class_attribute :erb_implementation
85
- self.erb_implementation = Erubis
86
-
87
- # Do not escape templates of these mime types.
88
- class_attribute :escape_whitelist
89
- self.escape_whitelist = ["text/plain"]
90
-
91
- ENCODING_TAG = Regexp.new("\\A(<%#{ENCODING_FLAG}-?%>)[ \\t]*")
92
-
93
- def self.call(template)
94
- new.call(template)
95
- end
96
-
97
- def supports_streaming?
98
- true
99
- end
100
-
101
- def handles_encoding?
102
- true
103
- end
104
-
105
- def call(template)
106
- # First, convert to BINARY, so in case the encoding is
107
- # wrong, we can still find an encoding tag
108
- # (<%# encoding %>) inside the String using a regular
109
- # expression
110
- template_source = template.source.dup.force_encoding(Encoding::ASCII_8BIT)
111
-
112
- erb = template_source.gsub(ENCODING_TAG, '')
113
- encoding = $2
114
-
115
- erb.force_encoding valid_encoding(template.source.dup, encoding)
116
-
117
- # Always make sure we return a String in the default_internal
118
- erb.encode!
119
-
120
- self.class.erb_implementation.new(
121
- erb,
122
- :escape => (self.class.escape_whitelist.include? template.type),
123
- :trim => (self.class.erb_trim_mode == "-")
124
- ).src
125
- end
126
-
127
- private
128
-
129
- def valid_encoding(string, encoding)
130
- # If a magic encoding comment was found, tag the
131
- # String with this encoding. This is for a case
132
- # where the original String was assumed to be,
133
- # for instance, UTF-8, but a magic comment
134
- # proved otherwise
135
- string.force_encoding(encoding) if encoding
136
-
137
- # If the String is valid, return the encoding we found
138
- return string.encoding if string.valid_encoding?
139
-
140
- # Otherwise, raise an exception
141
- raise WrongEncodingError.new(string, string.encoding)
142
- end
143
- end
144
- end
145
- end
146
- end
@@ -1,11 +0,0 @@
1
- module ActionView
2
- module Template::Handlers
3
- class Raw
4
- def call(template)
5
- escaped = template.source.gsub(':', '\:')
6
-
7
- '%q:' + escaped + ':;'
8
- end
9
- end
10
- end
11
- end
@@ -1,53 +0,0 @@
1
- module ActionView #:nodoc:
2
- # = Action View Template Handlers
3
- class Template
4
- module Handlers #:nodoc:
5
- autoload :ERB, 'action_view/template/handlers/erb'
6
- autoload :Builder, 'action_view/template/handlers/builder'
7
- autoload :Raw, 'action_view/template/handlers/raw'
8
-
9
- def self.extended(base)
10
- base.register_default_template_handler :erb, ERB.new
11
- base.register_template_handler :builder, Builder.new
12
- base.register_template_handler :raw, Raw.new
13
- base.register_template_handler :ruby, :source.to_proc
14
- end
15
-
16
- @@template_handlers = {}
17
- @@default_template_handlers = nil
18
-
19
- def self.extensions
20
- @@template_extensions ||= @@template_handlers.keys
21
- end
22
-
23
- # Register an object that knows how to handle template files with the given
24
- # extensions. This can be used to implement new template types.
25
- # The handler must respond to `:call`, which will be passed the template
26
- # and should return the rendered template as a String.
27
- def register_template_handler(*extensions, handler)
28
- raise(ArgumentError, "Extension is required") if extensions.empty?
29
- extensions.each do |extension|
30
- @@template_handlers[extension.to_sym] = handler
31
- end
32
- @@template_extensions = nil
33
- end
34
-
35
- def template_handler_extensions
36
- @@template_handlers.keys.map {|key| key.to_s }.sort
37
- end
38
-
39
- def registered_template_handler(extension)
40
- extension && @@template_handlers[extension.to_sym]
41
- end
42
-
43
- def register_default_template_handler(extension, klass)
44
- register_template_handler(extension, klass)
45
- @@default_template_handlers = klass
46
- end
47
-
48
- def handler_for_extension(extension)
49
- registered_template_handler(extension) || @@default_template_handlers
50
- end
51
- end
52
- end
53
- end