lib/dassets.rb in dassets-0.3.0 vs lib/dassets.rb in dassets-0.4.0

- old
+ new

@@ -2,65 +2,55 @@ require 'set' require 'ns-options' require 'dassets/version' require 'dassets/root_path' -require 'dassets/digests' +require 'dassets/file_store' +require 'dassets/default_cache' require 'dassets/engine' +require 'dassets/asset_file' ENV['DASSETS_ASSETS_FILE'] ||= 'config/assets' module Dassets - def self.config; @config ||= Config.new; end - def self.sources; @sources ||= Set.new; end - def self.digests; @digests ||= NullDigests.new; end - + def self.config; @config ||= Config.new; end def self.configure(&block) block.call(self.config) end - def self.reset - @sources = @digests = nil - end - def self.init require self.config.assets_file - @sources = SourceList.new(self.config) - @digests = Digests.new(self.config.digests_path) end - def self.[](asset_path) - self.digests.asset_file(asset_path) + def self.[](digest_path) + AssetFile.new(digest_path) end # Cmds def self.digest_source_files(paths=nil) - require 'dassets/cmds/digest_cmd' - Cmds::DigestCmd.new(paths).run + require 'dassets/digest_cmd' + DigestCmd.new(paths).run end class Config include NsOptions::Proxy - option :root_path, Pathname, :required => true - option :digests_path, Pathname, :required => true - option :output_path, RootPath, :required => true + option :root_path, Pathname, :required => true + option :assets_file, Pathname, :default => ENV['DASSETS_ASSETS_FILE'] + option :source_path, RootPath, :default => proc{ "app/assets" } + option :source_filter, Proc, :default => proc{ |paths| paths } + option :file_store, FileStore, :default => proc{ NullFileStore.new } - option :assets_file, Pathname, :default => ENV['DASSETS_ASSETS_FILE'] - option :source_path, RootPath, :default => proc{ "app/assets" } - option :source_filter, Proc, :default => proc{ |paths| paths } - attr_reader :engines + attr_accessor :cache def initialize - super({ - :digests_path => proc{ File.join(self.source_path, '.digests') }, - :output_path => proc{ File.join(self.source_path, 'public') } - }) + super @engines = Hash.new{ |k,v| Dassets::NullEngine.new } + @cache = DefaultCache.new end def source(path=nil, &filter) self.source_path = path if path self.source_filter = filter if filter @@ -74,11 +64,9 @@ module SourceList def self.new(config) paths = Set.new paths += Dir.glob(File.join(config.source_path, "**/*")) paths.reject!{ |path| !File.file?(path) } - paths.reject!{ |path| path =~ /^#{config.output_path}/ } - paths.reject!{ |path| path =~ /^#{config.digests_path}/ } config.source_filter.call(paths).sort end end