Sha256: c63a4aadfecae28f84f9c20371b870a4444974ea0c2a61a44c0aec0d2cf78e53

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 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.is_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)
              @asset = asset
              @env   =   env
              @args  =  args
            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] ||= {}
                if !@args[:html].has_key?("alt")
                  then @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

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-assets-2.0.3 lib/jekyll/assets/liquid/tag/defaults/image.rb
jekyll-assets-2.0.2 lib/jekyll/assets/liquid/tag/defaults/image.rb