Sha256: 6912338579932a25d1cef3dad575efdd34be138319cb7f5cd3ca494f863934bc

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 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, @asset.digest_path)
      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 same_asset? other.asset
        when Sprockets::Asset then same_asset? other
        else false
        end
      end


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


      protected


      def same_asset? other
        other.pathname.cleanpath == asset.pathname.cleanpath
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-assets-0.3.2 lib/jekyll/assets_plugin/asset_file.rb
jekyll-assets-0.3.1 lib/jekyll/assets_plugin/asset_file.rb