Sha256: 6ab5314f576215ebac81f20611c4028440cfd962c2e906cbe95d4204290efc92
Contents?: true
Size: 1.64 KB
Versions: 2
Compression:
Stored size: 1.64 KB
Contents
require 'active_support' module ActiveAssets module ActiveExpansions class Expansion include AssetScope include TypeInferrable attr_reader :type, :name, :assets, :namespace alias_method :all, :assets delegate :empty?, :to => :assets def initialize(name) @name = name @assets = [] end def configure(options = {}, &blk) @type, @group, @namespace = options.values_at(:type, :group, :namespace) instance_eval(&blk) if block_given? self end def asset(path, options = {}) options = HashWithIndifferentAccess.new(options) # map is for 1.9.2; HashWithIndifferentAccess bug? options.assert_valid_keys(*Asset.members.map(&:to_s)) inferred_type, extension = inferred_type(path) options.reverse_merge!( :type => inferred_type || @current_type || extension || type, :expansion_name => name, :group => @current_groups ) options.update(:path => path) members = options.values_at(*Asset.members) a = Asset.new(*members) a.valid! @assets << a end alias_method :a, :asset alias_method :_, :asset def group(*groups, &blk) @current_groups = groups instance_eval(&blk) ensure @current_groups = nil end def namespace(&blk) raise NoMethodError, "Cannot call namespace from within expansion." if block_given? @namespace end private def cleanse_path(path) File.join(File.dirname(path) + File.basename(path, ".#{type}")) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_assets-0.3.1 | lib/active_assets/active_expansions/expansion.rb |
active_assets-0.3.0 | lib/active_assets/active_expansions/expansion.rb |