Sha256: bd9702369d22fecccf280b5fbf27d7e487487ef3ad63a485f76dfe6254f1c9d6

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

# 3rd-party
require "sprockets"

module Jekyll
  module AssetsPlugin
    module Patches
      module AssetPatch
        def self.included(base)
          base.send :extend, ClassMethods
          base.send :include, InstanceMethods
        end

        module ClassMethods
          def mtimes
            @mtimes ||= {}
          end
        end

        module InstanceMethods
          attr_reader :site

          def jekyll_assets
            []
          end

          def bundle!
            site.bundle_asset! self if site
            self
          end

          def destination(dest)
            File.join dest, site.assets_config.dirname, filename
          end

          def filename
            case cachebust = site.assets_config.cachebust
            when :none, :soft then logical_path
            when :hard        then digest_path
            else fail "Unknown cachebust strategy: #{cachebust.inspect}"
            end
          end

          def modified?
            self.class.mtimes[pathname.to_s] != mtime.to_i
          end

          def write(dest)
            dest_path = destination dest

            return false if File.exist?(dest_path) && !modified?
            self.class.mtimes[pathname.to_s] = mtime.to_i

            write_to dest_path
            write_to "#{dest_path}.gz" if gzip?

            true
          end

          def gzip?
            site.assets_config.gzip.include? content_type
          end
        end
      end
    end
  end
end

Sprockets::Asset.send :include, Jekyll::AssetsPlugin::Patches::AssetPatch

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
jekyll-assets-0.13.0 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.12.1 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.12.0 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.11.0 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.10.1 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.10.0 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.9.2 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.9.1 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.9.0 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.8.1 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.8.0 lib/jekyll/assets_plugin/patches/asset_patch.rb
tgfa-jekyll-assets-0.7.9.2 lib/jekyll/assets_plugin/patches/asset_patch.rb
tgfa-jekyll-assets-0.7.9.1 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.7.9 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.7.8 lib/jekyll/assets_plugin/patches/asset_patch.rb
jekyll-assets-0.7.7 lib/jekyll/assets_plugin/patches/asset_patch.rb