gpt4 book ai didi

ruby-on-rails - rails 6 中的 asset_pack_path 和 image_pack_tag 有什么区别?

转载 作者:行者123 更新时间:2023-12-04 08:57:50 29 4
gpt4 key购买 nike

根据我的观点,image_pack_tag 是我们在 View 中用来将图像放置在 HTML 表单中的助手。但是在 webpack 的文档中,我也看到了 asset_pack_path。现在我对此感到困惑。这里的任何人都知道确切的区别吗?

最佳答案

asset_pack_path 只返回路径。 image_pack_tag 返回一个包含 <img> 的字符串html 元素。

module Webpacker::Helper
...

# Computes the relative path for a given Webpacker asset.
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
# This will use path_to_asset internally, so most of their behaviors will be the same.
#
# Example:
#
# # When extract_css is false in webpacker.yml and the file is a css:
# <%= asset_pack_path 'calendar.css' %> # => nil
#
# # When extract_css is true in webpacker.yml or the file is not a css:
# <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
def asset_pack_path(name, **options)
if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
end
end

# Computes the absolute path for a given Webpacker asset.
# Returns the absolute path using manifest.json and passes it to url_to_asset helper.
# This will use url_to_asset internally, so most of their behaviors will be the same.
#
# Example:
#
# # When extract_css is false in webpacker.yml and the file is a css:
# <%= asset_pack_url 'calendar.css' %> # => nil
#
# # When extract_css is true in webpacker.yml or the file is not a css:
# <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
def asset_pack_url(name, **options)
if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
url_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
end
end

# Creates an image tag that references the named pack file.
#
# Example:
#
# <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
# <img alt='Edit Entry' src='/packs/application-k344a6d59eef8632c9d1.png' width='16' height='10' />
#
# <%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
# <img srcset= "/packs/picture-2x-7cca48e6cae66ec07b8e.png 2x" src="/packs/picture-c38deda30895059837cf.png" >
def image_pack_tag(name, **options)
if options[:srcset] && !options[:srcset].is_a?(String)
options[:srcset] = options[:srcset].map do |src_name, size|
"#{resolve_path_to_image(src_name)} #{size}"
end.join(", ")
end

image_tag(resolve_path_to_image(name), options)
end
end

关于ruby-on-rails - rails 6 中的 asset_pack_path 和 image_pack_tag 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63718529/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com