actionpack 3.2.19 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +850 -401
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -288
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +39 -37
- data/lib/abstract_controller/callbacks.rb +101 -82
- data/lib/abstract_controller/collector.rb +7 -3
- data/lib/abstract_controller/helpers.rb +25 -13
- data/lib/abstract_controller/layouts.rb +74 -74
- data/lib/abstract_controller/logger.rb +1 -2
- data/lib/abstract_controller/rendering.rb +30 -13
- data/lib/abstract_controller/translation.rb +16 -1
- data/lib/abstract_controller/url_for.rb +6 -6
- data/lib/abstract_controller/view_paths.rb +1 -1
- data/lib/abstract_controller.rb +1 -8
- data/lib/action_controller/base.rb +46 -22
- data/lib/action_controller/caching/fragments.rb +23 -53
- data/lib/action_controller/caching.rb +46 -33
- data/lib/action_controller/deprecated/integration_test.rb +3 -0
- data/lib/action_controller/deprecated.rb +5 -1
- data/lib/action_controller/log_subscriber.rb +16 -8
- data/lib/action_controller/metal/conditional_get.rb +76 -32
- data/lib/action_controller/metal/data_streaming.rb +20 -26
- data/lib/action_controller/metal/exceptions.rb +19 -6
- data/lib/action_controller/metal/flash.rb +24 -9
- data/lib/action_controller/metal/force_ssl.rb +70 -12
- data/lib/action_controller/metal/head.rb +25 -4
- data/lib/action_controller/metal/helpers.rb +5 -9
- data/lib/action_controller/metal/hide_actions.rb +0 -1
- data/lib/action_controller/metal/http_authentication.rb +107 -83
- data/lib/action_controller/metal/implicit_render.rb +1 -1
- data/lib/action_controller/metal/instrumentation.rb +2 -1
- data/lib/action_controller/metal/live.rb +175 -0
- data/lib/action_controller/metal/mime_responds.rb +161 -47
- data/lib/action_controller/metal/params_wrapper.rb +112 -74
- data/lib/action_controller/metal/rack_delegation.rb +9 -3
- data/lib/action_controller/metal/redirecting.rb +15 -20
- data/lib/action_controller/metal/renderers.rb +11 -9
- data/lib/action_controller/metal/rendering.rb +9 -1
- data/lib/action_controller/metal/request_forgery_protection.rb +112 -19
- data/lib/action_controller/metal/responder.rb +20 -19
- data/lib/action_controller/metal/streaming.rb +12 -18
- data/lib/action_controller/metal/strong_parameters.rb +520 -0
- data/lib/action_controller/metal/testing.rb +13 -18
- data/lib/action_controller/metal/url_for.rb +28 -25
- data/lib/action_controller/metal.rb +17 -32
- data/lib/action_controller/model_naming.rb +12 -0
- data/lib/action_controller/railtie.rb +33 -17
- data/lib/action_controller/railties/helpers.rb +22 -0
- data/lib/action_controller/record_identifier.rb +18 -72
- data/lib/action_controller/test_case.rb +251 -131
- data/lib/action_controller/vendor/html-scanner.rb +4 -19
- data/lib/action_controller.rb +15 -6
- data/lib/action_dispatch/http/cache.rb +63 -11
- data/lib/action_dispatch/http/filter_parameters.rb +18 -8
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +49 -17
- data/lib/action_dispatch/http/mime_negotiation.rb +24 -1
- data/lib/action_dispatch/http/mime_type.rb +154 -100
- data/lib/action_dispatch/http/mime_types.rb +1 -1
- data/lib/action_dispatch/http/parameter_filter.rb +44 -46
- data/lib/action_dispatch/http/parameters.rb +28 -28
- data/lib/action_dispatch/http/rack_cache.rb +2 -3
- data/lib/action_dispatch/http/request.rb +64 -18
- data/lib/action_dispatch/http/response.rb +130 -35
- data/lib/action_dispatch/http/upload.rb +63 -20
- data/lib/action_dispatch/http/url.rb +98 -35
- data/lib/action_dispatch/journey/backwards.rb +5 -0
- data/lib/action_dispatch/journey/formatter.rb +146 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +44 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +156 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
- data/lib/action_dispatch/journey/nodes/node.rb +124 -0
- data/lib/action_dispatch/journey/parser.rb +206 -0
- data/lib/action_dispatch/journey/parser.y +47 -0
- data/lib/action_dispatch/journey/parser_extras.rb +23 -0
- data/lib/action_dispatch/journey/path/pattern.rb +196 -0
- data/lib/action_dispatch/journey/route.rb +124 -0
- data/lib/action_dispatch/journey/router/strexp.rb +24 -0
- data/lib/action_dispatch/journey/router/utils.rb +54 -0
- data/lib/action_dispatch/journey/router.rb +166 -0
- data/lib/action_dispatch/journey/routes.rb +75 -0
- data/lib/action_dispatch/journey/scanner.rb +61 -0
- data/lib/action_dispatch/journey/visitors.rb +197 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +34 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +5 -0
- data/lib/action_dispatch/middleware/callbacks.rb +9 -4
- data/lib/action_dispatch/middleware/cookies.rb +259 -114
- data/lib/action_dispatch/middleware/debug_exceptions.rb +26 -17
- data/lib/action_dispatch/middleware/exception_wrapper.rb +29 -3
- data/lib/action_dispatch/middleware/flash.rb +58 -58
- data/lib/action_dispatch/middleware/params_parser.rb +14 -29
- data/lib/action_dispatch/middleware/public_exceptions.rb +30 -14
- data/lib/action_dispatch/middleware/reloader.rb +6 -6
- data/lib/action_dispatch/middleware/remote_ip.rb +145 -39
- data/lib/action_dispatch/middleware/request_id.rb +2 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
- data/lib/action_dispatch/middleware/session/cookie_store.rb +82 -28
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +12 -45
- data/lib/action_dispatch/middleware/ssl.rb +70 -0
- data/lib/action_dispatch/middleware/stack.rb +6 -1
- data/lib/action_dispatch/middleware/static.rb +2 -1
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +14 -11
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +25 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +7 -9
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +15 -9
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +127 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +7 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +30 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +39 -13
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +6 -2
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +144 -0
- data/lib/action_dispatch/railtie.rb +16 -6
- data/lib/action_dispatch/request/session.rb +181 -0
- data/lib/action_dispatch/routing/inspector.rb +240 -0
- data/lib/action_dispatch/routing/mapper.rb +540 -291
- data/lib/action_dispatch/routing/polymorphic_routes.rb +16 -20
- data/lib/action_dispatch/routing/redirection.rb +46 -29
- data/lib/action_dispatch/routing/route_set.rb +207 -164
- data/lib/action_dispatch/routing/routes_proxy.rb +2 -0
- data/lib/action_dispatch/routing/url_for.rb +48 -33
- data/lib/action_dispatch/routing.rb +48 -83
- data/lib/action_dispatch/testing/assertions/dom.rb +3 -13
- data/lib/action_dispatch/testing/assertions/response.rb +32 -40
- data/lib/action_dispatch/testing/assertions/routing.rb +42 -41
- data/lib/action_dispatch/testing/assertions/selector.rb +17 -22
- data/lib/action_dispatch/testing/assertions/tag.rb +20 -23
- data/lib/action_dispatch/testing/integration.rb +65 -51
- data/lib/action_dispatch/testing/test_process.rb +9 -6
- data/lib/action_dispatch/testing/test_request.rb +7 -3
- data/lib/action_dispatch.rb +21 -15
- data/lib/action_pack/version.rb +7 -6
- data/lib/action_pack.rb +1 -1
- data/lib/action_view/base.rb +15 -34
- data/lib/action_view/buffers.rb +7 -1
- data/lib/action_view/context.rb +4 -4
- data/lib/action_view/dependency_tracker.rb +93 -0
- data/lib/action_view/digestor.rb +85 -0
- data/lib/action_view/flows.rb +1 -4
- data/lib/action_view/helpers/active_model_helper.rb +3 -4
- data/lib/action_view/helpers/asset_tag_helper.rb +215 -352
- data/lib/action_view/helpers/asset_url_helper.rb +355 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +13 -10
- data/lib/action_view/helpers/cache_helper.rb +150 -18
- data/lib/action_view/helpers/capture_helper.rb +44 -31
- data/lib/action_view/helpers/csrf_helper.rb +0 -2
- data/lib/action_view/helpers/date_helper.rb +269 -248
- data/lib/action_view/helpers/debug_helper.rb +10 -11
- data/lib/action_view/helpers/form_helper.rb +931 -537
- data/lib/action_view/helpers/form_options_helper.rb +341 -166
- data/lib/action_view/helpers/form_tag_helper.rb +190 -90
- data/lib/action_view/helpers/javascript_helper.rb +23 -16
- data/lib/action_view/helpers/number_helper.rb +148 -329
- data/lib/action_view/helpers/output_safety_helper.rb +3 -3
- data/lib/action_view/helpers/record_tag_helper.rb +17 -22
- data/lib/action_view/helpers/rendering_helper.rb +2 -2
- data/lib/action_view/helpers/sanitize_helper.rb +3 -6
- data/lib/action_view/helpers/tag_helper.rb +46 -33
- data/lib/action_view/helpers/tags/base.rb +147 -0
- data/lib/action_view/helpers/tags/check_box.rb +64 -0
- data/lib/action_view/helpers/tags/checkable.rb +16 -0
- data/lib/action_view/helpers/tags/collection_check_boxes.rb +43 -0
- data/lib/action_view/helpers/tags/collection_helpers.rb +83 -0
- data/lib/action_view/helpers/tags/collection_radio_buttons.rb +36 -0
- data/lib/action_view/helpers/tags/collection_select.rb +28 -0
- data/lib/action_view/helpers/tags/color_field.rb +25 -0
- data/lib/action_view/helpers/tags/date_field.rb +13 -0
- data/lib/action_view/helpers/tags/date_select.rb +72 -0
- data/lib/action_view/helpers/tags/datetime_field.rb +22 -0
- data/lib/action_view/helpers/tags/datetime_local_field.rb +19 -0
- data/lib/action_view/helpers/tags/datetime_select.rb +8 -0
- data/lib/action_view/helpers/tags/email_field.rb +8 -0
- data/lib/action_view/helpers/tags/file_field.rb +8 -0
- data/lib/action_view/helpers/tags/grouped_collection_select.rb +29 -0
- data/lib/action_view/helpers/tags/hidden_field.rb +8 -0
- data/lib/action_view/helpers/tags/label.rb +65 -0
- data/lib/action_view/helpers/tags/month_field.rb +13 -0
- data/lib/action_view/helpers/tags/number_field.rb +18 -0
- data/lib/action_view/helpers/tags/password_field.rb +12 -0
- data/lib/action_view/helpers/tags/radio_button.rb +31 -0
- data/lib/action_view/helpers/tags/range_field.rb +8 -0
- data/lib/action_view/helpers/tags/search_field.rb +24 -0
- data/lib/action_view/helpers/tags/select.rb +40 -0
- data/lib/action_view/helpers/tags/tel_field.rb +8 -0
- data/lib/action_view/helpers/tags/text_area.rb +18 -0
- data/lib/action_view/helpers/tags/text_field.rb +29 -0
- data/lib/action_view/helpers/tags/time_field.rb +13 -0
- data/lib/action_view/helpers/tags/time_select.rb +8 -0
- data/lib/action_view/helpers/tags/time_zone_select.rb +20 -0
- data/lib/action_view/helpers/tags/url_field.rb +8 -0
- data/lib/action_view/helpers/tags/week_field.rb +13 -0
- data/lib/action_view/helpers/tags.rb +39 -0
- data/lib/action_view/helpers/text_helper.rb +130 -114
- data/lib/action_view/helpers/translation_helper.rb +32 -16
- data/lib/action_view/helpers/url_helper.rb +211 -270
- data/lib/action_view/helpers.rb +2 -4
- data/lib/action_view/locale/en.yml +1 -105
- data/lib/action_view/log_subscriber.rb +6 -4
- data/lib/action_view/lookup_context.rb +15 -28
- data/lib/action_view/model_naming.rb +12 -0
- data/lib/action_view/path_set.rb +8 -20
- data/lib/action_view/railtie.rb +6 -22
- data/lib/action_view/record_identifier.rb +84 -0
- data/lib/action_view/renderer/abstract_renderer.rb +25 -19
- data/lib/action_view/renderer/partial_renderer.rb +158 -81
- data/lib/action_view/renderer/renderer.rb +8 -12
- data/lib/action_view/renderer/streaming_template_renderer.rb +2 -5
- data/lib/action_view/renderer/template_renderer.rb +12 -10
- data/lib/action_view/routing_url_for.rb +107 -0
- data/lib/action_view/template/error.rb +22 -12
- data/lib/action_view/template/handlers/builder.rb +1 -1
- data/lib/action_view/template/handlers/erb.rb +40 -19
- data/lib/action_view/template/handlers/raw.rb +11 -0
- data/lib/action_view/template/handlers.rb +12 -9
- data/lib/action_view/template/resolver.rb +107 -53
- data/lib/action_view/template/text.rb +12 -8
- data/lib/action_view/template/types.rb +57 -0
- data/lib/action_view/template.rb +25 -23
- data/lib/action_view/test_case.rb +67 -42
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/document.rb +0 -0
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/node.rb +12 -12
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/sanitizer.rb +13 -2
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/selector.rb +9 -9
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/{action_controller → action_view}/vendor/html-scanner/html/version.rb +0 -0
- data/lib/action_view/vendor/html-scanner.rb +20 -0
- data/lib/action_view.rb +17 -8
- metadata +184 -214
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require '
|
|
3
|
-
require 'action_view/helpers/
|
|
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
4
|
require 'action_view/helpers/tag_helper'
|
|
5
5
|
|
|
6
6
|
module ActionView
|
|
@@ -11,214 +11,129 @@ module ActionView
|
|
|
11
11
|
# the assets exist before linking to them:
|
|
12
12
|
#
|
|
13
13
|
# image_tag("rails.png")
|
|
14
|
-
# # => <img alt="Rails" src="/
|
|
14
|
+
# # => <img alt="Rails" src="/assets/rails.png" />
|
|
15
15
|
# stylesheet_link_tag("application")
|
|
16
|
-
# # => <link href="/
|
|
17
|
-
#
|
|
18
|
-
# === Using asset hosts
|
|
19
|
-
#
|
|
20
|
-
# By default, Rails links to these assets on the current host in the public
|
|
21
|
-
# folder, but you can direct Rails to link to assets from a dedicated asset
|
|
22
|
-
# server by setting ActionController::Base.asset_host in the application
|
|
23
|
-
# configuration, typically in <tt>config/environments/production.rb</tt>.
|
|
24
|
-
# For example, you'd define <tt>assets.example.com</tt> to be your asset
|
|
25
|
-
# host this way:
|
|
26
|
-
#
|
|
27
|
-
# ActionController::Base.asset_host = "assets.example.com"
|
|
28
|
-
#
|
|
29
|
-
# Helpers take that into account:
|
|
30
|
-
#
|
|
31
|
-
# image_tag("rails.png")
|
|
32
|
-
# # => <img alt="Rails" src="http://assets.example.com/images/rails.png?1230601161" />
|
|
33
|
-
# stylesheet_link_tag("application")
|
|
34
|
-
# # => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
|
|
35
|
-
#
|
|
36
|
-
# Browsers typically open at most two simultaneous connections to a single
|
|
37
|
-
# host, which means your assets often have to wait for other assets to finish
|
|
38
|
-
# downloading. You can alleviate this by using a <tt>%d</tt> wildcard in the
|
|
39
|
-
# +asset_host+. For example, "assets%d.example.com". If that wildcard is
|
|
40
|
-
# present Rails distributes asset requests among the corresponding four hosts
|
|
41
|
-
# "assets0.example.com", ..., "assets3.example.com". With this trick browsers
|
|
42
|
-
# will open eight simultaneous connections rather than two.
|
|
43
|
-
#
|
|
44
|
-
# image_tag("rails.png")
|
|
45
|
-
# # => <img alt="Rails" src="http://assets0.example.com/images/rails.png?1230601161" />
|
|
46
|
-
# stylesheet_link_tag("application")
|
|
47
|
-
# # => <link href="http://assets2.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
|
|
48
|
-
#
|
|
49
|
-
# To do this, you can either setup four actual hosts, or you can use wildcard
|
|
50
|
-
# DNS to CNAME the wildcard to a single asset host. You can read more about
|
|
51
|
-
# setting up your DNS CNAME records from your ISP.
|
|
52
|
-
#
|
|
53
|
-
# Note: This is purely a browser performance optimization and is not meant
|
|
54
|
-
# for server load balancing. See http://www.die.net/musings/page_load_time/
|
|
55
|
-
# for background.
|
|
56
|
-
#
|
|
57
|
-
# Alternatively, you can exert more control over the asset host by setting
|
|
58
|
-
# +asset_host+ to a proc like this:
|
|
59
|
-
#
|
|
60
|
-
# ActionController::Base.asset_host = Proc.new { |source|
|
|
61
|
-
# "http://assets#{Digest::MD5.hexdigest(source).to_i(16) % 2 + 1}.example.com"
|
|
62
|
-
# }
|
|
63
|
-
# image_tag("rails.png")
|
|
64
|
-
# # => <img alt="Rails" src="http://assets1.example.com/images/rails.png?1230601161" />
|
|
65
|
-
# stylesheet_link_tag("application")
|
|
66
|
-
# # => <link href="http://assets2.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
|
|
67
|
-
#
|
|
68
|
-
# The example above generates "http://assets1.example.com" and
|
|
69
|
-
# "http://assets2.example.com". This option is useful for example if
|
|
70
|
-
# you need fewer/more than four hosts, custom host names, etc.
|
|
71
|
-
#
|
|
72
|
-
# As you see the proc takes a +source+ parameter. That's a string with the
|
|
73
|
-
# absolute path of the asset with any extensions and timestamps in place,
|
|
74
|
-
# for example "/images/rails.png?1230601161".
|
|
75
|
-
#
|
|
76
|
-
# ActionController::Base.asset_host = Proc.new { |source|
|
|
77
|
-
# if source.starts_with?('/images')
|
|
78
|
-
# "http://images.example.com"
|
|
79
|
-
# else
|
|
80
|
-
# "http://assets.example.com"
|
|
81
|
-
# end
|
|
82
|
-
# }
|
|
83
|
-
# image_tag("rails.png")
|
|
84
|
-
# # => <img alt="Rails" src="http://images.example.com/images/rails.png?1230601161" />
|
|
85
|
-
# stylesheet_link_tag("application")
|
|
86
|
-
# # => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
|
|
87
|
-
#
|
|
88
|
-
# Alternatively you may ask for a second parameter +request+. That one is
|
|
89
|
-
# particularly useful for serving assets from an SSL-protected page. The
|
|
90
|
-
# example proc below disables asset hosting for HTTPS connections, while
|
|
91
|
-
# still sending assets for plain HTTP requests from asset hosts. If you don't
|
|
92
|
-
# have SSL certificates for each of the asset hosts this technique allows you
|
|
93
|
-
# to avoid warnings in the client about mixed media.
|
|
94
|
-
#
|
|
95
|
-
# ActionController::Base.asset_host = Proc.new { |source, request|
|
|
96
|
-
# if request.ssl?
|
|
97
|
-
# "#{request.protocol}#{request.host_with_port}"
|
|
98
|
-
# else
|
|
99
|
-
# "#{request.protocol}assets.example.com"
|
|
100
|
-
# end
|
|
101
|
-
# }
|
|
102
|
-
#
|
|
103
|
-
# You can also implement a custom asset host object that responds to +call+
|
|
104
|
-
# and takes either one or two parameters just like the proc.
|
|
105
|
-
#
|
|
106
|
-
# config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
|
|
107
|
-
# "http://asset%d.example.com", "https://asset1.example.com"
|
|
108
|
-
# )
|
|
109
|
-
#
|
|
110
|
-
# === Customizing the asset path
|
|
111
|
-
#
|
|
112
|
-
# By default, Rails appends asset's timestamps to all asset paths. This allows
|
|
113
|
-
# you to set a cache-expiration date for the asset far into the future, but
|
|
114
|
-
# still be able to instantly invalidate it by simply updating the file (and
|
|
115
|
-
# hence updating the timestamp, which then updates the URL as the timestamp
|
|
116
|
-
# is part of that, which in turn busts the cache).
|
|
117
|
-
#
|
|
118
|
-
# It's the responsibility of the web server you use to set the far-future
|
|
119
|
-
# expiration date on cache assets that you need to take advantage of this
|
|
120
|
-
# feature. Here's an example for Apache:
|
|
121
|
-
#
|
|
122
|
-
# # Asset Expiration
|
|
123
|
-
# ExpiresActive On
|
|
124
|
-
# <FilesMatch "\.(ico|gif|jpe?g|png|js|css)$">
|
|
125
|
-
# ExpiresDefault "access plus 1 year"
|
|
126
|
-
# </FilesMatch>
|
|
127
|
-
#
|
|
128
|
-
# Also note that in order for this to work, all your application servers must
|
|
129
|
-
# return the same timestamps. This means that they must have their clocks
|
|
130
|
-
# synchronized. If one of them drifts out of sync, you'll see different
|
|
131
|
-
# timestamps at random and the cache won't work. In that case the browser
|
|
132
|
-
# will request the same assets over and over again even thought they didn't
|
|
133
|
-
# change. You can use something like Live HTTP Headers for Firefox to verify
|
|
134
|
-
# that the cache is indeed working.
|
|
135
|
-
#
|
|
136
|
-
# This strategy works well enough for most server setups and requires the
|
|
137
|
-
# least configuration, but if you deploy several application servers at
|
|
138
|
-
# different times - say to handle a temporary spike in load - then the
|
|
139
|
-
# asset time stamps will be out of sync. In a setup like this you may want
|
|
140
|
-
# to set the way that asset paths are generated yourself.
|
|
141
|
-
#
|
|
142
|
-
# Altering the asset paths that Rails generates can be done in two ways.
|
|
143
|
-
# The easiest is to define the RAILS_ASSET_ID environment variable. The
|
|
144
|
-
# contents of this variable will always be used in preference to
|
|
145
|
-
# calculated timestamps. A more complex but flexible way is to set
|
|
146
|
-
# <tt>ActionController::Base.config.asset_path</tt> to a proc
|
|
147
|
-
# that takes the unmodified asset path and returns the path needed for
|
|
148
|
-
# your asset caching to work. Typically you'd do something like this in
|
|
149
|
-
# <tt>config/environments/production.rb</tt>:
|
|
150
|
-
#
|
|
151
|
-
# # Normally you'd calculate RELEASE_NUMBER at startup.
|
|
152
|
-
# RELEASE_NUMBER = 12345
|
|
153
|
-
# config.action_controller.asset_path = proc { |asset_path|
|
|
154
|
-
# "/release-#{RELEASE_NUMBER}#{asset_path}"
|
|
155
|
-
# }
|
|
156
|
-
#
|
|
157
|
-
# This example would cause the following behavior on all servers no
|
|
158
|
-
# matter when they were deployed:
|
|
159
|
-
#
|
|
160
|
-
# image_tag("rails.png")
|
|
161
|
-
# # => <img alt="Rails" src="/release-12345/images/rails.png" />
|
|
162
|
-
# stylesheet_link_tag("application")
|
|
163
|
-
# # => <link href="/release-12345/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" />
|
|
164
|
-
#
|
|
165
|
-
# Changing the asset_path does require that your web servers have
|
|
166
|
-
# knowledge of the asset template paths that you rewrite to so it's not
|
|
167
|
-
# suitable for out-of-the-box use. To use the example given above you
|
|
168
|
-
# could use something like this in your Apache VirtualHost configuration:
|
|
169
|
-
#
|
|
170
|
-
# <LocationMatch "^/release-\d+/(images|javascripts|stylesheets)/.*$">
|
|
171
|
-
# # Some browsers still send conditional-GET requests if there's a
|
|
172
|
-
# # Last-Modified header or an ETag header even if they haven't
|
|
173
|
-
# # reached the expiry date sent in the Expires header.
|
|
174
|
-
# Header unset Last-Modified
|
|
175
|
-
# Header unset ETag
|
|
176
|
-
# FileETag None
|
|
177
|
-
#
|
|
178
|
-
# # Assets requested using a cache-busting filename should be served
|
|
179
|
-
# # only once and then cached for a really long time. The HTTP/1.1
|
|
180
|
-
# # spec frowns on hugely-long expiration times though and suggests
|
|
181
|
-
# # that assets which never expire be served with an expiration date
|
|
182
|
-
# # 1 year from access.
|
|
183
|
-
# ExpiresActive On
|
|
184
|
-
# ExpiresDefault "access plus 1 year"
|
|
185
|
-
# </LocationMatch>
|
|
186
|
-
#
|
|
187
|
-
# # We use cached-busting location names with the far-future expires
|
|
188
|
-
# # headers to ensure that if a file does change it can force a new
|
|
189
|
-
# # request. The actual asset filenames are still the same though so we
|
|
190
|
-
# # need to rewrite the location from the cache-busting location to the
|
|
191
|
-
# # real asset location so that we can serve it.
|
|
192
|
-
# RewriteEngine On
|
|
193
|
-
# RewriteRule ^/release-\d+/(images|javascripts|stylesheets)/(.*)$ /$1/$2 [L]
|
|
16
|
+
# # => <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" />
|
|
194
17
|
module AssetTagHelper
|
|
18
|
+
extend ActiveSupport::Concern
|
|
19
|
+
|
|
20
|
+
include AssetUrlHelper
|
|
195
21
|
include TagHelper
|
|
196
|
-
|
|
197
|
-
|
|
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
|
+
|
|
198
103
|
# Returns a link tag that browsers and news readers can use to auto-detect
|
|
199
|
-
# an RSS or
|
|
104
|
+
# an RSS or Atom feed. The +type+ can either be <tt>:rss</tt> (default) or
|
|
200
105
|
# <tt>:atom</tt>. Control the link options in url_for format using the
|
|
201
106
|
# +url_options+. You can modify the LINK tag itself in +tag_options+.
|
|
202
107
|
#
|
|
203
108
|
# ==== Options
|
|
109
|
+
#
|
|
204
110
|
# * <tt>:rel</tt> - Specify the relation of this link, defaults to "alternate"
|
|
205
111
|
# * <tt>:type</tt> - Override the auto-generated mime type
|
|
206
112
|
# * <tt>:title</tt> - Specify the title of the link, defaults to the +type+
|
|
207
113
|
#
|
|
208
114
|
# ==== Examples
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
-
#
|
|
212
|
-
#
|
|
213
|
-
#
|
|
214
|
-
#
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
#
|
|
219
|
-
#
|
|
220
|
-
#
|
|
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" />
|
|
221
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
|
+
|
|
222
137
|
tag(
|
|
223
138
|
"link",
|
|
224
139
|
"rel" => tag_options[:rel] || "alternate",
|
|
@@ -228,133 +143,64 @@ module ActionView
|
|
|
228
143
|
)
|
|
229
144
|
end
|
|
230
145
|
|
|
231
|
-
#
|
|
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".
|
|
232
149
|
#
|
|
233
|
-
#
|
|
234
|
-
#
|
|
235
|
-
# <link href="/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
|
|
236
|
-
#
|
|
237
|
-
# You may specify a different file in the first argument:
|
|
238
|
-
#
|
|
239
|
-
# <%= favicon_link_tag '/myicon.ico' %>
|
|
150
|
+
# ==== Options
|
|
240
151
|
#
|
|
241
|
-
#
|
|
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'
|
|
242
154
|
#
|
|
243
|
-
#
|
|
155
|
+
# ==== Examples
|
|
244
156
|
#
|
|
245
|
-
#
|
|
157
|
+
# favicon_link_tag '/myicon.ico'
|
|
158
|
+
# # => <link href="/assets/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
|
|
246
159
|
#
|
|
247
|
-
#
|
|
160
|
+
# Mobile Safari looks for a different <link> tag, pointing to an image that
|
|
248
161
|
# will be used if you add the page to the home screen of an iPod Touch, iPhone, or iPad.
|
|
249
162
|
# The following call would generate such a tag:
|
|
250
163
|
#
|
|
251
|
-
#
|
|
252
|
-
#
|
|
253
|
-
def favicon_link_tag(source='
|
|
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={})
|
|
254
167
|
tag('link', {
|
|
255
168
|
:rel => 'shortcut icon',
|
|
256
169
|
:type => 'image/vnd.microsoft.icon',
|
|
257
170
|
:href => path_to_image(source)
|
|
258
|
-
}.merge(options.symbolize_keys))
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
# Computes the path to an image asset in the public images directory.
|
|
262
|
-
# Full paths from the document root will be passed through.
|
|
263
|
-
# Used internally by +image_tag+ to build the image path:
|
|
264
|
-
#
|
|
265
|
-
# image_path("edit") # => "/images/edit"
|
|
266
|
-
# image_path("edit.png") # => "/images/edit.png"
|
|
267
|
-
# image_path("icons/edit.png") # => "/images/icons/edit.png"
|
|
268
|
-
# image_path("/icons/edit.png") # => "/icons/edit.png"
|
|
269
|
-
# image_path("http://www.example.com/img/edit.png") # => "http://www.example.com/img/edit.png"
|
|
270
|
-
#
|
|
271
|
-
# If you have images as application resources this method may conflict with their named routes.
|
|
272
|
-
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
|
|
273
|
-
# plugin authors are encouraged to do so.
|
|
274
|
-
def image_path(source)
|
|
275
|
-
source.present? ? asset_paths.compute_public_path(source, 'images') : ""
|
|
276
|
-
end
|
|
277
|
-
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
|
|
278
|
-
|
|
279
|
-
# Computes the path to a video asset in the public videos directory.
|
|
280
|
-
# Full paths from the document root will be passed through.
|
|
281
|
-
# Used internally by +video_tag+ to build the video path.
|
|
282
|
-
#
|
|
283
|
-
# ==== Examples
|
|
284
|
-
# video_path("hd") # => /videos/hd
|
|
285
|
-
# video_path("hd.avi") # => /videos/hd.avi
|
|
286
|
-
# video_path("trailers/hd.avi") # => /videos/trailers/hd.avi
|
|
287
|
-
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
|
|
288
|
-
# video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
|
|
289
|
-
def video_path(source)
|
|
290
|
-
asset_paths.compute_public_path(source, 'videos')
|
|
291
|
-
end
|
|
292
|
-
alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
|
|
293
|
-
|
|
294
|
-
# Computes the path to an audio asset in the public audios directory.
|
|
295
|
-
# Full paths from the document root will be passed through.
|
|
296
|
-
# Used internally by +audio_tag+ to build the audio path.
|
|
297
|
-
#
|
|
298
|
-
# ==== Examples
|
|
299
|
-
# audio_path("horse") # => /audios/horse
|
|
300
|
-
# audio_path("horse.wav") # => /audios/horse.wav
|
|
301
|
-
# audio_path("sounds/horse.wav") # => /audios/sounds/horse.wav
|
|
302
|
-
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
|
|
303
|
-
# audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
|
|
304
|
-
def audio_path(source)
|
|
305
|
-
asset_paths.compute_public_path(source, 'audios')
|
|
306
|
-
end
|
|
307
|
-
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
|
|
308
|
-
|
|
309
|
-
# Computes the path to a font asset in the public fonts directory.
|
|
310
|
-
# Full paths from the document root will be passed through.
|
|
311
|
-
#
|
|
312
|
-
# ==== Examples
|
|
313
|
-
# font_path("font") # => /fonts/font
|
|
314
|
-
# font_path("font.ttf") # => /fonts/font.ttf
|
|
315
|
-
# font_path("dir/font.ttf") # => /fonts/dir/font.ttf
|
|
316
|
-
# font_path("/dir/font.ttf") # => /dir/font.ttf
|
|
317
|
-
# font_path("http://www.example.com/dir/font.ttf") # => http://www.example.com/dir/font.ttf
|
|
318
|
-
def font_path(source)
|
|
319
|
-
asset_paths.compute_public_path(source, 'fonts')
|
|
171
|
+
}.merge!(options.symbolize_keys))
|
|
320
172
|
end
|
|
321
|
-
alias_method :path_to_font, :font_path # aliased to avoid conflicts with an font_path named route
|
|
322
173
|
|
|
323
|
-
# Returns an
|
|
324
|
-
# path or a file
|
|
174
|
+
# Returns an HTML image tag for the +source+. The +source+ can be a full
|
|
175
|
+
# path or a file.
|
|
325
176
|
#
|
|
326
177
|
# ==== Options
|
|
178
|
+
#
|
|
327
179
|
# You can add HTML attributes using the +options+. The +options+ supports
|
|
328
180
|
# three additional keys for convenience and conformance:
|
|
329
181
|
#
|
|
330
182
|
# * <tt>:alt</tt> - If no alt text is given, the file name part of the
|
|
331
183
|
# +source+ is used (capitalized and without the extension)
|
|
332
|
-
# * <tt>:size</tt> - Supplied as "{Width}x{Height}", so "30x45" becomes
|
|
333
|
-
# width="30" and height="45"
|
|
334
|
-
# value is not in the correct format.
|
|
335
|
-
# * <tt>:mouseover</tt> - Set an alternate image to be used when the onmouseover
|
|
336
|
-
# event is fired, and sets the original image to be replaced onmouseout.
|
|
337
|
-
# This can be used to implement an easy image toggle that fires on onmouseover.
|
|
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.
|
|
338
187
|
#
|
|
339
188
|
# ==== Examples
|
|
340
|
-
#
|
|
341
|
-
#
|
|
342
|
-
#
|
|
343
|
-
#
|
|
344
|
-
#
|
|
345
|
-
#
|
|
346
|
-
#
|
|
347
|
-
#
|
|
348
|
-
#
|
|
349
|
-
#
|
|
350
|
-
#
|
|
351
|
-
#
|
|
352
|
-
#
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
# <img src="/images/mouse.png" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" alt="Mouse" />
|
|
356
|
-
def image_tag(source, options = {})
|
|
357
|
-
options.symbolize_keys!
|
|
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
|
|
358
204
|
|
|
359
205
|
src = options[:src] = path_to_image(source)
|
|
360
206
|
|
|
@@ -363,19 +209,32 @@ module ActionView
|
|
|
363
209
|
end
|
|
364
210
|
|
|
365
211
|
if size = options.delete(:size)
|
|
366
|
-
options[:width], options[:height] = size.split("x") if size =~ %r{
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if mouseover = options.delete(:mouseover)
|
|
370
|
-
options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
|
|
371
|
-
options[:onmouseout] = "this.src='#{src}'"
|
|
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}
|
|
372
214
|
end
|
|
373
215
|
|
|
374
216
|
tag("img", options)
|
|
375
217
|
end
|
|
376
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" />
|
|
377
236
|
def image_alt(src)
|
|
378
|
-
File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').capitalize
|
|
237
|
+
File.basename(src, '.*').sub(/-[[:xdigit:]]{32}\z/, '').tr('-_', ' ').capitalize
|
|
379
238
|
end
|
|
380
239
|
|
|
381
240
|
# Returns an html video tag for the +sources+. If +sources+ is a string,
|
|
@@ -395,62 +254,66 @@ module ActionView
|
|
|
395
254
|
# value is not in the correct format.
|
|
396
255
|
#
|
|
397
256
|
# ==== Examples
|
|
398
|
-
#
|
|
399
|
-
#
|
|
400
|
-
#
|
|
401
|
-
#
|
|
402
|
-
#
|
|
403
|
-
#
|
|
404
|
-
#
|
|
405
|
-
#
|
|
406
|
-
#
|
|
407
|
-
#
|
|
408
|
-
#
|
|
409
|
-
#
|
|
410
|
-
#
|
|
411
|
-
#
|
|
412
|
-
#
|
|
413
|
-
#
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
|
|
421
|
-
end
|
|
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]
|
|
422
279
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
sources.map { |source| tag("source", :src => source) }.join.html_safe
|
|
280
|
+
if size = options.delete(:size)
|
|
281
|
+
options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
|
|
426
282
|
end
|
|
427
|
-
else
|
|
428
|
-
options[:src] = path_to_video(sources)
|
|
429
|
-
tag("video", options)
|
|
430
283
|
end
|
|
431
284
|
end
|
|
432
285
|
|
|
433
|
-
# Returns an
|
|
286
|
+
# Returns an HTML audio tag for the +source+.
|
|
434
287
|
# The +source+ can be full path or file that exists in
|
|
435
288
|
# your public audios directory.
|
|
436
289
|
#
|
|
437
|
-
#
|
|
438
|
-
#
|
|
439
|
-
#
|
|
440
|
-
#
|
|
441
|
-
#
|
|
442
|
-
#
|
|
443
|
-
#
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
tag("audio", options)
|
|
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)
|
|
448
300
|
end
|
|
449
301
|
|
|
450
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?
|
|
451
308
|
|
|
452
|
-
|
|
453
|
-
|
|
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
|
|
454
317
|
end
|
|
455
318
|
end
|
|
456
319
|
end
|