module Octopress::Ink::Cache
Constants
- INK_CACHE_DIR
Public Instance Methods
cache_label(asset)
click to toggle source
# File lib/octopress-ink/cache.rb, line 26 def cache_label(asset) "#{asset.plugin.slug}-#{File.basename(asset.file, '.*').downcase}" end
clean()
click to toggle source
# File lib/octopress-ink/cache.rb, line 43 def clean if File.directory?(INK_CACHE_DIR) remove = Find.find(INK_CACHE_DIR).to_a.reject do |file| @cache_files.include?(file) || File.directory?(file) end FileUtils.rm(remove) end end
get_cache_path(dir, label, str)
click to toggle source
# File lib/octopress-ink/cache.rb, line 30 def get_cache_path(dir, label, str) File.join(dir, ".#{label}#{Digest::MD5.hexdigest(str)}.js") end
read_cache(asset, options)
click to toggle source
# File lib/octopress-ink/cache.rb, line 13 def read_cache(asset, options) path = get_cache_path(INK_CACHE_DIR, cache_label(asset), options.to_s << asset.content) @cache_files << path File.exist?(path) ? File.read(path) : nil unless path.nil? end
reset()
click to toggle source
# File lib/octopress-ink/cache.rb, line 8 def reset @cache_files = [] @write_cache = {} end
write()
click to toggle source
# File lib/octopress-ink/cache.rb, line 34 def write @write_cache.each do |path, contents| File.open(path, 'w') do |f| f.print(contents) end end @write_cache = {} end
write_to_cache(asset, content, options)
click to toggle source
# File lib/octopress-ink/cache.rb, line 19 def write_to_cache(asset, content, options) FileUtils.mkdir_p(INK_CACHE_DIR) unless File.directory?(INK_CACHE_DIR) path = get_cache_path(INK_CACHE_DIR, cache_label(asset), options.to_s << asset.content) @write_cache[path] = content content end