This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/lib/Rails/Assets/Traits/AssetPathTrait.php

32 lines
978 B
PHP
Raw Normal View History

2013-10-02 18:14:53 +02:00
<?php
namespace Rails\Assets\Traits;
trait AssetPathTrait
{
/**
* Returns the asset path (i.e., the URL) for a file.
* If the digest option is true, the path to the compiled file
* (with fingerprint) will be returned, if found. Otherwise, $file
* will just be appended to the assets path.
* Note that $file could include path relative to assets path, if necessary,
* like $this->assetPath('jquery-ui/loading.gif');
*/
protected function assetPath($file, array $options = [])
{
if (!isset($options['digest'])) {
$options['digest'] = true;
}
if ($options['digest']) {
if ($path = \Rails::assets()->findCompiledFile($file)) {
return $path;
}
}
$root = \Rails::application()->router()->rootPath();
if ($root == '/') {
$root = '';
}
return $root . \Rails::assets()->prefix() . '/' . $file;
}
}