Sha256: 9638d9fa9f9b5cc8e0150e81f741663a102bdeb1fd164d42d07f15335512c39c

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

module Jekyll
  module Assets
    module Helpers
      extend Forwardable::Extended
      rb_delegate :manifest, {
        :to => :parent
      }

      # --
      # @param [String] path the path you wish to resolve.
      # Find the path to the asset.
      # --
      def asset_path(path, opts = {})
        return path if Pathname.new(path).absolute?
        asset = manifest.find(path).first

        if asset
          parent.used.add(asset)
          parent.prefix_path(
            parent.digest?? asset.digest_path : asset.logical_path
          )
        else
          path
        end
      end

      # --
      # @param [String] path the path you wish to resolve.
      # Pull the asset path and wrap it in url().
      # --
      def asset_url(path, opts = {})
        "url(#{asset_path(
          path, opts
        )})"
      end

      # --
      # Get access to the actual asset environment.
      # @return [Jekyll::Assets::Env]
      # --
      def parent
        environment.is_a?(Cached) ? environment.parent : environment
      end

      # --
      # Creates font_url, font_path, image_path, image_url,
      # img_path, and img_url for your pleasure.
      # --
      %W(font image img).each do |key|
        define_method "#{key}_path" do |*args|
          asset_path(
            *args
          )
        end

        #

        define_method "#{key}_url" do |*args|
          asset_url(
            *args
          )
        end
      end
    end
  end
end

#

module Sprockets
  class Context
    prepend Jekyll::Assets::Helpers
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-assets-2.2.2 lib/jekyll/assets/helpers.rb
jekyll-assets-2.2.1 lib/jekyll/assets/helpers.rb