Class | Juicer::Asset::Path |
In: |
lib/juicer/asset/path.rb
|
Parent: | Object |
Assets are files used by CSS and JavaScript files. The Asset class provides tools for manipulating asset paths, such as rebasing, adding cache busters, and cycling asset hosts.
Asset::Path objects are most commonly created by Juicer::Asset::PathResolver#resolve which resolves include paths to file names. It is possible, however, to use the asset class directly:
Dir.pwd #=> "/home/christian/projects/mysite/design/css" asset = Juicer::Asset::Path.new "../images/logo.png" asset.path #=> "../images/logo.png" asset.rebase("~/projects/mysite/design").path #=> "images/logo.png" asset.filename #=> "/home/christian/projects/mysite/design/images/logo.png" asset.path(:cache_buster_type => :soft) #=> "../images/logo.png?jcb=1234567890" asset.path(:cache_buster_type => :soft, :cache_buster => nil) #=> "../images/logo.png?1234567890" asset.path(:cache_buster => "bustIT") #=> "../images/logo.png?bustIT=1234567890" asset = Juicer::Asset::Path.new "../images/logo.png", :document_root #=> "/home/christian/projects/mysite" asset.absolute_path(:cache_buster_type => :hard) #=> "/images/logo-jcb1234567890.png" asset.absolute_path(:host => "http://localhost") #=> "http://localhost/images/logo.png" asset.absolute_path(:host => "http://localhost", :cache_buster_type => :hard) #=> "http://localhost/images/logo-jcb1234567890.png"
Author: | Christian Johansen (christian@cjohansen.no) |
Copyright: | Copyright (c) 2009 Christian Johansen |
License: | BSD |
base | [R] | Base directory to resolve relative path from, see Juicer::Asset::Path#initialize |
document_root | [R] | Directory served as root through a web server, see Juicer::Asset::Path#initialize |
hosts | [R] | Hosts served from :document_root, see Juicer::Asset::Path#initialize |
Accepts a single host, or an array of hosts and returns an array of hosts that include scheme/protocol, and don‘t have trailing slash.
Initialize asset at path. Accepts an optional hash of options:
Returns absolute path calculated using the document_root. Optionally accepts a hash of options:
A cache buster will be added if either (or both) of the :cache_buster or :cache_buster_type options are provided. The default cache buster type is :soft.
Raises an ArgumentException if no document_root has been set.
Returns the original path.
Accepts an optional hash of options for cache busters:
A cache buster will be added if either (or both) of the :cache_buster or :cache_buster_type options are provided. The default cache buster type is :soft.
Rebase path and return a new Asset::Path object.
asset = Juicer::Asset::Path.new "../images/logo.png", :base => "/var/www/public/stylesheets" asset2 = asset.rebase("/var/www/public") asset2.relative_path #=> "images/logo.png"
Return path relative to base
Accepts an optional hash of options for cache busters:
A cache buster will be added if either (or both) of the :cache_buster or :cache_buster_type options are provided. The default cache buster type is :soft.