Sha256: 64708a5410c913d711c10f7786d85d36335ad3f9af17932440f9d64dc83d6722

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

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

require_relative "../utils"

module Jekyll
  module Assets
    module Patches
      # --
      # Patches `Sprockets::CachedEnvironment` with some of
      # the stuff that we would like available.  Including our
      # `Util` methods, the `#manifest`, the `#asset_config`,
      # and even `#jekyll`, so that we can remain fast while
      # having some of the stuff that we need access to.
      # --
      module CachedEnv
        include Utils

        # --
        attr_reader :manifest
        attr_reader :asset_config
        attr_reader :jekyll

        # --
        # @param [Env] env the environment.
        # Patches initialize so we can give access to `#jekyll`.
        # @return [self]
        # --
        def initialize(env)
          super

          @manifest = env.manifest
          @asset_config = env.asset_config
          @jekyll = env.jekyll
        end

        # --
        def find_asset(*)
          super.tap do |v|
            v&.environment = self
          end
        end

        # --
        def find_asset!(*a)
          load(resolve!(*a).first).tap do |v|
            v.environment = self
          end
        end
      end
    end
  end
end

# --
module Sprockets
  class CachedEnvironment
    prepend Jekyll::Assets::Patches::CachedEnv
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jekyll-assets-3.0.12 lib/jekyll/assets/patches/cached.rb
jekyll-assets-3.0.11 lib/jekyll/assets/patches/cached.rb
jekyll-assets-3.0.10 lib/jekyll/assets/patches/cached.rb
jekyll-assets-3.0.9 lib/jekyll/assets/patches/cached.rb
jekyll-assets-3.0.8 lib/jekyll/assets/patches/cached.rb
jekyll-assets-3.0.7 lib/jekyll/assets/patches/cached.rb
jekyll-assets-3.0.6 lib/jekyll/assets/patches/cached.rb