lib/sewing_kit/webpack/helper.rb in sewing_kit-0.7.1 vs lib/sewing_kit/webpack/helper.rb in sewing_kit-0.8.0

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require 'base64' require 'action_view/helpers' require 'sewing_kit/webpack/manifest' module SewingKit @@ -8,42 +9,40 @@ include ActionView::Helpers class UnknownJavaScriptAssetError < StandardError end - def sewing_kit_asset_paths(entrypointName, extension: 'js') - return '' unless entrypointName.present? + def sewing_kit_asset_paths(entrypoint_name, extension: 'js') + return '' unless entrypoint_name.present? - paths = SewingKit::Webpack::Manifest.asset_paths(entrypointName) + paths = SewingKit::Webpack::Manifest.asset_paths(entrypoint_name) return '' unless paths && paths[extension] - entryPaths = paths[extension] - if serve_development_assets? && extension == 'js' - entryPaths.unshift('/webpack/assets/dll/vendor.js') - end - entryPaths + entry_paths = paths[extension] + entry_paths.unshift('/webpack/assets/dll/vendor.js') if serve_development_assets? && extension == 'js' + entry_paths end def sewing_kit_link_tag(*paths) options = paths.extract_options! - tags = paths.uniq.map { |path| + tags = paths.uniq.map do |path| next '' if path == '' create_asset_tag(:link, path, options) - } + end safe_join(tags, "\n") end def sewing_kit_script_tag(*paths) options = paths.extract_options! - tags = paths.uniq.map { |path| + tags = paths.uniq.map do |path| next '' if path == '' create_asset_tag(:script, path, options) - } + end safe_join(tags, "\n") end private @@ -53,18 +52,23 @@ options = tag_options.clone if tag_options[:integrity] file_hash = extract_hash(path) - options[:integrity] = file_hash ? encode_hash(file_hash) : nil + options[:integrity] = maybe_integrity(file_hash) end case tag_type when :script content_tag(:script, '', options.reverse_merge(src: path)) when :link tag(:link, options.reverse_merge(href: path, rel: 'stylesheet')) end + end + + def maybe_integrity(file_hash) + return nil unless file_hash + encode_hash(file_hash) end def encode_hash(hash) # sewing-kit's default config places a sha256 hash in the filename. Browsers expect integrity # to be the Base64 encoded version of the binary hash prefixed with the hashing algorithm