Sha256: d94a9fdcbc3de95fafae778cccf1ebaf3b2b4d11c57e84acf89c9ec9f49e0557

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

module Octopress
  module Assets
    class Asset

      def initialize(plugin, type, file)
        @file = file
        @type = type
        @plugin = plugin
        @plugin_type = plugin.type
        @root = plugin.assets_path
        @dir = File.join(plugin.namespace, type)
        @exists = {}
      end

      def file
        @file
      end

      def path(site)
        file = user_path(site)

        if !exists?(file) && @plugin_type != 'local_plugin'
          file = plugin_path 
        end

        unless exists? file
          raise IOError.new "Could not find #{File.basename(file)} at #{file}"
        end
        Pathname.new file
      end

      def file(file, site)
        @file = file
        path(site)
      end

      def destination
        File.join(@dir, @file)
      end

      def copy(site)
        site.static_files << StaticFile.new(path(site), destination)
      end

      def plugin_dir
        File.join @root, @type
      end

      def plugin_path
        File.join plugin_dir, @file
      end

      def user_dir(site)
        File.join site.source, Plugins.custom_dir(site), @dir
      end

      def user_path(site)
        if @plugin_type == 'local_plugin'
          File.join site.source, @dir, @file
        else
          File.join user_dir(site), @file
        end
      end

      def exists?(file)
        @exists[file] ||= File.exists?(file)
        @exists[file]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octopress-ink-1.0.0.alpha.14 lib/octopress-ink/assets/asset.rb
octopress-ink-1.0.0.alpha.13 lib/octopress-ink/assets/asset.rb
octopress-ink-1.0.0.alpha.12 lib/octopress-ink/assets/asset.rb