Sha256: d74b1445d11571aec3b753fca6bd90bab5c6878a8060fe30eb4fb96bcbd9b97e

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

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

require "jekyll/assets"

module Jekyll
  module Assets
    class Default
      class Img < Default
        content_types %r!^image/(?\!x-icon$)[a-zA-Z0-9\-_\+]+$!
        internal!

        # --
        def set_width
          unless args.key?(:width) || !config[:width]
            args[:width] = "100%"
          end
        end

        # --
        def set_height
          unless args.key?(:height) || !config[:height]
            args[:height] = "auto"
          end
        end

        # --
        def set_src
          dpath = @asset.digest_path
          return @args[:src] = @asset.url if @asset.is_a?(Url)
          return @args[:src] = @env.prefix_url(dpath) unless @args[:inline]
          @args[:src] = @asset.data_uri
        end

        # --
        def set_integrity
          return unless integrity?
          @args[:integrity] = @asset.integrity
          unless @args.key?(:crossorigin)
            @args[:crossorigin] = "anonymous"
          end
        end

        # --
        def integrity?
          config[:integrity] && !@asset.is_a?(Url) &&
            !@args.key?(:integrity)
        end
      end
    end
  end
end

# --
Jekyll::Assets::Hook.register :config, :before_merge do |c|
  c.deep_merge!({
    defaults: {
      img: {
        height: false,
        integrity: Jekyll.production?,
        width: false,
      },
    },
  })
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-assets-3.0.12 lib/jekyll/assets/plugins/html/defaults/img.rb
jekyll-assets-3.0.11 lib/jekyll/assets/plugins/html/defaults/img.rb
jekyll-assets-3.0.10 lib/jekyll/assets/plugins/html/defaults/img.rb
jekyll-assets-3.0.9 lib/jekyll/assets/plugins/html/defaults/img.rb