Class: Asset::Util
- Inherits:
-
Object
- Object
- Asset::Util
- Defined in:
- lib/assets/util.rb
Class Method Summary collapse
-
.asset_path(path) ⇒ Object
Asset path.
-
.digest(path, time = mtime(path)) ⇒ Object
Digest.
-
.load_images ⇒ Object
Load images into memory.
-
.load_manifest ⇒ Object
Load manifest.
-
.mtime(path) ⇒ Object
Get timestamp.
Class Method Details
.asset_path(path) ⇒ Object
Asset path
10 11 12 |
# File 'lib/assets/util.rb', line 10 def self.asset_path(path) File.join(::Asset.path, path) end |
.digest(path, time = mtime(path)) ⇒ Object
Digest
15 16 17 |
# File 'lib/assets/util.rb', line 15 def self.digest(path, time = mtime(path)) Digest::MD5.hexdigest(%{#{path}#{time.to_i}}) end |
.load_images ⇒ Object
Load images into memory
55 56 57 58 59 60 61 |
# File 'lib/assets/util.rb', line 55 def self.load_images # Store the path and the timestamp images = Dir["#{::Asset.path}/images/**/*"].select{|f| File.file?(f)}.map do |i| i =~ /\/images\/(.+)/; [$1, mtime("images/#{$1}").to_i] end Hash[*images.flatten] end |
.load_manifest ⇒ Object
Load manifest
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/assets/util.rb', line 20 def self.load_manifest list = YAML.load_file(File.join(::Asset.path, 'manifest.yml')) manifest = [] list.each do |type, files| max = Time.new(0).utc files.each do |name| # Depending on the options, the name can be a string or a Hash h = name.is_a?(Hash) # Path looks like app.js or similar path = h ? name.keys[0] : name # Get the modified time of the asset modified = mtime("#{type}/#{path}") # Record max to know the latest change max = modified if modified > max # Loading manifest with items manifest << ::Asset::Item.new( path, type, digest(path, modified), modified, (h ? name['compress'] : true), (h ? name['bundle'] : true)) end # Insert the bundle manifest.insert(0, ::Asset::Item.new( "bundle.#{type}", type, digest("bundle.#{type}", max), max)) end manifest end |
.mtime(path) ⇒ Object
Get timestamp
5 6 7 |
# File 'lib/assets/util.rb', line 5 def self.mtime(path) File.mtime(asset_path(path)).utc end |