Sha256: e6a6b9971df7b12c194122c526da0e0faa1c2c038607064f004cefa4fc8acc6d
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
# Frozen-string-literal: true # Copyright: 2012 - 2018 - MIT License # Encoding: utf-8 require "liquid/drop" require "forwardable/extended" require "fastimage" module Jekyll module Assets class Drop < Liquid::Drop extend Forwardable::Extended def initialize(path, jekyll:) @path = path.to_s @sprockets = jekyll.sprockets @jekyll = jekyll @asset = nil end rb_delegate :width, to: :dimensions, type: :hash rb_delegate :height, to: :dimensions, type: :hash rb_delegate :basename, to: :File, args: :@path rb_delegate :content_type, to: :asset rb_delegate :integrity, to: :asset rb_delegate :filename, to: :asset # -- # @todo this needs to move to `_url` # @return [String] the prefixed and digested path. # The digest path. # -- def digest_path @sprockets.prefix_url(asset.digest_path) end # -- # Image dimensions if the asest is an image. # @return [Hash<Integer,Integer>] the dimensions. # @note this can break easily. # -- def dimensions @dimensions ||= begin img = FastImage.size(asset.filename.to_s) { width: img.first, height: img.last, } end rescue => e Logger.error e end private def asset @asset ||= begin @sprockets.find_asset!(@path) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jekyll-assets-3.0.8 | lib/jekyll/assets/drop.rb |
jekyll-assets-3.0.7 | lib/jekyll/assets/drop.rb |