lib/hanami/helpers/assets_helper.rb in hanami-2.1.0.rc2 vs lib/hanami/helpers/assets_helper.rb in hanami-2.1.0.rc3
- old
+ new
@@ -9,51 +9,51 @@
module Helpers
# HTML assets helpers
#
# Inject these helpers in a view
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @see http://www.rubydoc.info/gems/hanami-helpers/Hanami/Helpers/HtmlHelper
module AssetsHelper
- # @since 0.1.0
+ # @since 2.1.0
# @api private
NEW_LINE_SEPARATOR = "\n"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
WILDCARD_EXT = ".*"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
JAVASCRIPT_EXT = ".js"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
STYLESHEET_EXT = ".css"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
JAVASCRIPT_MIME_TYPE = "text/javascript"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
STYLESHEET_MIME_TYPE = "text/css"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
FAVICON_MIME_TYPE = "image/x-icon"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
STYLESHEET_REL = "stylesheet"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
FAVICON_REL = "shortcut icon"
- # @since 0.1.0
+ # @since 2.1.0
# @api private
DEFAULT_FAVICON = "favicon.ico"
# @since 0.3.0
# @api private
@@ -83,19 +83,19 @@
#
# If the "subresource integrity mode" is on, `integriy` is the
# name of the algorithm, then a hyphen, then the hash value of the file.
# If more than one algorithm is used, they"ll be separated by a space.
#
- # @param sources [Array<String>] one or more assets by name or absolute URL
+ # @param source_paths [Array<String, #url>] one or more assets by name or absolute URL
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the javascript file is missing
# from the manifest
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Single Asset
#
@@ -187,19 +187,19 @@
#
# If the "subresource integrity mode" is on, `integriy` is the
# name of the algorithm, then a hyphen, then the hashed value of the file.
# If more than one algorithm is used, they"ll be separated by a space.
#
- # @param sources [Array<String>] one or more assets by name or absolute URL
+ # @param source_paths [Array<String, #url>] one or more assets by name or absolute URL
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the stylesheet file is missing
# from the manifest
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Single Asset
#
@@ -280,20 +280,20 @@
# version of the relative URL.
#
# If the "CDN mode" is on, the `src` is an absolute URL of the
# application CDN.
#
- # @param source [String] asset name or absolute URL
+ # @param source [String, #url] asset name, absolute URL, or asset object
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the image file is missing
# from the manifest
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
@@ -351,20 +351,20 @@
# of the relative URL.
#
# If the "CDN mode" is on, the `href` is an absolute URL of the
# application CDN.
#
- # @param source [String] asset name
+ # @param source [String, #url] asset name or asset object
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the favicon is file missing
# from the manifest
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
@@ -422,11 +422,11 @@
# version of the relative URL.
#
# If the "CDN mode" is on, the `src` is an absolute URL of the
# application CDN.
#
- # @param source [String] asset name or absolute URL
+ # @param source [String, #url] asset name, absolute URL or asset object
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
@@ -434,11 +434,11 @@
# from the manifest
#
# @raise [ArgumentError] if source isn"t specified both as argument or
# tag inside the given block
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
@@ -524,11 +524,11 @@
# version of the relative URL.
#
# If the "CDN mode" is on, the `src` is an absolute URL of the
# application CDN.
#
- # @param source [String] asset name or absolute URL
+ # @param source [String, #url] asset name, absolute URL or asset object
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
@@ -536,11 +536,11 @@
# from the manifest
#
# @raise [ArgumentError] if source isn"t specified both as argument or
# tag inside the given block
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
@@ -624,19 +624,19 @@
#
# If Fingerprint mode is on, it returns the fingerprinted path of the source
#
# If CDN mode is on, it returns the absolute URL of the asset.
#
- # @param source [String] the asset name
+ # @param source_path [String, #url] the asset name or asset object
#
# @return [String] the asset path
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the asset is missing
# from the manifest
#
- # @since 0.1.0
+ # @since 2.1.0
#
# @example Basic Usage
#
# <%= asset_url "application.js" %>
#
@@ -664,29 +664,30 @@
#
# <%= asset_url "application.js" %>
#
# # "https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
def asset_url(source_path)
+ return source_path.url if source_path.respond_to?(:url)
return source_path if _absolute_url?(source_path)
_context.assets[source_path].url
end
private
- # @since 0.1.0
+ # @since 2.1.0
# @api private
def _safe_tags(*source_paths, &blk)
::Hanami::View::HTML::SafeString.new(
source_paths.map(&blk).join(NEW_LINE_SEPARATOR)
)
end
# @since 2.1.0
# @api private
def _typed_path(source, ext)
- source = "#{source}#{ext}" if _append_extension?(source, ext)
+ source = "#{source}#{ext}" if source.is_a?(String) && _append_extension?(source, ext)
asset_url(source)
end
# @api private
def _subresource_integrity_value(source_path, ext)
@@ -694,11 +695,11 @@
source_path = "#{source_path}#{ext}" unless /#{Regexp.escape(ext)}\z/.match?(source_path)
_context.assets[source_path].sri
end
- # @since 0.1.0
+ # @since 2.1.0
# @api private
def _absolute_url?(source)
ABSOLUTE_URL_MATCHER.match(source)
end
@@ -708,10 +709,10 @@
return false unless _absolute_url?(source)
_context.assets.crossorigin?(source)
end
- # @since 0.1.0
+ # @since 2.1.0
# @api private
def _source_options(src, options, &blk)
options ||= {}
if src.respond_to?(:to_hash)