mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Address comment via @dhh, better option naming
This commit is contained in:
parent
e1791d1dd4
commit
3ee9d0061f
3 changed files with 23 additions and 23 deletions
|
@ -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", "public_folder").symbolize_keys
|
||||
path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys
|
||||
sources.uniq.map { |source|
|
||||
tag_options = {
|
||||
"src" => path_to_javascript(source, path_options)
|
||||
|
@ -92,7 +92,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", "public_folder").symbolize_keys
|
||||
path_options = options.extract!("protocol", "host", "skip_pipeline").symbolize_keys
|
||||
sources.uniq.map { |source|
|
||||
tag_options = {
|
||||
"rel" => "stylesheet",
|
||||
|
@ -173,7 +173,7 @@ module ActionView
|
|||
tag("link", {
|
||||
rel: "shortcut icon",
|
||||
type: "image/x-icon",
|
||||
href: path_to_image(source, public_folder: options.delete(:public_folder))
|
||||
href: path_to_image(source, skip_pipeline: options.delete(:skip_pipeline))
|
||||
}.merge!(options.symbolize_keys))
|
||||
end
|
||||
|
||||
|
@ -211,7 +211,7 @@ module ActionView
|
|||
options = options.symbolize_keys
|
||||
check_for_image_tag_errors(options)
|
||||
|
||||
src = options[:src] = path_to_image(source, public_folder: options.delete(:public_folder))
|
||||
src = options[:src] = path_to_image(source, skip_pipeline: options.delete(:skip_pipeline))
|
||||
|
||||
unless src.start_with?("cid:") || src.start_with?("data:") || src.blank?
|
||||
options[:alt] = options.fetch(:alt) { image_alt(src) }
|
||||
|
@ -289,7 +289,7 @@ module ActionView
|
|||
public_poster_folder = options.delete(:public_poster_folder)
|
||||
sources << options
|
||||
multiple_sources_tag_builder("video", sources) do |options|
|
||||
options[:poster] = path_to_image(options[:poster], public_folder: public_poster_folder) if options[:poster]
|
||||
options[:poster] = path_to_image(options[:poster], skip_pipeline: public_poster_folder) if options[:poster]
|
||||
options[:width], options[:height] = extract_dimensions(options.delete(:size)) if options[:size]
|
||||
end
|
||||
end
|
||||
|
@ -313,17 +313,17 @@ module ActionView
|
|||
private
|
||||
def multiple_sources_tag_builder(type, sources)
|
||||
options = sources.extract_options!.symbolize_keys
|
||||
public_folder = options.delete(:public_folder)
|
||||
skip_pipeline = options.delete(:skip_pipeline)
|
||||
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, public_folder: public_folder)) }
|
||||
safe_join sources.map { |source| tag("source", src: send("path_to_#{type}", source, skip_pipeline: skip_pipeline)) }
|
||||
end
|
||||
else
|
||||
options[:src] = send("path_to_#{type}", sources.first, public_folder: public_folder)
|
||||
options[:src] = send("path_to_#{type}", sources.first, skip_pipeline: skip_pipeline)
|
||||
content_tag(type, nil, options)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -121,7 +121,7 @@ module ActionView
|
|||
# This is the entry point for all assets.
|
||||
# When using the asset pipeline (i.e. sprockets and sprockets-rails), the
|
||||
# behavior is "enhanced". You can bypass the asset pipeline by passing in
|
||||
# <tt>public_folder: true</tt> to the options.
|
||||
# <tt>skip_pipeline: true</tt> to the options.
|
||||
#
|
||||
# All other asset *_path helpers delegate through this method.
|
||||
#
|
||||
|
@ -132,16 +132,16 @@ module ActionView
|
|||
#
|
||||
# asset_path("application.js") # => "/assets/application-60aa4fdc5cea14baf5400fba1abf4f2a46a5166bad4772b1effe341570f07de9.js"
|
||||
#
|
||||
# === Without the asset pipeline (<tt>public_folder: true</tt>)
|
||||
# === Without the asset pipeline (<tt>skip_pipeline: true</tt>)
|
||||
#
|
||||
# Accepts a <tt>type</tt> option that can specify the asset's extension. No error
|
||||
# checking is done to verify the source passed into +asset_path+ is valid
|
||||
# and that the file exists on disk.
|
||||
#
|
||||
# asset_path("application.js", public_folder: true) # => "application.js"
|
||||
# asset_path("filedoesnotexist.png", public_folder: true) # => "filedoesnotexist.png"
|
||||
# asset_path("application", type: :javascript, public_folder: true) # => "/javascripts/application.js"
|
||||
# asset_path("application", type: :stylesheet, public_folder: true) # => "/stylesheets/application.css"
|
||||
# asset_path("application.js", skip_pipeline: true) # => "application.js"
|
||||
# asset_path("filedoesnotexist.png", skip_pipeline: true) # => "filedoesnotexist.png"
|
||||
# asset_path("application", type: :javascript, skip_pipeline: true) # => "/javascripts/application.js"
|
||||
# asset_path("application", type: :stylesheet, skip_pipeline: true) # => "/stylesheets/application.css"
|
||||
#
|
||||
# === Options applying to all assets
|
||||
#
|
||||
|
@ -167,18 +167,18 @@ module ActionView
|
|||
# root prepended.
|
||||
#
|
||||
# Rails.application.config.relative_url_root = "bar"
|
||||
# asset_path("foo.js", public_folder: true) # => "bar/foo.js"
|
||||
# asset_path("foo.js", skip_pipeline: true) # => "bar/foo.js"
|
||||
#
|
||||
# - A different asset host can be specified via <tt>config.action_controller.asset_host</tt>
|
||||
# this is commonly used in conjunction with a CDN.
|
||||
#
|
||||
# Rails.application.config.action_controller.asset_host = "assets.example.com"
|
||||
# asset_path("foo.js", public_folder: true) # => "http://assets.example.com/foo.js"
|
||||
# asset_path("foo.js", skip_pipeline: true) # => "http://assets.example.com/foo.js"
|
||||
#
|
||||
# - An extension name can be specified manually with <tt>extname</tt>.
|
||||
#
|
||||
# asset_path("foo", public_folder: true, extname: ".js") # => "/foo.js"
|
||||
# asset_path("foo.css", public_folder: true, extname: ".js") # => "/foo.css.js"
|
||||
# asset_path("foo", skip_pipeline: true, extname: ".js") # => "/foo.js"
|
||||
# asset_path("foo.css", skip_pipeline: true, extname: ".js") # => "/foo.css.js"
|
||||
def asset_path(source, options = {})
|
||||
raise ArgumentError, "nil is not a valid asset source" if source.nil?
|
||||
|
||||
|
@ -193,7 +193,7 @@ module ActionView
|
|||
end
|
||||
|
||||
if source[0] != ?/
|
||||
if options[:public_folder]
|
||||
if options[:skip_pipeline]
|
||||
source = public_compute_asset_path(source, options)
|
||||
else
|
||||
source = compute_asset_path(source, options)
|
||||
|
|
|
@ -88,7 +88,7 @@ module ApplicationTests
|
|||
}
|
||||
|
||||
cases.each do |(view_method, tag_match)|
|
||||
app_file "app/views/posts/index.html.erb", "<%= #{ view_method } '#{contents}', public_folder: true %>"
|
||||
app_file "app/views/posts/index.html.erb", "<%= #{ view_method } '#{contents}', skip_pipeline: true %>"
|
||||
|
||||
app "development"
|
||||
|
||||
|
@ -114,7 +114,7 @@ module ApplicationTests
|
|||
}
|
||||
|
||||
cases.each do |(view_method, tag_match)|
|
||||
app_file "app/views/posts/index.html.erb", "<%= #{ view_method } '#{contents}', public_folder: true %>"
|
||||
app_file "app/views/posts/index.html.erb", "<%= #{ view_method } '#{contents}', skip_pipeline: true %>"
|
||||
|
||||
app "development"
|
||||
|
||||
|
@ -127,10 +127,10 @@ module ApplicationTests
|
|||
end
|
||||
end
|
||||
|
||||
test "{ public_folder: true } does not use the asset pipeline" do
|
||||
test "{ skip_pipeline: true } does not use the asset pipeline" do
|
||||
cases = {
|
||||
/\/assets\/application-.*.\.js/ => {},
|
||||
/application.js/ => { public_folder: true },
|
||||
/application.js/ => { skip_pipeline: true },
|
||||
}
|
||||
cases.each do |(tag_match, options_hash)|
|
||||
app_file "app/views/posts/index.html.erb", "<%= asset_path('application.js', #{ options_hash }) %>"
|
||||
|
|
Loading…
Reference in a new issue