Sha256: fe71e5fe8656db531bb2a4401739a8413d1a079daec1a38e3c7b242bf3f44273

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

# stdlib
require "set"

# 3rd-party
require "sprockets"

module Jekyll
  module AssetsPlugin
    module Patches
      module ProcessedAssetPatch
        def self.included(base)
          base.class_eval do
            attr_reader :jekyll_assets

            alias_method :__orig_build_dependency_paths,
              :build_dependency_paths

            alias_method :build_dependency_paths,
              :__wrap_build_dependency_paths

            alias_method :__orig_init_with, :init_with
            alias_method :init_with, :__wrap_init_with

            alias_method :__orig_encode_with, :encode_with
            alias_method :encode_with, :__wrap_encode_with
          end
        end

        def __wrap_build_dependency_paths(environment, context)
          @jekyll_assets = Set.new

          context.jekyll_assets.each do |path|
            @jekyll_assets << path
            @jekyll_assets += environment.find_asset(path).jekyll_assets
          end

          __orig_build_dependency_paths environment, context
        end

        def __wrap_init_with(environment, coder)
          __orig_init_with environment, coder

          jekyll_assets = coder["jekyll_assets"].map { |p| expand_root_path(p) }
          @jekyll_assets = Set.new jekyll_assets
        end

        def __wrap_encode_with(coder)
          __orig_encode_with coder

          coder["jekyll_assets"] = jekyll_assets.map do |path|
            relativize_root_path path
          end
        end

        ::Sprockets::ProcessedAsset.send :include, self
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-assets-0.14.0 lib/jekyll/assets_plugin/patches/processed_asset_patch.rb