Sha256: 0f0d6371c1445bb0c4a676dfe3d63014a601ff97cf29cb1d1894b7363a64f9ad

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# stdlib
require 'set'


module Jekyll
  module AssetsPlugin
    # Represents single asset that can be used as StaticFile for Site
    #
    class AssetFile
      class NotFound < StandardError; end

      @@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 other.asset.logical_path == asset.logical_path
        when Sprockets::Asset then other.logical_path == asset.logical_path
        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.2.0 lib/jekyll/assets_plugin/asset_file.rb