Sha256: 0b0c1f612dca7742d8ab64a65e6866279ff0c25ba2942eb8c17308ca7296be6b

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Jekyll
  module AssetsPlugin
    class AssetFile

      @@mtimes = Hash.new


      attr_reader :asset


      def initialize site, asset
        @site, @asset = site, asset
      end


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


      def filename
        cachebust = @site.assets_config.cachebust

        case cachebust
        when :none, :soft then asset.logical_path
        when :hard        then asset.digest_path
        else raise "Unknown cachebust strategy: #{cachebust.inspect}"
        end
      end


      def path
        @asset.pathname.to_s
      end


      def mtime
        @asset.mtime.to_i
      end


      def modified?
        @@mtimes[path] != mtime
      end


      def write dest
        dest_path = destination dest

        return false if File.exist?(dest_path) and !modified?
        @@mtimes[path] = mtime

        @asset.write_to dest_path
        true
      end


      def == other
        case other
        when AssetFile        then @asset == other.asset
        when Sprockets::Asset then @asset == other
        else false
        end
      end


      def to_s
        "#<Jekyll::AssetsPlugin::AssetFile:#{asset.logical_path}>"
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-assets-0.3.4 lib/jekyll/assets_plugin/asset_file.rb