actionpack 4.0.1 → 4.2.11.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +402 -1173
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -7
- data/lib/abstract_controller/base.rb +39 -7
- data/lib/abstract_controller/callbacks.rb +32 -53
- data/lib/abstract_controller/collector.rb +11 -1
- data/lib/abstract_controller/helpers.rb +26 -16
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
- data/lib/abstract_controller/rendering.rb +57 -127
- data/lib/abstract_controller/url_for.rb +1 -1
- data/lib/abstract_controller.rb +1 -2
- data/lib/action_controller/base.rb +19 -10
- data/lib/action_controller/caching/fragments.rb +7 -1
- data/lib/action_controller/caching.rb +2 -12
- data/lib/action_controller/log_subscriber.rb +29 -20
- data/lib/action_controller/metal/conditional_get.rb +37 -12
- data/lib/action_controller/metal/data_streaming.rb +1 -1
- data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
- data/lib/action_controller/metal/exceptions.rb +1 -1
- data/lib/action_controller/metal/flash.rb +17 -0
- data/lib/action_controller/metal/force_ssl.rb +2 -2
- data/lib/action_controller/metal/head.rb +8 -6
- data/lib/action_controller/metal/helpers.rb +6 -2
- data/lib/action_controller/metal/http_authentication.rb +45 -23
- data/lib/action_controller/metal/instrumentation.rb +9 -6
- data/lib/action_controller/metal/live.rb +173 -20
- data/lib/action_controller/metal/mime_responds.rb +127 -232
- data/lib/action_controller/metal/params_wrapper.rb +16 -9
- data/lib/action_controller/metal/rack_delegation.rb +1 -1
- data/lib/action_controller/metal/redirecting.rb +34 -26
- data/lib/action_controller/metal/renderers.rb +39 -12
- data/lib/action_controller/metal/rendering.rb +41 -14
- data/lib/action_controller/metal/request_forgery_protection.rb +147 -19
- data/lib/action_controller/metal/streaming.rb +19 -21
- data/lib/action_controller/metal/strong_parameters.rb +166 -22
- data/lib/action_controller/metal/testing.rb +0 -1
- data/lib/action_controller/metal/url_for.rb +11 -12
- data/lib/action_controller/metal.rb +14 -8
- data/lib/action_controller/model_naming.rb +1 -1
- data/lib/action_controller/railtie.rb +5 -1
- data/lib/action_controller/test_case.rb +160 -94
- data/lib/action_controller.rb +2 -18
- data/lib/action_dispatch/http/cache.rb +5 -4
- data/lib/action_dispatch/http/filter_parameters.rb +2 -2
- data/lib/action_dispatch/http/filter_redirect.rb +5 -4
- data/lib/action_dispatch/http/headers.rb +46 -10
- data/lib/action_dispatch/http/mime_negotiation.rb +31 -4
- data/lib/action_dispatch/http/mime_type.rb +25 -26
- data/lib/action_dispatch/http/mime_types.rb +1 -0
- data/lib/action_dispatch/http/parameter_filter.rb +1 -1
- data/lib/action_dispatch/http/parameters.rb +25 -41
- data/lib/action_dispatch/http/request.rb +49 -32
- data/lib/action_dispatch/http/response.rb +127 -25
- data/lib/action_dispatch/http/upload.rb +9 -21
- data/lib/action_dispatch/http/url.rb +97 -70
- data/lib/action_dispatch/journey/formatter.rb +35 -19
- data/lib/action_dispatch/journey/gtg/builder.rb +3 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +10 -7
- data/lib/action_dispatch/journey/gtg/transition_table.rb +23 -33
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
- data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -5
- data/lib/action_dispatch/journey/nodes/node.rb +4 -0
- data/lib/action_dispatch/journey/parser.rb +51 -59
- data/lib/action_dispatch/journey/parser.y +12 -10
- data/lib/action_dispatch/journey/path/pattern.rb +16 -19
- data/lib/action_dispatch/journey/route.rb +8 -19
- data/lib/action_dispatch/journey/router/strexp.rb +9 -6
- data/lib/action_dispatch/journey/router/utils.rb +54 -18
- data/lib/action_dispatch/journey/router.rb +53 -75
- data/lib/action_dispatch/journey/routes.rb +4 -0
- data/lib/action_dispatch/journey/scanner.rb +5 -5
- data/lib/action_dispatch/journey/visitors.rb +81 -60
- data/lib/action_dispatch/journey/visualizer/fsm.css +0 -4
- data/lib/action_dispatch/journey/visualizer/index.html.erb +2 -2
- data/lib/action_dispatch/middleware/callbacks.rb +7 -7
- data/lib/action_dispatch/middleware/cookies.rb +119 -43
- data/lib/action_dispatch/middleware/debug_exceptions.rb +32 -13
- data/lib/action_dispatch/middleware/exception_wrapper.rb +60 -20
- data/lib/action_dispatch/middleware/flash.rb +37 -24
- data/lib/action_dispatch/middleware/params_parser.rb +2 -2
- data/lib/action_dispatch/middleware/public_exceptions.rb +12 -3
- data/lib/action_dispatch/middleware/reloader.rb +11 -2
- data/lib/action_dispatch/middleware/remote_ip.rb +40 -54
- data/lib/action_dispatch/middleware/request_id.rb +1 -1
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +8 -7
- data/lib/action_dispatch/middleware/show_exceptions.rb +6 -2
- data/lib/action_dispatch/middleware/ssl.rb +10 -7
- data/lib/action_dispatch/middleware/static.rb +79 -23
- data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +21 -19
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/{diagnostics.erb → diagnostics.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +3 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +120 -64
- data/lib/action_dispatch/railtie.rb +5 -2
- data/lib/action_dispatch/request/session.rb +12 -0
- data/lib/action_dispatch/request/utils.rb +35 -0
- data/lib/action_dispatch/routing/endpoint.rb +10 -0
- data/lib/action_dispatch/routing/inspector.rb +11 -17
- data/lib/action_dispatch/routing/mapper.rb +519 -312
- data/lib/action_dispatch/routing/polymorphic_routes.rb +204 -79
- data/lib/action_dispatch/routing/redirection.rb +51 -26
- data/lib/action_dispatch/routing/route_set.rb +331 -206
- data/lib/action_dispatch/routing/routes_proxy.rb +5 -4
- data/lib/action_dispatch/routing/url_for.rb +19 -5
- data/lib/action_dispatch/routing.rb +9 -6
- data/lib/action_dispatch/testing/assertions/dom.rb +2 -26
- data/lib/action_dispatch/testing/assertions/response.rb +9 -15
- data/lib/action_dispatch/testing/assertions/routing.rb +22 -22
- data/lib/action_dispatch/testing/assertions/selector.rb +2 -429
- data/lib/action_dispatch/testing/assertions/tag.rb +2 -134
- data/lib/action_dispatch/testing/assertions.rb +11 -7
- data/lib/action_dispatch/testing/integration.rb +31 -29
- data/lib/action_dispatch/testing/test_request.rb +1 -1
- data/lib/action_dispatch/testing/test_response.rb +1 -5
- data/lib/action_dispatch.rb +5 -8
- data/lib/action_pack/gem_version.rb +15 -0
- data/lib/action_pack/version.rb +4 -7
- data/lib/action_pack.rb +1 -1
- metadata +77 -159
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/deprecated/integration_test.rb +0 -5
- data/lib/action_controller/deprecated.rb +0 -7
- data/lib/action_controller/metal/responder.rb +0 -287
- data/lib/action_controller/record_identifier.rb +0 -31
- data/lib/action_controller/vendor/html-scanner.rb +0 -5
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -24
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -7
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -43
- data/lib/action_view/base.rb +0 -201
- data/lib/action_view/buffers.rb +0 -49
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/dependency_tracker.rb +0 -93
- data/lib/action_view/digestor.rb +0 -113
- data/lib/action_view/flows.rb +0 -76
- data/lib/action_view/helpers/active_model_helper.rb +0 -49
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
- data/lib/action_view/helpers/asset_url_helper.rb +0 -355
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
- data/lib/action_view/helpers/cache_helper.rb +0 -196
- data/lib/action_view/helpers/capture_helper.rb +0 -216
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -30
- data/lib/action_view/helpers/date_helper.rb +0 -1083
- data/lib/action_view/helpers/debug_helper.rb +0 -39
- data/lib/action_view/helpers/form_helper.rb +0 -1880
- data/lib/action_view/helpers/form_options_helper.rb +0 -838
- data/lib/action_view/helpers/form_tag_helper.rb +0 -785
- data/lib/action_view/helpers/javascript_helper.rb +0 -117
- data/lib/action_view/helpers/number_helper.rb +0 -441
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -106
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -256
- data/lib/action_view/helpers/tag_helper.rb +0 -173
- data/lib/action_view/helpers/tags/base.rb +0 -148
- data/lib/action_view/helpers/tags/check_box.rb +0 -64
- data/lib/action_view/helpers/tags/checkable.rb +0 -16
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -44
- data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
- data/lib/action_view/helpers/tags/collection_select.rb +0 -28
- data/lib/action_view/helpers/tags/color_field.rb +0 -25
- data/lib/action_view/helpers/tags/date_field.rb +0 -13
- data/lib/action_view/helpers/tags/date_select.rb +0 -72
- data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
- data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
- data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
- data/lib/action_view/helpers/tags/email_field.rb +0 -8
- data/lib/action_view/helpers/tags/file_field.rb +0 -8
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
- data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
- data/lib/action_view/helpers/tags/label.rb +0 -66
- data/lib/action_view/helpers/tags/month_field.rb +0 -13
- data/lib/action_view/helpers/tags/number_field.rb +0 -18
- data/lib/action_view/helpers/tags/password_field.rb +0 -12
- data/lib/action_view/helpers/tags/radio_button.rb +0 -31
- data/lib/action_view/helpers/tags/range_field.rb +0 -8
- data/lib/action_view/helpers/tags/search_field.rb +0 -24
- data/lib/action_view/helpers/tags/select.rb +0 -40
- data/lib/action_view/helpers/tags/tel_field.rb +0 -8
- data/lib/action_view/helpers/tags/text_area.rb +0 -18
- data/lib/action_view/helpers/tags/text_field.rb +0 -29
- data/lib/action_view/helpers/tags/time_field.rb +0 -13
- data/lib/action_view/helpers/tags/time_select.rb +0 -8
- data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
- data/lib/action_view/helpers/tags/url_field.rb +0 -8
- data/lib/action_view/helpers/tags/week_field.rb +0 -13
- data/lib/action_view/helpers/tags.rb +0 -39
- data/lib/action_view/helpers/text_helper.rb +0 -443
- data/lib/action_view/helpers/translation_helper.rb +0 -107
- data/lib/action_view/helpers/url_helper.rb +0 -635
- data/lib/action_view/helpers.rb +0 -58
- data/lib/action_view/locale/en.yml +0 -56
- data/lib/action_view/log_subscriber.rb +0 -30
- data/lib/action_view/lookup_context.rb +0 -241
- data/lib/action_view/model_naming.rb +0 -12
- data/lib/action_view/path_set.rb +0 -77
- data/lib/action_view/railtie.rb +0 -43
- data/lib/action_view/record_identifier.rb +0 -84
- data/lib/action_view/renderer/abstract_renderer.rb +0 -47
- data/lib/action_view/renderer/partial_renderer.rb +0 -492
- data/lib/action_view/renderer/renderer.rb +0 -50
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
- data/lib/action_view/renderer/template_renderer.rb +0 -96
- data/lib/action_view/routing_url_for.rb +0 -107
- data/lib/action_view/tasks/dependencies.rake +0 -17
- data/lib/action_view/template/error.rb +0 -138
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -146
- data/lib/action_view/template/handlers/raw.rb +0 -11
- data/lib/action_view/template/handlers.rb +0 -53
- data/lib/action_view/template/resolver.rb +0 -326
- data/lib/action_view/template/text.rb +0 -34
- data/lib/action_view/template/types.rb +0 -57
- data/lib/action_view/template.rb +0 -339
- data/lib/action_view/test_case.rb +0 -270
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
- data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_view/vendor/html-scanner.rb +0 -20
- data/lib/action_view.rb +0 -93
@@ -1,355 +0,0 @@
|
|
1
|
-
require 'zlib'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
# = Action View Asset URL Helpers
|
5
|
-
module Helpers
|
6
|
-
# This module provides methods for generating asset paths and
|
7
|
-
# urls.
|
8
|
-
#
|
9
|
-
# image_path("rails.png")
|
10
|
-
# # => "/assets/rails.png"
|
11
|
-
#
|
12
|
-
# image_url("rails.png")
|
13
|
-
# # => "http://www.example.com/assets/rails.png"
|
14
|
-
#
|
15
|
-
# === Using asset hosts
|
16
|
-
#
|
17
|
-
# By default, Rails links to these assets on the current host in the public
|
18
|
-
# folder, but you can direct Rails to link to assets from a dedicated asset
|
19
|
-
# server by setting <tt>ActionController::Base.asset_host</tt> in the application
|
20
|
-
# configuration, typically in <tt>config/environments/production.rb</tt>.
|
21
|
-
# For example, you'd define <tt>assets.example.com</tt> to be your asset
|
22
|
-
# host this way, inside the <tt>configure</tt> block of your environment-specific
|
23
|
-
# configuration files or <tt>config/application.rb</tt>:
|
24
|
-
#
|
25
|
-
# config.action_controller.asset_host = "assets.example.com"
|
26
|
-
#
|
27
|
-
# Helpers take that into account:
|
28
|
-
#
|
29
|
-
# image_tag("rails.png")
|
30
|
-
# # => <img alt="Rails" src="http://assets.example.com/assets/rails.png" />
|
31
|
-
# stylesheet_link_tag("application")
|
32
|
-
# # => <link href="http://assets.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
33
|
-
#
|
34
|
-
# Browsers typically open at most two simultaneous connections to a single
|
35
|
-
# host, which means your assets often have to wait for other assets to finish
|
36
|
-
# downloading. You can alleviate this by using a <tt>%d</tt> wildcard in the
|
37
|
-
# +asset_host+. For example, "assets%d.example.com". If that wildcard is
|
38
|
-
# present Rails distributes asset requests among the corresponding four hosts
|
39
|
-
# "assets0.example.com", ..., "assets3.example.com". With this trick browsers
|
40
|
-
# will open eight simultaneous connections rather than two.
|
41
|
-
#
|
42
|
-
# image_tag("rails.png")
|
43
|
-
# # => <img alt="Rails" src="http://assets0.example.com/assets/rails.png" />
|
44
|
-
# stylesheet_link_tag("application")
|
45
|
-
# # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
46
|
-
#
|
47
|
-
# To do this, you can either setup four actual hosts, or you can use wildcard
|
48
|
-
# DNS to CNAME the wildcard to a single asset host. You can read more about
|
49
|
-
# setting up your DNS CNAME records from your ISP.
|
50
|
-
#
|
51
|
-
# Note: This is purely a browser performance optimization and is not meant
|
52
|
-
# for server load balancing. See http://www.die.net/musings/page_load_time/
|
53
|
-
# for background.
|
54
|
-
#
|
55
|
-
# Alternatively, you can exert more control over the asset host by setting
|
56
|
-
# +asset_host+ to a proc like this:
|
57
|
-
#
|
58
|
-
# ActionController::Base.asset_host = Proc.new { |source|
|
59
|
-
# "http://assets#{Digest::MD5.hexdigest(source).to_i(16) % 2 + 1}.example.com"
|
60
|
-
# }
|
61
|
-
# image_tag("rails.png")
|
62
|
-
# # => <img alt="Rails" src="http://assets1.example.com/assets/rails.png" />
|
63
|
-
# stylesheet_link_tag("application")
|
64
|
-
# # => <link href="http://assets2.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
65
|
-
#
|
66
|
-
# The example above generates "http://assets1.example.com" and
|
67
|
-
# "http://assets2.example.com". This option is useful for example if
|
68
|
-
# you need fewer/more than four hosts, custom host names, etc.
|
69
|
-
#
|
70
|
-
# As you see the proc takes a +source+ parameter. That's a string with the
|
71
|
-
# absolute path of the asset, for example "/assets/rails.png".
|
72
|
-
#
|
73
|
-
# ActionController::Base.asset_host = Proc.new { |source|
|
74
|
-
# if source.ends_with?('.css')
|
75
|
-
# "http://stylesheets.example.com"
|
76
|
-
# else
|
77
|
-
# "http://assets.example.com"
|
78
|
-
# end
|
79
|
-
# }
|
80
|
-
# image_tag("rails.png")
|
81
|
-
# # => <img alt="Rails" src="http://assets.example.com/assets/rails.png" />
|
82
|
-
# stylesheet_link_tag("application")
|
83
|
-
# # => <link href="http://stylesheets.example.com/assets/application.css" media="screen" rel="stylesheet" />
|
84
|
-
#
|
85
|
-
# Alternatively you may ask for a second parameter +request+. That one is
|
86
|
-
# particularly useful for serving assets from an SSL-protected page. The
|
87
|
-
# example proc below disables asset hosting for HTTPS connections, while
|
88
|
-
# still sending assets for plain HTTP requests from asset hosts. If you don't
|
89
|
-
# have SSL certificates for each of the asset hosts this technique allows you
|
90
|
-
# to avoid warnings in the client about mixed media.
|
91
|
-
#
|
92
|
-
# config.action_controller.asset_host = Proc.new { |source, request|
|
93
|
-
# if request.ssl?
|
94
|
-
# "#{request.protocol}#{request.host_with_port}"
|
95
|
-
# else
|
96
|
-
# "#{request.protocol}assets.example.com"
|
97
|
-
# end
|
98
|
-
# }
|
99
|
-
#
|
100
|
-
# You can also implement a custom asset host object that responds to +call+
|
101
|
-
# and takes either one or two parameters just like the proc.
|
102
|
-
#
|
103
|
-
# config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
|
104
|
-
# "http://asset%d.example.com", "https://asset1.example.com"
|
105
|
-
# )
|
106
|
-
#
|
107
|
-
module AssetUrlHelper
|
108
|
-
URI_REGEXP = %r{^[-a-z]+://|^(?:cid|data):|^//}i
|
109
|
-
|
110
|
-
# Computes the path to asset in public directory. If :type
|
111
|
-
# options is set, a file extension will be appended and scoped
|
112
|
-
# to the corresponding public directory.
|
113
|
-
#
|
114
|
-
# All other asset *_path helpers delegate through this method.
|
115
|
-
#
|
116
|
-
# asset_path "application.js" # => /application.js
|
117
|
-
# asset_path "application", type: :javascript # => /javascripts/application.js
|
118
|
-
# asset_path "application", type: :stylesheet # => /stylesheets/application.css
|
119
|
-
# asset_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
|
120
|
-
def asset_path(source, options = {})
|
121
|
-
source = source.to_s
|
122
|
-
return "" unless source.present?
|
123
|
-
return source if source =~ URI_REGEXP
|
124
|
-
|
125
|
-
tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '')
|
126
|
-
|
127
|
-
if extname = compute_asset_extname(source, options)
|
128
|
-
source = "#{source}#{extname}"
|
129
|
-
end
|
130
|
-
|
131
|
-
if source[0] != ?/
|
132
|
-
source = compute_asset_path(source, options)
|
133
|
-
end
|
134
|
-
|
135
|
-
relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
|
136
|
-
if relative_url_root
|
137
|
-
source = "#{relative_url_root}#{source}" unless source.starts_with?("#{relative_url_root}/")
|
138
|
-
end
|
139
|
-
|
140
|
-
if host = compute_asset_host(source, options)
|
141
|
-
source = "#{host}#{source}"
|
142
|
-
end
|
143
|
-
|
144
|
-
"#{source}#{tail}"
|
145
|
-
end
|
146
|
-
alias_method :path_to_asset, :asset_path # aliased to avoid conflicts with a asset_path named route
|
147
|
-
|
148
|
-
# Computes the full URL to a asset in the public directory. This
|
149
|
-
# will use +asset_path+ internally, so most of their behaviors
|
150
|
-
# will be the same.
|
151
|
-
def asset_url(source, options = {})
|
152
|
-
path_to_asset(source, options.merge(:protocol => :request))
|
153
|
-
end
|
154
|
-
alias_method :url_to_asset, :asset_url # aliased to avoid conflicts with an asset_url named route
|
155
|
-
|
156
|
-
ASSET_EXTENSIONS = {
|
157
|
-
javascript: '.js',
|
158
|
-
stylesheet: '.css'
|
159
|
-
}
|
160
|
-
|
161
|
-
# Compute extname to append to asset path. Returns nil if
|
162
|
-
# nothing should be added.
|
163
|
-
def compute_asset_extname(source, options = {})
|
164
|
-
return if options[:extname] == false
|
165
|
-
extname = options[:extname] || ASSET_EXTENSIONS[options[:type]]
|
166
|
-
extname if extname && File.extname(source) != extname
|
167
|
-
end
|
168
|
-
|
169
|
-
# Maps asset types to public directory.
|
170
|
-
ASSET_PUBLIC_DIRECTORIES = {
|
171
|
-
audio: '/audios',
|
172
|
-
font: '/fonts',
|
173
|
-
image: '/images',
|
174
|
-
javascript: '/javascripts',
|
175
|
-
stylesheet: '/stylesheets',
|
176
|
-
video: '/videos'
|
177
|
-
}
|
178
|
-
|
179
|
-
# Computes asset path to public directory. Plugins and
|
180
|
-
# extensions can override this method to point to custom assets
|
181
|
-
# or generate digested paths or query strings.
|
182
|
-
def compute_asset_path(source, options = {})
|
183
|
-
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
|
184
|
-
File.join(dir, source)
|
185
|
-
end
|
186
|
-
|
187
|
-
# Pick an asset host for this source. Returns +nil+ if no host is set,
|
188
|
-
# the host if no wildcard is set, the host interpolated with the
|
189
|
-
# numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
|
190
|
-
# or the value returned from invoking call on an object responding to call
|
191
|
-
# (proc or otherwise).
|
192
|
-
def compute_asset_host(source = "", options = {})
|
193
|
-
request = self.request if respond_to?(:request)
|
194
|
-
host = config.asset_host if defined? config.asset_host
|
195
|
-
host ||= request.base_url if request && options[:protocol] == :request
|
196
|
-
|
197
|
-
if host.respond_to?(:call)
|
198
|
-
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
|
199
|
-
args = [source]
|
200
|
-
args << request if request && (arity > 1 || arity < 0)
|
201
|
-
host = host.call(*args)
|
202
|
-
elsif host =~ /%d/
|
203
|
-
host = host % (Zlib.crc32(source) % 4)
|
204
|
-
end
|
205
|
-
|
206
|
-
return unless host
|
207
|
-
|
208
|
-
if host =~ URI_REGEXP
|
209
|
-
host
|
210
|
-
else
|
211
|
-
protocol = options[:protocol] || config.default_asset_host_protocol || (request ? :request : :relative)
|
212
|
-
case protocol
|
213
|
-
when :relative
|
214
|
-
"//#{host}"
|
215
|
-
when :request
|
216
|
-
"#{request.protocol}#{host}"
|
217
|
-
else
|
218
|
-
"#{protocol}://#{host}"
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
# Computes the path to a javascript asset in the public javascripts directory.
|
224
|
-
# If the +source+ filename has no extension, .js will be appended (except for explicit URIs)
|
225
|
-
# Full paths from the document root will be passed through.
|
226
|
-
# Used internally by javascript_include_tag to build the script path.
|
227
|
-
#
|
228
|
-
# javascript_path "xmlhr" # => /javascripts/xmlhr.js
|
229
|
-
# javascript_path "dir/xmlhr.js" # => /javascripts/dir/xmlhr.js
|
230
|
-
# javascript_path "/dir/xmlhr" # => /dir/xmlhr.js
|
231
|
-
# javascript_path "http://www.example.com/js/xmlhr" # => http://www.example.com/js/xmlhr
|
232
|
-
# javascript_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js
|
233
|
-
def javascript_path(source, options = {})
|
234
|
-
path_to_asset(source, {type: :javascript}.merge!(options))
|
235
|
-
end
|
236
|
-
alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with a javascript_path named route
|
237
|
-
|
238
|
-
# Computes the full URL to a javascript asset in the public javascripts directory.
|
239
|
-
# This will use +javascript_path+ internally, so most of their behaviors will be the same.
|
240
|
-
def javascript_url(source, options = {})
|
241
|
-
url_to_asset(source, {type: :javascript}.merge!(options))
|
242
|
-
end
|
243
|
-
alias_method :url_to_javascript, :javascript_url # aliased to avoid conflicts with a javascript_url named route
|
244
|
-
|
245
|
-
# Computes the path to a stylesheet asset in the public stylesheets directory.
|
246
|
-
# If the +source+ filename has no extension, <tt>.css</tt> will be appended (except for explicit URIs).
|
247
|
-
# Full paths from the document root will be passed through.
|
248
|
-
# Used internally by +stylesheet_link_tag+ to build the stylesheet path.
|
249
|
-
#
|
250
|
-
# stylesheet_path "style" # => /stylesheets/style.css
|
251
|
-
# stylesheet_path "dir/style.css" # => /stylesheets/dir/style.css
|
252
|
-
# stylesheet_path "/dir/style.css" # => /dir/style.css
|
253
|
-
# stylesheet_path "http://www.example.com/css/style" # => http://www.example.com/css/style
|
254
|
-
# stylesheet_path "http://www.example.com/css/style.css" # => http://www.example.com/css/style.css
|
255
|
-
def stylesheet_path(source, options = {})
|
256
|
-
path_to_asset(source, {type: :stylesheet}.merge!(options))
|
257
|
-
end
|
258
|
-
alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with a stylesheet_path named route
|
259
|
-
|
260
|
-
# Computes the full URL to a stylesheet asset in the public stylesheets directory.
|
261
|
-
# This will use +stylesheet_path+ internally, so most of their behaviors will be the same.
|
262
|
-
def stylesheet_url(source, options = {})
|
263
|
-
url_to_asset(source, {type: :stylesheet}.merge!(options))
|
264
|
-
end
|
265
|
-
alias_method :url_to_stylesheet, :stylesheet_url # aliased to avoid conflicts with a stylesheet_url named route
|
266
|
-
|
267
|
-
# Computes the path to an image asset.
|
268
|
-
# Full paths from the document root will be passed through.
|
269
|
-
# Used internally by +image_tag+ to build the image path:
|
270
|
-
#
|
271
|
-
# image_path("edit") # => "/assets/edit"
|
272
|
-
# image_path("edit.png") # => "/assets/edit.png"
|
273
|
-
# image_path("icons/edit.png") # => "/assets/icons/edit.png"
|
274
|
-
# image_path("/icons/edit.png") # => "/icons/edit.png"
|
275
|
-
# image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"
|
276
|
-
#
|
277
|
-
# If you have images as application resources this method may conflict with their named routes.
|
278
|
-
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
|
279
|
-
# plugin authors are encouraged to do so.
|
280
|
-
def image_path(source, options = {})
|
281
|
-
path_to_asset(source, {type: :image}.merge!(options))
|
282
|
-
end
|
283
|
-
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
|
284
|
-
|
285
|
-
# Computes the full URL to an image asset.
|
286
|
-
# This will use +image_path+ internally, so most of their behaviors will be the same.
|
287
|
-
def image_url(source, options = {})
|
288
|
-
url_to_asset(source, {type: :image}.merge!(options))
|
289
|
-
end
|
290
|
-
alias_method :url_to_image, :image_url # aliased to avoid conflicts with an image_url named route
|
291
|
-
|
292
|
-
# Computes the path to a video asset in the public videos directory.
|
293
|
-
# Full paths from the document root will be passed through.
|
294
|
-
# Used internally by +video_tag+ to build the video path.
|
295
|
-
#
|
296
|
-
# video_path("hd") # => /videos/hd
|
297
|
-
# video_path("hd.avi") # => /videos/hd.avi
|
298
|
-
# video_path("trailers/hd.avi") # => /videos/trailers/hd.avi
|
299
|
-
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
|
300
|
-
# video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
|
301
|
-
def video_path(source, options = {})
|
302
|
-
path_to_asset(source, {type: :video}.merge!(options))
|
303
|
-
end
|
304
|
-
alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
|
305
|
-
|
306
|
-
# Computes the full URL to a video asset in the public videos directory.
|
307
|
-
# This will use +video_path+ internally, so most of their behaviors will be the same.
|
308
|
-
def video_url(source, options = {})
|
309
|
-
url_to_asset(source, {type: :video}.merge!(options))
|
310
|
-
end
|
311
|
-
alias_method :url_to_video, :video_url # aliased to avoid conflicts with an video_url named route
|
312
|
-
|
313
|
-
# Computes the path to an audio asset in the public audios directory.
|
314
|
-
# Full paths from the document root will be passed through.
|
315
|
-
# Used internally by +audio_tag+ to build the audio path.
|
316
|
-
#
|
317
|
-
# audio_path("horse") # => /audios/horse
|
318
|
-
# audio_path("horse.wav") # => /audios/horse.wav
|
319
|
-
# audio_path("sounds/horse.wav") # => /audios/sounds/horse.wav
|
320
|
-
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
|
321
|
-
# audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
|
322
|
-
def audio_path(source, options = {})
|
323
|
-
path_to_asset(source, {type: :audio}.merge!(options))
|
324
|
-
end
|
325
|
-
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
|
326
|
-
|
327
|
-
# Computes the full URL to an audio asset in the public audios directory.
|
328
|
-
# This will use +audio_path+ internally, so most of their behaviors will be the same.
|
329
|
-
def audio_url(source, options = {})
|
330
|
-
url_to_asset(source, {type: :audio}.merge!(options))
|
331
|
-
end
|
332
|
-
alias_method :url_to_audio, :audio_url # aliased to avoid conflicts with an audio_url named route
|
333
|
-
|
334
|
-
# Computes the path to a font asset.
|
335
|
-
# Full paths from the document root will be passed through.
|
336
|
-
#
|
337
|
-
# font_path("font") # => /assets/font
|
338
|
-
# font_path("font.ttf") # => /assets/font.ttf
|
339
|
-
# font_path("dir/font.ttf") # => /assets/dir/font.ttf
|
340
|
-
# font_path("/dir/font.ttf") # => /dir/font.ttf
|
341
|
-
# font_path("http://www.example.com/dir/font.ttf") # => http://www.example.com/dir/font.ttf
|
342
|
-
def font_path(source, options = {})
|
343
|
-
path_to_asset(source, {type: :font}.merge!(options))
|
344
|
-
end
|
345
|
-
alias_method :path_to_font, :font_path # aliased to avoid conflicts with an font_path named route
|
346
|
-
|
347
|
-
# Computes the full URL to a font asset.
|
348
|
-
# This will use +font_path+ internally, so most of their behaviors will be the same.
|
349
|
-
def font_url(source, options = {})
|
350
|
-
url_to_asset(source, {type: :font}.merge!(options))
|
351
|
-
end
|
352
|
-
alias_method :url_to_font, :font_url # aliased to avoid conflicts with an font_url named route
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|
@@ -1,203 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
# = Action View Atom Feed Helpers
|
5
|
-
module Helpers
|
6
|
-
module AtomFeedHelper
|
7
|
-
# Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ERB or any other
|
8
|
-
# template languages).
|
9
|
-
#
|
10
|
-
# Full usage example:
|
11
|
-
#
|
12
|
-
# config/routes.rb:
|
13
|
-
# Basecamp::Application.routes.draw do
|
14
|
-
# resources :posts
|
15
|
-
# root to: "posts#index"
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# app/controllers/posts_controller.rb:
|
19
|
-
# class PostsController < ApplicationController::Base
|
20
|
-
# # GET /posts.html
|
21
|
-
# # GET /posts.atom
|
22
|
-
# def index
|
23
|
-
# @posts = Post.all
|
24
|
-
#
|
25
|
-
# respond_to do |format|
|
26
|
-
# format.html
|
27
|
-
# format.atom
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# app/views/posts/index.atom.builder:
|
33
|
-
# atom_feed do |feed|
|
34
|
-
# feed.title("My great blog!")
|
35
|
-
# feed.updated(@posts[0].created_at) if @posts.length > 0
|
36
|
-
#
|
37
|
-
# @posts.each do |post|
|
38
|
-
# feed.entry(post) do |entry|
|
39
|
-
# entry.title(post.title)
|
40
|
-
# entry.content(post.body, type: 'html')
|
41
|
-
#
|
42
|
-
# entry.author do |author|
|
43
|
-
# author.name("DHH")
|
44
|
-
# end
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# The options for atom_feed are:
|
50
|
-
#
|
51
|
-
# * <tt>:language</tt>: Defaults to "en-US".
|
52
|
-
# * <tt>:root_url</tt>: The HTML alternative that this feed is doubling for. Defaults to / on the current host.
|
53
|
-
# * <tt>:url</tt>: The URL for this feed. Defaults to the current URL.
|
54
|
-
# * <tt>:id</tt>: The id for this feed. Defaults to "tag:#{request.host},#{options[:schema_date]}:#{request.fullpath.split(".")[0]}"
|
55
|
-
# * <tt>:schema_date</tt>: The date at which the tag scheme for the feed was first used. A good default is the year you
|
56
|
-
# created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. If not specified,
|
57
|
-
# 2005 is used (as an "I don't care" value).
|
58
|
-
# * <tt>:instruct</tt>: Hash of XML processing instructions in the form {target => {attribute => value, }} or {target => [{attribute => value, }, ]}
|
59
|
-
#
|
60
|
-
# Other namespaces can be added to the root element:
|
61
|
-
#
|
62
|
-
# app/views/posts/index.atom.builder:
|
63
|
-
# atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
|
64
|
-
# 'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
|
65
|
-
# feed.title("My great blog!")
|
66
|
-
# feed.updated((@posts.first.created_at))
|
67
|
-
# feed.tag!(openSearch:totalResults, 10)
|
68
|
-
#
|
69
|
-
# @posts.each do |post|
|
70
|
-
# feed.entry(post) do |entry|
|
71
|
-
# entry.title(post.title)
|
72
|
-
# entry.content(post.body, type: 'html')
|
73
|
-
# entry.tag!('app:edited', Time.now)
|
74
|
-
#
|
75
|
-
# entry.author do |author|
|
76
|
-
# author.name("DHH")
|
77
|
-
# end
|
78
|
-
# end
|
79
|
-
# end
|
80
|
-
# end
|
81
|
-
#
|
82
|
-
# The Atom spec defines five elements (content rights title subtitle
|
83
|
-
# summary) which may directly contain xhtml content if type: 'xhtml'
|
84
|
-
# is specified as an attribute. If so, this helper will take care of
|
85
|
-
# the enclosing div and xhtml namespace declaration. Example usage:
|
86
|
-
#
|
87
|
-
# entry.summary type: 'xhtml' do |xhtml|
|
88
|
-
# xhtml.p pluralize(order.line_items.count, "line item")
|
89
|
-
# xhtml.p "Shipped to #{order.address}"
|
90
|
-
# xhtml.p "Paid by #{order.pay_type}"
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
#
|
94
|
-
# <tt>atom_feed</tt> yields an +AtomFeedBuilder+ instance. Nested elements yield
|
95
|
-
# an +AtomBuilder+ instance.
|
96
|
-
def atom_feed(options = {}, &block)
|
97
|
-
if options[:schema_date]
|
98
|
-
options[:schema_date] = options[:schema_date].strftime("%Y-%m-%d") if options[:schema_date].respond_to?(:strftime)
|
99
|
-
else
|
100
|
-
options[:schema_date] = "2005" # The Atom spec copyright date
|
101
|
-
end
|
102
|
-
|
103
|
-
xml = options.delete(:xml) || eval("xml", block.binding)
|
104
|
-
xml.instruct!
|
105
|
-
if options[:instruct]
|
106
|
-
options[:instruct].each do |target,attrs|
|
107
|
-
if attrs.respond_to?(:keys)
|
108
|
-
xml.instruct!(target, attrs)
|
109
|
-
elsif attrs.respond_to?(:each)
|
110
|
-
attrs.each { |attr_group| xml.instruct!(target, attr_group) }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom'}
|
116
|
-
feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)}
|
117
|
-
|
118
|
-
xml.feed(feed_opts) do
|
119
|
-
xml.id(options[:id] || "tag:#{request.host},#{options[:schema_date]}:#{request.fullpath.split(".")[0]}")
|
120
|
-
xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:root_url] || (request.protocol + request.host_with_port))
|
121
|
-
xml.link(:rel => 'self', :type => 'application/atom+xml', :href => options[:url] || request.url)
|
122
|
-
|
123
|
-
yield AtomFeedBuilder.new(xml, self, options)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
class AtomBuilder #:nodoc:
|
128
|
-
XHTML_TAG_NAMES = %w(content rights title subtitle summary).to_set
|
129
|
-
|
130
|
-
def initialize(xml)
|
131
|
-
@xml = xml
|
132
|
-
end
|
133
|
-
|
134
|
-
private
|
135
|
-
# Delegate to xml builder, first wrapping the element in a xhtml
|
136
|
-
# namespaced div element if the method and arguments indicate
|
137
|
-
# that an xhtml_block? is desired.
|
138
|
-
def method_missing(method, *arguments, &block)
|
139
|
-
if xhtml_block?(method, arguments)
|
140
|
-
@xml.__send__(method, *arguments) do
|
141
|
-
@xml.div(:xmlns => 'http://www.w3.org/1999/xhtml') do |xhtml|
|
142
|
-
block.call(xhtml)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
else
|
146
|
-
@xml.__send__(method, *arguments, &block)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
# True if the method name matches one of the five elements defined
|
151
|
-
# in the Atom spec as potentially containing XHTML content and
|
152
|
-
# if type: 'xhtml' is, in fact, specified.
|
153
|
-
def xhtml_block?(method, arguments)
|
154
|
-
if XHTML_TAG_NAMES.include?(method.to_s)
|
155
|
-
last = arguments.last
|
156
|
-
last.is_a?(Hash) && last[:type].to_s == 'xhtml'
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
class AtomFeedBuilder < AtomBuilder #:nodoc:
|
162
|
-
def initialize(xml, view, feed_options = {})
|
163
|
-
@xml, @view, @feed_options = xml, view, feed_options
|
164
|
-
end
|
165
|
-
|
166
|
-
# Accepts a Date or Time object and inserts it in the proper format. If nil is passed, current time in UTC is used.
|
167
|
-
def updated(date_or_time = nil)
|
168
|
-
@xml.updated((date_or_time || Time.now.utc).xmlschema)
|
169
|
-
end
|
170
|
-
|
171
|
-
# Creates an entry tag for a specific record and prefills the id using class and id.
|
172
|
-
#
|
173
|
-
# Options:
|
174
|
-
#
|
175
|
-
# * <tt>:published</tt>: Time first published. Defaults to the created_at attribute on the record if one such exists.
|
176
|
-
# * <tt>:updated</tt>: Time of update. Defaults to the updated_at attribute on the record if one such exists.
|
177
|
-
# * <tt>:url</tt>: The URL for this entry. Defaults to the polymorphic_url for the record.
|
178
|
-
# * <tt>:id</tt>: The ID for this entry. Defaults to "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}"
|
179
|
-
# * <tt>:type</tt>: The TYPE for this entry. Defaults to "text/html".
|
180
|
-
def entry(record, options = {})
|
181
|
-
@xml.entry do
|
182
|
-
@xml.id(options[:id] || "tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}")
|
183
|
-
|
184
|
-
if options[:published] || (record.respond_to?(:created_at) && record.created_at)
|
185
|
-
@xml.published((options[:published] || record.created_at).xmlschema)
|
186
|
-
end
|
187
|
-
|
188
|
-
if options[:updated] || (record.respond_to?(:updated_at) && record.updated_at)
|
189
|
-
@xml.updated((options[:updated] || record.updated_at).xmlschema)
|
190
|
-
end
|
191
|
-
|
192
|
-
type = options.fetch(:type, 'text/html')
|
193
|
-
|
194
|
-
@xml.link(:rel => 'alternate', :type => type, :href => options[:url] || @view.polymorphic_url(record))
|
195
|
-
|
196
|
-
yield AtomBuilder.new(@xml)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|