lib/hanami/assets/config/manifest.rb in hanami-assets-0.2.1 vs lib/hanami/assets/config/manifest.rb in hanami-assets-0.3.0
- old
+ new
@@ -5,22 +5,22 @@
#
# @since 0.1.0
# @api private
class MissingDigestManifestError < Error
def initialize(path)
- super("Can't read manifest: #{ path }")
+ super("Can't read manifest: #{path}")
end
end
# This error is raised when an asset is referenced from the DOM, but it's
# not present in the digest manifest
#
# @since 0.1.0
# @api private
class MissingDigestAssetError < Error
def initialize(asset, manifest_path)
- super("Can't find asset `#{ asset }' in manifest (#{ manifest_path })")
+ super("Can't find asset `#{asset}' in manifest (#{manifest_path})")
end
end
# Configuration settings
#
@@ -71,10 +71,18 @@
# Digest manifest
#
# @since 0.1.0
# @api private
class DigestManifest
+ # @since 0.3.0
+ # @api private
+ TARGET = 'target'.freeze
+
+ # @since 0.3.0
+ # @api private
+ SUBRESOURCE_INTEGRITY = 'sri'.freeze
+
# Return a new instance
#
# @param assets [Hash] the content of the digest manifest
# @param manifest_path [Pathname] the path to the digest manifest
#
@@ -93,19 +101,31 @@
# Resolve the given asset into a digest path
#
# For a given path <tt>/assets/application.js</tt> it will return
# <tt>/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js</tt>
#
- # @param asset [#to_s] the relateive asset path
+ # @param asset [#to_s] the relative asset path
#
# @return [String] the digest path
#
# @raise [Hanami::Assets::MissingDigestAssetError] when the asset can't be
# found in manifest
def resolve(asset)
@assets.fetch(asset.to_s) do
raise Hanami::Assets::MissingDigestAssetError.new(asset, @manifest_path)
end
+ end
+
+ # @since 0.3.0
+ # @api private
+ def target(path)
+ resolve(path).fetch(TARGET)
+ end
+
+ # @since 0.3.0
+ # @api private
+ def subresource_integrity_values(path)
+ resolve(path).fetch(SUBRESOURCE_INTEGRITY)
end
end
end
end
end