Class: AssetPacker::Processor::Local

Inherits:
AssetPacker::Processor show all
Defined in:
lib/asset_packer/processor/local.rb

Direct Known Subclasses

Image, Script, Stylesheet

Defined Under Namespace

Classes: Image, Script, Stylesheet

Instance Attribute Summary

Attributes inherited from AssetPacker::Processor

#asset_dir, #destination, #full_source_uri, #source_uri

Instance Method Summary collapse

Methods inherited from AssetPacker::Processor

#cache, #initialize, #retrieve_asset

Constructor Details

This class inherits a constructor from AssetPacker::Processor

Instance Method Details

#call(doc) ⇒ Object



5
6
7
8
9
# File 'lib/asset_packer/processor/local.rb', line 5

def call(doc)
  Chain.new([Image, Script, Stylesheet].map {|klz|
    klz.new(source_uri, asset_dir, destination)
  }).(doc)
end

#save_asset(uri, extension) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/asset_packer/processor/local.rb', line 11

def save_asset(uri, extension)
  return uri if uri =~ /^data:/
  asset_dir.mkdir unless asset_dir.directory?
  content = retrieve_asset(uri)
  content = yield(content) if block_given?
  digest  = Digest::MD5.hexdigest(content)
  target  = asset_dir.join(extension ? digest + '.' + extension : digest)
  File.write(target, content) unless target.exist?
  target.relative_path_from(destination.dirname)
end