aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-08-18 15:24:13 -0500
committerschneems <richard.schneeman@gmail.com>2016-08-29 13:16:07 -0500
commit9b22681cfc6b98343a8de0fbc0e2527aa688f36a (patch)
tree3c7bfeb06282b20939ddf1779bfb299df00ba86b /actionview
parent0a633b324eb8239a467fa7fbb9fa18abcd5759d3 (diff)
downloadrails-9b22681cfc6b98343a8de0fbc0e2527aa688f36a.tar.gz
rails-9b22681cfc6b98343a8de0fbc0e2527aa688f36a.tar.bz2
rails-9b22681cfc6b98343a8de0fbc0e2527aa688f36a.zip
Add `public_*` helpers to all the `_tag` methods.
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/helpers/asset_tag_helper.rb68
1 files changed, 58 insertions, 10 deletions
diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb
index 6cac4bc0ad..3a83701ef3 100644
--- a/actionview/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb
@@ -56,7 +56,7 @@ module ActionView
# # => <script src="http://www.example.com/xmlhr.js"></script>
def javascript_include_tag(*sources)
options = sources.extract_options!.stringify_keys
- path_options = options.extract!("protocol", "extname", "host").symbolize_keys
+ path_options = options.extract!("protocol", "extname", "host", "public_folder").symbolize_keys
sources.uniq.map { |source|
tag_options = {
"src" => path_to_javascript(source, path_options)
@@ -65,6 +65,14 @@ module ActionView
}.join("\n").html_safe
end
+ # Computes the path to a series of javascript assets in the public
+ # folder. This uses +javascript_include_tag+ and skips any asset
+ # lookups by assuming any assets are in the `public` folder.
+ def public_javascript_include_tag(*sources)
+ options = sources.extract_options!
+ javascript_include_tag(*sources, { public_folder: true }.merge!(options))
+ end
+
# Returns a stylesheet link tag for the sources specified as arguments. If
# you don't specify an extension, <tt>.css</tt> will be appended automatically.
# You can modify the link attributes by passing a hash as the last argument.
@@ -92,8 +100,7 @@ module ActionView
# # <link href="/css/stylish.css" media="screen" rel="stylesheet" />
def stylesheet_link_tag(*sources)
options = sources.extract_options!.stringify_keys
- path_options = options.extract!("protocol", "host").symbolize_keys
-
+ path_options = options.extract!("protocol", "host", "public_folder").symbolize_keys
sources.uniq.map { |source|
tag_options = {
"rel" => "stylesheet",
@@ -104,6 +111,14 @@ module ActionView
}.join("\n").html_safe
end
+ # Computes the path to a series of stylesheet assets in the public
+ # folder. This uses +stylesheet_link_tag+ and skips any asset
+ # lookups by assuming any assets are in the `public` folder.
+ def public_stylesheet_link_tag(*sources)
+ options = sources.extract_options!
+ stylesheet_link_tag(*sources, { public_folder: true }.merge!(options))
+ end
+
# Returns a link tag that browsers and feed readers can use to auto-detect
# an RSS or Atom feed. The +type+ can either be <tt>:rss</tt> (default) or
# <tt>:atom</tt>. Control the link options in url_for format using the
@@ -171,13 +186,20 @@ module ActionView
# favicon_link_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png'
# # => <link href="/assets/mb-icon.png" rel="apple-touch-icon" type="image/png" />
def favicon_link_tag(source="favicon.ico", options={})
- tag("link", {
+ tag('link', {
rel: "shortcut icon",
type: "image/x-icon",
- href: path_to_image(source)
+ href: path_to_image(source, { public_folder: options.delete(:public_folder) })
}.merge!(options.symbolize_keys))
end
+ # Returns a link tag for a favicon asset in the public
+ # folder. This uses +favicon_link_tag+ and skips any asset
+ # lookups by assuming any assets are in the `public` folder.
+ def public_favicon_link_tag(source='favicon.ico', options={})
+ favicon_link_tag(source, { public_folder: true }.merge!(options))
+ end
+
# Returns an HTML image tag for the +source+. The +source+ can be a full
# path or a file.
#
@@ -212,7 +234,7 @@ module ActionView
options = options.symbolize_keys
check_for_image_tag_errors(options)
- src = options[:src] = path_to_image(source)
+ src = options[:src] = path_to_image(source, { public_folder: options.delete(:public_folder) })
unless src.start_with?("cid:") || src.start_with?("data:") || src.blank?
options[:alt] = options.fetch(:alt) { image_alt(src) }
@@ -222,6 +244,13 @@ module ActionView
tag("img", options)
end
+ # Returns an HTML image tag for the source asset in the public
+ # folder. This uses +image_tag+ and skips any asset
+ # lookups by assuming any assets are in the `public` folder.
+ def public_image_tag(source, options={})
+ image_tag(source, { public_folder: true }.merge!(options))
+ end
+
# Returns a string suitable for an HTML image tag alt attribute.
# The +src+ argument is meant to be an image file path.
# The method removes the basename of the file path and the digest,
@@ -282,12 +311,23 @@ module ActionView
# video_tag(["trailer.ogg", "trailer.flv"], size: "160x120")
# # => <video height="120" width="160"><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
def video_tag(*sources)
+ options = sources.extract_options!.symbolize_keys
+ public_poster_folder = options.delete(:public_poster_folder)
+ sources << options
multiple_sources_tag("video", sources) do |options|
- options[:poster] = path_to_image(options[:poster]) if options[:poster]
+ options[:poster] = path_to_image(options[:poster], { public_folder: public_poster_folder }) if options[:poster]
options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
end
end
+ # Returns an HTML video tag for the source asset in the public
+ # folder. This uses +video_tag+ and skips any asset
+ # lookups by assuming any assets are in the `public` folder.
+ def public_video_tag(*sources)
+ options = sources.extract_options!
+ video_tag(*sources, { public_folder: true , public_poster_folder: true}.merge!(options))
+ end
+
# Returns an HTML audio tag for the +source+.
# The +source+ can be full path or file that exists in
# your public audios directory.
@@ -304,19 +344,27 @@ module ActionView
multiple_sources_tag("audio", sources)
end
+ # Returns an HTML audio tag for the source asset in the public
+ # folder. This uses +audio_tag+ and skips any asset
+ def public_audio_tag(*sources)
+ options = sources.extract_options!
+ audio_tag(*sources, { public_folder: true }.merge!(options))
+ end
+
private
def multiple_sources_tag(type, sources)
- options = sources.extract_options!.symbolize_keys
+ options = sources.extract_options!.symbolize_keys
+ public_folder = options.delete(:public_folder)
sources.flatten!
yield options if block_given?
if sources.size > 1
content_tag(type, options) do
- safe_join sources.map { |source| tag("source", src: send("path_to_#{type}", source)) }
+ safe_join sources.map { |source| tag("source", src: send("path_to_#{type}", source, { public_folder: public_folder })) }
end
else
- options[:src] = send("path_to_#{type}", sources.first)
+ options[:src] = send("path_to_#{type}", sources.first, { public_folder: public_folder })
content_tag(type, nil, options)
end
end