lib/hanami/assets/configuration.rb in hanami-assets-0.3.0 vs lib/hanami/assets/configuration.rb in hanami-assets-0.4.0

- old
+ new

@@ -84,22 +84,23 @@ namespace = Utils::String.new(base).namespace framework = Utils::Class.load_from_pattern!("(#{namespace}|Hanami)::Assets") framework.configuration end - # @since 0.1.0 + # @since 0.4.0 # @api private - attr_reader :digest_manifest + attr_reader :public_manifest # Return a new instance # # @return [Hanami::Assets::Configuration] a new instance # # @since 0.1.0 # @api private - def initialize + def initialize(&blk) reset! + instance_eval(&blk) if block_given? end # Compile mode # # Determine if compile assets from sources to destination. @@ -112,21 +113,21 @@ else @compile = value end end - # Digest mode + # Fingerprint mode # - # Determine if the helpers should generate the digest path for an asset. + # Determine if the helpers should generate the fingerprinted path for an asset. # Usually this is turned on in production mode. # # @since 0.1.0 - def digest(value = nil) + def fingerprint(value = nil) if value.nil? - @digest + @fingerprint else - @digest = value + @fingerprint = value end end # Subresource integrity mode # @@ -409,12 +410,12 @@ # @api private def asset_url(source) "#{@base_url}#{compile_path(source)}" end - # An array of digest algorithms to use for generating asset subresource - # integrity checks + # An array of crypographically secure hashing algorithms to use for + # generating asset subresource integrity checks # # @since 0.3.0 def subresource_integrity_algorithms if @subresource_integrity == true [DEFAULT_SUBRESOURCE_INTEGRITY_ALGORITHM] @@ -428,15 +429,15 @@ # Subresource integrity attribute # # @since 0.3.0 # @api private def subresource_integrity_value(source) - if subresource_integrity - digest_manifest.subresource_integrity_values( - prefix.join(source) - ).join(SUBRESOURCE_INTEGRITY_SEPARATOR) - end + return unless subresource_integrity + + public_manifest.subresource_integrity_values( + prefix.join(source) + ).join(SUBRESOURCE_INTEGRITY_SEPARATOR) end # Load Javascript compressor # # @return [Hanami::Assets::Compressors::Javascript] a compressor @@ -499,15 +500,15 @@ @port = DEFAULT_PORT @prefix = Utils::PathPrefix.new(DEFAULT_PREFIX) @subresource_integrity = false @cdn = false - @digest = false + @fingerprint = false @compile = false @base_url = nil @destination_directory = nil - @digest_manifest = Config::NullDigestManifest.new(self) + @public_manifest = Config::NullManifest.new(self) @javascript_compressor = nil @stylesheet_compressor = nil root Dir.pwd @@ -519,13 +520,13 @@ # # This MUST be executed before to accept the first HTTP request # # @since 0.1.0 def load! - if (digest || subresource_integrity) && manifest_path.exist? - @digest_manifest = Config::DigestManifest.new( - JSON.load(manifest_path.read), + if (fingerprint || subresource_integrity) && manifest_path.exist? + @public_manifest = Config::Manifest.new( + JSON.parse(manifest_path.read), manifest_path ) end @base_url = URI::Generic.build(scheme: scheme, host: host, port: url_port).to_s @@ -589,10 +590,10 @@ # @since 0.1.0 # @api private def compile_path(source) result = prefix.join(source) - result = digest_manifest.target(result) if digest + result = public_manifest.target(result) if fingerprint result.to_s end # @since 0.1.0 # @api private