Sha256: 8fd3e9c1030adefbe991cc0507b907e0c0b21bc6cdfc0b32b0aff841fc1b6f09

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

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

module Jekyll
  module Assets
    module Liquid
      class Tag
        module Defaults
          class Image
            def self.for?(tag)
              tag == "img" || tag == "image"
            end

            # TODO: In 3.0 env needs to be enforced if this is not changed,
            #   for now it's not enforced to maintain the 2.0 API.

            def initialize(args, asset, env = nil)
              @args = args
              @asset = asset
              @env = env
            end

            #

            def set!
              set_img_dimensions
              set_img_alt
            end

            # TODO: 3.0 - Remove the `!@env`

            private
            def set_img_alt
              if !@env || @env.asset_config["features"]["automatic_img_alt"]
                @args[:html] ||= {}
                unless @args[:html].key?("alt")
                  @args[:html]["alt"] = @asset.logical_path
                end
              end
            end

            # TODO: 3.0 - Remove the `!@env`

            private
            def set_img_dimensions
              if !@env || @env.asset_config["features"]["automatic_img_size"]
                dimensions = FastImage.new(@asset.filename).size
                return unless dimensions
                @args[:html] ||= {}

                @args[:html][ "width"] ||= dimensions.first
                @args[:html]["height"] ||= dimensions. last
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-assets-2.1.3 lib/jekyll/assets/liquid/tag/defaults/image.rb
jekyll-assets-2.1.2 lib/jekyll/assets/liquid/tag/defaults/image.rb
jekyll-assets-2.1.1 lib/jekyll/assets/liquid/tag/defaults/image.rb
jekyll-assets-2.1.0 lib/jekyll/assets/liquid/tag/defaults/image.rb