class Asset::Util
Public Class Methods
asset_path(path)
click to toggle source
Asset
path
# File lib/assets/util.rb, line 25 def self.asset_path(path) File.join(::Asset.path, path) end
digest(string)
click to toggle source
Digest
# File lib/assets/util.rb, line 30 def self.digest(string) Digest::MD5.hexdigest(string) end
load_bundle(type)
click to toggle source
Load bundles for js and css
# File lib/assets/util.rb, line 46 def self.load_bundle(type) # Find the items items = ::Asset.manifest.select{|r| r.type == type} # Find keys for digest and max modified time keys, max = items.map(&:key).join, items.map(&:modified).max # Insert the bundle into the manifest ::Asset.manifest.insert(0, ::Asset::Item.new("bundle.#{type}", type, digest(keys), max)) end
load_images()
click to toggle source
Load images into memory
# File lib/assets/util.rb, line 58 def self.load_images # Store the path and the timestamp img = Dir["#{::Asset.path}/images/#{pattern}"].uniq.map do |i| i =~ /\/images\/(.+)/; [$1, mtime("images/#{$1}").to_i] end Hash[*img.flatten] end
load_manifest()
click to toggle source
Load manifest
# File lib/assets/util.rb, line 35 def self.load_manifest Dir["#{Asset.path}/{css,js}/#{pattern}"].uniq.map do |f| # Extract type and name f =~ /(js|css)\/(.+)$/; type, name = $1, $2 # Loading manifest with items ::Asset::Item.new(name, type, digest(File.read(f)), mtime("#{type}/#{name}")) end end
mtime(path)
click to toggle source
Get timestamp
# File lib/assets/util.rb, line 20 def self.mtime(path) File.mtime(asset_path(path)).utc end
p?()
click to toggle source
Production mode?
# File lib/assets/util.rb, line 72 def self.p? %w[staging production].include?(::Asset.mode) end
pattern()
click to toggle source
File match pattern
# File lib/assets/util.rb, line 67 def self.pattern ::Asset.symlinks ? '**{,/*/**}/*.*' : '**/*.*' end
setup!()
click to toggle source
Setup assets
# File lib/assets/util.rb, line 5 def self.setup! # Load the manifest ::Asset.manifest = load_manifest # Insert bundles %w[css js].each{|type| load_bundle(type)} # Load the bundle ::Asset.bundle = YAML.load_file(File.join(::Asset.path, 'manifest.yml')) # Load the images ::Asset.images = load_images end