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,93 +0,0 @@
1
- require 'thread_safe'
2
-
3
- module ActionView
4
- class DependencyTracker
5
- @trackers = ThreadSafe::Cache.new
6
-
7
- def self.find_dependencies(name, template)
8
- tracker = @trackers[template.handler]
9
-
10
- if tracker.present?
11
- tracker.call(name, template)
12
- else
13
- []
14
- end
15
- end
16
-
17
- def self.register_tracker(extension, tracker)
18
- handler = Template.handler_for_extension(extension)
19
- @trackers[handler] = tracker
20
- end
21
-
22
- def self.remove_tracker(handler)
23
- @trackers.delete(handler)
24
- end
25
-
26
- class ERBTracker
27
- EXPLICIT_DEPENDENCY = /# Template Dependency: (\S+)/
28
-
29
- # Matches:
30
- # render partial: "comments/comment", collection: commentable.comments
31
- # render "comments/comments"
32
- # render 'comments/comments'
33
- # render('comments/comments')
34
- #
35
- # render(@topic) => render("topics/topic")
36
- # render(topics) => render("topics/topic")
37
- # render(message.topics) => render("topics/topic")
38
- RENDER_DEPENDENCY = /
39
- render\s* # render, followed by optional whitespace
40
- \(? # start an optional parenthesis for the render call
41
- (partial:|:partial\s+=>)?\s* # naming the partial, used with collection -- 1st capture
42
- ([@a-z"'][@\w\/\."']+) # the template name itself -- 2nd capture
43
- /x
44
-
45
- def self.call(name, template)
46
- new(name, template).dependencies
47
- end
48
-
49
- def initialize(name, template)
50
- @name, @template = name, template
51
- end
52
-
53
- def dependencies
54
- render_dependencies + explicit_dependencies
55
- end
56
-
57
- attr_reader :name, :template
58
- private :name, :template
59
-
60
- private
61
-
62
- def source
63
- template.source
64
- end
65
-
66
- def directory
67
- name.split("/")[0..-2].join("/")
68
- end
69
-
70
- def render_dependencies
71
- source.scan(RENDER_DEPENDENCY).
72
- collect(&:second).uniq.
73
-
74
- # render(@topic) => render("topics/topic")
75
- # render(topics) => render("topics/topic")
76
- # render(message.topics) => render("topics/topic")
77
- collect { |name| name.sub(/\A@?([a-z_]+\.)*([a-z_]+)\z/) { "#{$2.pluralize}/#{$2.singularize}" } }.
78
-
79
- # render("headline") => render("message/headline")
80
- collect { |name| name.include?("/") ? name : "#{directory}/#{name}" }.
81
-
82
- # replace quotes from string renders
83
- collect { |name| name.gsub(/["']/, "") }
84
- end
85
-
86
- def explicit_dependencies
87
- source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
88
- end
89
- end
90
-
91
- register_tracker :erb, ERBTracker
92
- end
93
- end
@@ -1,113 +0,0 @@
1
- require 'thread_safe'
2
- require 'action_view/dependency_tracker'
3
- require 'monitor'
4
-
5
- module ActionView
6
- class Digestor
7
- cattr_reader(:cache)
8
- @@cache = ThreadSafe::Cache.new
9
- @@digest_monitor = Monitor.new
10
-
11
- class << self
12
- def digest(name, format, finder, options = {})
13
- cache_key = ([name, format] + Array.wrap(options[:dependencies])).join('.')
14
- # this is a correctly done double-checked locking idiom
15
- # (ThreadSafe::Cache's lookups have volatile semantics)
16
- @@cache[cache_key] || @@digest_monitor.synchronize do
17
- @@cache.fetch(cache_key) do # re-check under lock
18
- compute_and_store_digest(cache_key, name, format, finder, options)
19
- end
20
- end
21
- end
22
-
23
- private
24
- def compute_and_store_digest(cache_key, name, format, finder, options) # called under @@digest_monitor lock
25
- klass = if options[:partial] || name.include?("/_")
26
- # Prevent re-entry or else recursive templates will blow the stack.
27
- # There is no need to worry about other threads seeing the +false+ value,
28
- # as they will then have to wait for this thread to let go of the @@digest_monitor lock.
29
- pre_stored = @@cache.put_if_absent(cache_key, false).nil? # put_if_absent returns nil on insertion
30
- PartialDigestor
31
- else
32
- Digestor
33
- end
34
-
35
- digest = klass.new(name, format, finder, options).digest
36
- # Store the actual digest if config.cache_template_loading is true
37
- @@cache[cache_key] = stored_digest = digest if ActionView::Resolver.caching?
38
- digest
39
- ensure
40
- # something went wrong or ActionView::Resolver.caching? is false, make sure not to corrupt the @@cache
41
- @@cache.delete_pair(cache_key, false) if pre_stored && !stored_digest
42
- end
43
- end
44
-
45
- attr_reader :name, :format, :finder, :options
46
-
47
- def initialize(name, format, finder, options={})
48
- @name, @format, @finder, @options = name, format, finder, options
49
- end
50
-
51
- def digest
52
- Digest::MD5.hexdigest("#{source}-#{dependency_digest}").tap do |digest|
53
- logger.try :info, "Cache digest for #{name}.#{format}: #{digest}"
54
- end
55
- rescue ActionView::MissingTemplate
56
- logger.try :error, "Couldn't find template for digesting: #{name}.#{format}"
57
- ''
58
- end
59
-
60
- def dependencies
61
- DependencyTracker.find_dependencies(name, template)
62
- rescue ActionView::MissingTemplate
63
- [] # File doesn't exist, so no dependencies
64
- end
65
-
66
- def nested_dependencies
67
- dependencies.collect do |dependency|
68
- dependencies = PartialDigestor.new(dependency, format, finder).nested_dependencies
69
- dependencies.any? ? { dependency => dependencies } : dependency
70
- end
71
- end
72
-
73
- private
74
-
75
- def logger
76
- ActionView::Base.logger
77
- end
78
-
79
- def logical_name
80
- name.gsub(%r|/_|, "/")
81
- end
82
-
83
- def partial?
84
- false
85
- end
86
-
87
- def template
88
- @template ||= finder.find(logical_name, [], partial?, formats: [ format ])
89
- end
90
-
91
- def source
92
- template.source
93
- end
94
-
95
- def dependency_digest
96
- template_digests = dependencies.collect do |template_name|
97
- Digestor.digest(template_name, format, finder, partial: true)
98
- end
99
-
100
- (template_digests + injected_dependencies).join("-")
101
- end
102
-
103
- def injected_dependencies
104
- Array.wrap(options[:dependencies])
105
- end
106
- end
107
-
108
- class PartialDigestor < Digestor # :nodoc:
109
- def partial?
110
- true
111
- end
112
- end
113
- end
@@ -1,76 +0,0 @@
1
- require 'active_support/core_ext/string/output_safety'
2
-
3
- module ActionView
4
- class OutputFlow #:nodoc:
5
- attr_reader :content
6
-
7
- def initialize
8
- @content = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new }
9
- end
10
-
11
- # Called by _layout_for to read stored values.
12
- def get(key)
13
- @content[key]
14
- end
15
-
16
- # Called by each renderer object to set the layout contents.
17
- def set(key, value)
18
- @content[key] = value
19
- end
20
-
21
- # Called by content_for
22
- def append(key, value)
23
- @content[key] << value
24
- end
25
- alias_method :append!, :append
26
-
27
- end
28
-
29
- class StreamingFlow < OutputFlow #:nodoc:
30
- def initialize(view, fiber)
31
- @view = view
32
- @parent = nil
33
- @child = view.output_buffer
34
- @content = view.view_flow.content
35
- @fiber = fiber
36
- @root = Fiber.current.object_id
37
- end
38
-
39
- # Try to get an stored content. If the content
40
- # is not available and we are inside the layout
41
- # fiber, we set that we are waiting for the given
42
- # key and yield.
43
- def get(key)
44
- return super if @content.key?(key)
45
-
46
- if inside_fiber?
47
- view = @view
48
-
49
- begin
50
- @waiting_for = key
51
- view.output_buffer, @parent = @child, view.output_buffer
52
- Fiber.yield
53
- ensure
54
- @waiting_for = nil
55
- view.output_buffer, @child = @parent, view.output_buffer
56
- end
57
- end
58
-
59
- super
60
- end
61
-
62
- # Appends the contents for the given key. This is called
63
- # by provides and resumes back to the fiber if it is
64
- # the key it is waiting for.
65
- def append!(key, value)
66
- super
67
- @fiber.resume if @waiting_for == key
68
- end
69
-
70
- private
71
-
72
- def inside_fiber?
73
- Fiber.current.object_id != @root
74
- end
75
- end
76
- end
@@ -1,49 +0,0 @@
1
- require 'active_support/core_ext/class/attribute_accessors'
2
- require 'active_support/core_ext/enumerable'
3
-
4
- module ActionView
5
- # = Active Model Helpers
6
- module Helpers
7
- module ActiveModelHelper
8
- end
9
-
10
- module ActiveModelInstanceTag
11
- def object
12
- @active_model_object ||= begin
13
- object = super
14
- object.respond_to?(:to_model) ? object.to_model : object
15
- end
16
- end
17
-
18
- def content_tag(*)
19
- error_wrapping(super)
20
- end
21
-
22
- def tag(type, options, *)
23
- tag_generate_errors?(options) ? error_wrapping(super) : super
24
- end
25
-
26
- def error_wrapping(html_tag)
27
- if object_has_errors?
28
- Base.field_error_proc.call(html_tag, self)
29
- else
30
- html_tag
31
- end
32
- end
33
-
34
- def error_message
35
- object.errors[@method_name]
36
- end
37
-
38
- private
39
-
40
- def object_has_errors?
41
- object.respond_to?(:errors) && object.errors.respond_to?(:[]) && error_message.present?
42
- end
43
-
44
- def tag_generate_errors?(options)
45
- options['type'] != 'hidden'
46
- end
47
- end
48
- end
49
- end
@@ -1,320 +0,0 @@
1
- require 'active_support/core_ext/array/extract_options'
2
- require 'active_support/core_ext/hash/keys'
3
- require 'action_view/helpers/asset_url_helper'
4
- require 'action_view/helpers/tag_helper'
5
-
6
- module ActionView
7
- # = Action View Asset Tag Helpers
8
- module Helpers #:nodoc:
9
- # This module provides methods for generating HTML that links views to assets such
10
- # as images, javascripts, stylesheets, and feeds. These methods do not verify
11
- # the assets exist before linking to them:
12
- #
13
- # image_tag("rails.png")
14
- # # => <img alt="Rails" src="/assets/rails.png" />
15
- # stylesheet_link_tag("application")
16
- # # => <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" />
17
- module AssetTagHelper
18
- extend ActiveSupport::Concern
19
-
20
- include AssetUrlHelper
21
- include TagHelper
22
-
23
- # Returns an HTML script tag for each of the +sources+ provided.
24
- #
25
- # Sources may be paths to JavaScript files. Relative paths are assumed to be relative
26
- # to <tt>assets/javascripts</tt>, full paths are assumed to be relative to the document
27
- # root. Relative paths are idiomatic, use absolute paths only when needed.
28
- #
29
- # When passing paths, the ".js" extension is optional.
30
- #
31
- # You can modify the HTML attributes of the script tag by passing a hash as the
32
- # last argument.
33
- #
34
- # When the Asset Pipeline is enabled, you can pass the name of your manifest as
35
- # source, and include other JavaScript or CoffeeScript files inside the manifest.
36
- #
37
- # javascript_include_tag "xmlhr"
38
- # # => <script src="/assets/xmlhr.js?1284139606"></script>
39
- #
40
- # javascript_include_tag "xmlhr.js"
41
- # # => <script src="/assets/xmlhr.js?1284139606"></script>
42
- #
43
- # javascript_include_tag "common.javascript", "/elsewhere/cools"
44
- # # => <script src="/assets/common.javascript?1284139606"></script>
45
- # # <script src="/elsewhere/cools.js?1423139606"></script>
46
- #
47
- # javascript_include_tag "http://www.example.com/xmlhr"
48
- # # => <script src="http://www.example.com/xmlhr"></script>
49
- #
50
- # javascript_include_tag "http://www.example.com/xmlhr.js"
51
- # # => <script src="http://www.example.com/xmlhr.js"></script>
52
- def javascript_include_tag(*sources)
53
- options = sources.extract_options!.stringify_keys
54
- path_options = options.extract!('protocol').symbolize_keys
55
-
56
- sources.uniq.map { |source|
57
- tag_options = {
58
- "src" => path_to_javascript(source, path_options)
59
- }.merge!(options)
60
- content_tag(:script, "", tag_options)
61
- }.join("\n").html_safe
62
- end
63
-
64
- # Returns a stylesheet link tag for the sources specified as arguments. If
65
- # you don't specify an extension, <tt>.css</tt> will be appended automatically.
66
- # You can modify the link attributes by passing a hash as the last argument.
67
- # For historical reasons, the 'media' attribute will always be present and defaults
68
- # to "screen", so you must explicitly set it to "all" for the stylesheet(s) to
69
- # apply to all media types.
70
- #
71
- # stylesheet_link_tag "style"
72
- # # => <link href="/assets/style.css" media="screen" rel="stylesheet" />
73
- #
74
- # stylesheet_link_tag "style.css"
75
- # # => <link href="/assets/style.css" media="screen" rel="stylesheet" />
76
- #
77
- # stylesheet_link_tag "http://www.example.com/style.css"
78
- # # => <link href="http://www.example.com/style.css" media="screen" rel="stylesheet" />
79
- #
80
- # stylesheet_link_tag "style", media: "all"
81
- # # => <link href="/assets/style.css" media="all" rel="stylesheet" />
82
- #
83
- # stylesheet_link_tag "style", media: "print"
84
- # # => <link href="/assets/style.css" media="print" rel="stylesheet" />
85
- #
86
- # stylesheet_link_tag "random.styles", "/css/stylish"
87
- # # => <link href="/assets/random.styles" media="screen" rel="stylesheet" />
88
- # # <link href="/css/stylish.css" media="screen" rel="stylesheet" />
89
- def stylesheet_link_tag(*sources)
90
- options = sources.extract_options!.stringify_keys
91
- path_options = options.extract!('protocol').symbolize_keys
92
-
93
- sources.uniq.map { |source|
94
- tag_options = {
95
- "rel" => "stylesheet",
96
- "media" => "screen",
97
- "href" => path_to_stylesheet(source, path_options)
98
- }.merge!(options)
99
- tag(:link, tag_options)
100
- }.join("\n").html_safe
101
- end
102
-
103
- # Returns a link tag that browsers and news readers can use to auto-detect
104
- # an RSS or Atom feed. The +type+ can either be <tt>:rss</tt> (default) or
105
- # <tt>:atom</tt>. Control the link options in url_for format using the
106
- # +url_options+. You can modify the LINK tag itself in +tag_options+.
107
- #
108
- # ==== Options
109
- #
110
- # * <tt>:rel</tt> - Specify the relation of this link, defaults to "alternate"
111
- # * <tt>:type</tt> - Override the auto-generated mime type
112
- # * <tt>:title</tt> - Specify the title of the link, defaults to the +type+
113
- #
114
- # ==== Examples
115
- #
116
- # auto_discovery_link_tag
117
- # # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/action" />
118
- # auto_discovery_link_tag(:atom)
119
- # # => <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.currenthost.com/controller/action" />
120
- # auto_discovery_link_tag(:rss, {action: "feed"})
121
- # # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/controller/feed" />
122
- # auto_discovery_link_tag(:rss, {action: "feed"}, {title: "My RSS"})
123
- # # => <link rel="alternate" type="application/rss+xml" title="My RSS" href="http://www.currenthost.com/controller/feed" />
124
- # auto_discovery_link_tag(:rss, {controller: "news", action: "feed"})
125
- # # => <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.currenthost.com/news/feed" />
126
- # auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "Example RSS"})
127
- # # => <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed" />
128
- def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
129
- if !(type == :rss || type == :atom) && tag_options[:type].blank?
130
- message = "You have passed type other than :rss or :atom to auto_discovery_link_tag and haven't supplied " +
131
- "the :type option key. This behavior is deprecated and will be remove in Rails 4.1. You should pass " +
132
- ":type option explicitly if you want to use other types, for example: " +
133
- "auto_discovery_link_tag(:xml, '/feed.xml', :type => 'application/xml')"
134
- ActiveSupport::Deprecation.warn message
135
- end
136
-
137
- tag(
138
- "link",
139
- "rel" => tag_options[:rel] || "alternate",
140
- "type" => tag_options[:type] || Mime::Type.lookup_by_extension(type.to_s).to_s,
141
- "title" => tag_options[:title] || type.to_s.upcase,
142
- "href" => url_options.is_a?(Hash) ? url_for(url_options.merge(:only_path => false)) : url_options
143
- )
144
- end
145
-
146
- # Returns a link loading a favicon file. You may specify a different file
147
- # in the first argument. The helper accepts an additional options hash where
148
- # you can override "rel" and "type".
149
- #
150
- # ==== Options
151
- #
152
- # * <tt>:rel</tt> - Specify the relation of this link, defaults to 'shortcut icon'
153
- # * <tt>:type</tt> - Override the auto-generated mime type, defaults to 'image/vnd.microsoft.icon'
154
- #
155
- # ==== Examples
156
- #
157
- # favicon_link_tag '/myicon.ico'
158
- # # => <link href="/assets/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
159
- #
160
- # Mobile Safari looks for a different <link> tag, pointing to an image that
161
- # will be used if you add the page to the home screen of an iPod Touch, iPhone, or iPad.
162
- # The following call would generate such a tag:
163
- #
164
- # favicon_link_tag '/mb-icon.png', rel: 'apple-touch-icon', type: 'image/png'
165
- # # => <link href="/assets/mb-icon.png" rel="apple-touch-icon" type="image/png" />
166
- def favicon_link_tag(source='favicon.ico', options={})
167
- tag('link', {
168
- :rel => 'shortcut icon',
169
- :type => 'image/vnd.microsoft.icon',
170
- :href => path_to_image(source)
171
- }.merge!(options.symbolize_keys))
172
- end
173
-
174
- # Returns an HTML image tag for the +source+. The +source+ can be a full
175
- # path or a file.
176
- #
177
- # ==== Options
178
- #
179
- # You can add HTML attributes using the +options+. The +options+ supports
180
- # three additional keys for convenience and conformance:
181
- #
182
- # * <tt>:alt</tt> - If no alt text is given, the file name part of the
183
- # +source+ is used (capitalized and without the extension)
184
- # * <tt>:size</tt> - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes
185
- # width="30" and height="45", and "50" becomes width="50" and height="50".
186
- # <tt>:size</tt> will be ignored if the value is not in the correct format.
187
- #
188
- # ==== Examples
189
- #
190
- # image_tag("icon")
191
- # # => <img alt="Icon" src="/assets/icon" />
192
- # image_tag("icon.png")
193
- # # => <img alt="Icon" src="/assets/icon.png" />
194
- # image_tag("icon.png", size: "16x10", alt: "Edit Entry")
195
- # # => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />
196
- # image_tag("/icons/icon.gif", size: "16")
197
- # # => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
198
- # image_tag("/icons/icon.gif", height: '32', width: '32')
199
- # # => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
200
- # image_tag("/icons/icon.gif", class: "menu_icon")
201
- # # => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
202
- def image_tag(source, options={})
203
- options = options.symbolize_keys
204
-
205
- src = options[:src] = path_to_image(source)
206
-
207
- unless src =~ /^(?:cid|data):/ || src.blank?
208
- options[:alt] = options.fetch(:alt){ image_alt(src) }
209
- end
210
-
211
- if size = options.delete(:size)
212
- options[:width], options[:height] = size.split("x") if size =~ %r{\A\d+x\d+\z}
213
- options[:width] = options[:height] = size if size =~ %r{\A\d+\z}
214
- end
215
-
216
- tag("img", options)
217
- end
218
-
219
- # Returns a string suitable for an html image tag alt attribute.
220
- # The +src+ argument is meant to be an image file path.
221
- # The method removes the basename of the file path and the digest,
222
- # if any. It also removes hyphens and underscores from file names and
223
- # replaces them with spaces, returning a space-separated, titleized
224
- # string.
225
- #
226
- # ==== Examples
227
- #
228
- # image_tag('rails.png')
229
- # # => <img alt="Rails" src="/assets/rails.png" />
230
- #
231
- # image_tag('hyphenated-file-name.png')
232
- # # => <img alt="Hyphenated file name" src="/assets/hyphenated-file-name.png" />
233
- #
234
- # image_tag('underscored_file_name.png')
235
- # # => <img alt="Underscored file name" src="/assets/underscored_file_name.png" />
236
- def image_alt(src)
237
- File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').tr('-_', ' ').capitalize
238
- end
239
-
240
- # Returns an html video tag for the +sources+. If +sources+ is a string,
241
- # a single video tag will be returned. If +sources+ is an array, a video
242
- # tag with nested source tags for each source will be returned. The
243
- # +sources+ can be full paths or files that exists in your public videos
244
- # directory.
245
- #
246
- # ==== Options
247
- # You can add HTML attributes using the +options+. The +options+ supports
248
- # two additional keys for convenience and conformance:
249
- #
250
- # * <tt>:poster</tt> - Set an image (like a screenshot) to be shown
251
- # before the video loads. The path is calculated like the +src+ of +image_tag+.
252
- # * <tt>:size</tt> - Supplied as "{Width}x{Height}", so "30x45" becomes
253
- # width="30" and height="45". <tt>:size</tt> will be ignored if the
254
- # value is not in the correct format.
255
- #
256
- # ==== Examples
257
- #
258
- # video_tag("trailer")
259
- # # => <video src="/videos/trailer" />
260
- # video_tag("trailer.ogg")
261
- # # => <video src="/videos/trailer.ogg" />
262
- # video_tag("trailer.ogg", controls: true, autobuffer: true)
263
- # # => <video autobuffer="autobuffer" controls="controls" src="/videos/trailer.ogg" />
264
- # video_tag("trailer.m4v", size: "16x10", poster: "screenshot.png")
265
- # # => <video src="/videos/trailer.m4v" width="16" height="10" poster="/assets/screenshot.png" />
266
- # video_tag("/trailers/hd.avi", size: "16x16")
267
- # # => <video src="/trailers/hd.avi" width="16" height="16" />
268
- # video_tag("/trailers/hd.avi", height: '32', width: '32')
269
- # # => <video height="32" src="/trailers/hd.avi" width="32" />
270
- # video_tag("trailer.ogg", "trailer.flv")
271
- # # => <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
272
- # video_tag(["trailer.ogg", "trailer.flv"])
273
- # # => <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
274
- # video_tag(["trailer.ogg", "trailer.flv"], size: "160x120")
275
- # # => <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
276
- def video_tag(*sources)
277
- multiple_sources_tag('video', sources) do |options|
278
- options[:poster] = path_to_image(options[:poster]) if options[:poster]
279
-
280
- if size = options.delete(:size)
281
- options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
282
- end
283
- end
284
- end
285
-
286
- # Returns an HTML audio tag for the +source+.
287
- # The +source+ can be full path or file that exists in
288
- # your public audios directory.
289
- #
290
- # audio_tag("sound")
291
- # # => <audio src="/audios/sound" />
292
- # audio_tag("sound.wav")
293
- # # => <audio src="/audios/sound.wav" />
294
- # audio_tag("sound.wav", autoplay: true, controls: true)
295
- # # => <audio autoplay="autoplay" controls="controls" src="/audios/sound.wav" />
296
- # audio_tag("sound.wav", "sound.mid")
297
- # # => <audio><source src="/audios/sound.wav" /><source src="/audios/sound.mid" /></audio>
298
- def audio_tag(*sources)
299
- multiple_sources_tag('audio', sources)
300
- end
301
-
302
- private
303
- def multiple_sources_tag(type, sources)
304
- options = sources.extract_options!.symbolize_keys
305
- sources.flatten!
306
-
307
- yield options if block_given?
308
-
309
- if sources.size > 1
310
- content_tag(type, options) do
311
- safe_join sources.map { |source| tag("source", :src => send("path_to_#{type}", source)) }
312
- end
313
- else
314
- options[:src] = send("path_to_#{type}", sources.first)
315
- content_tag(type, nil, options)
316
- end
317
- end
318
- end
319
- end
320
- end