Sha256: 7ae486e9f4b2165c01a9c0490ccf464de891f8d55373d15c523caf84d7160688

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

# Frozen-string-literal: true
# Copyright: 2012 - 2016 - MIT License
# Encoding: utf-8

module Jekyll
  module Assets
    module Liquid
      class Tag
        module Defaults
          class Sha

            # --
            # What we plan to accept for.
            # --
            def self.for?(tag)
              return tag == "css" || tag == "js"
            end

            # --
            # Initialize a new instance.
            # --
            def initialize(args, asset, env)
              @args = args
              @asset = asset
              @env = env
            end

            # --
            # Run the defaults.
            # --
            def set!
              set_integrity
            end

            # --
            # Set the integrity attribute.
            # @return [nil]
            # --
            def set_integrity
              digest = Sprockets::DigestUtils.integrity_uri(
                Digest::SHA384.digest(
                  @asset.to_s
                )
              )

              @args.args[:html] ||= {}
              if @env.asset_config["features"]["integrity"]
                @args.args[:html]["integrity"] = digest
                @args.args[:html]["crossorigin"] = "anonymous" \
                  unless @args.args[:html]["crossorigin"]
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jekyll-assets-2.4.0 lib/jekyll/assets/liquid/tag/defaults/sha.rb
jekyll-assets-2.3.2 lib/jekyll/assets/liquid/tag/defaults/sha.rb
jekyll-assets-2.3.0 lib/jekyll/assets/liquid/tag/defaults/sha.rb
jekyll-assets-2.2.8 lib/jekyll/assets/liquid/tag/defaults/sha.rb
jekyll-assets-2.2.7 lib/jekyll/assets/liquid/tag/defaults/sha.rb
jekyll-assets-2.2.6 lib/jekyll/assets/liquid/tag/defaults/sha.rb