*/
class AssetRenderer
{
/**
*
* @var AssetRenderer
*/
private static $render = null;
private static $registered = false;
private function __construct()
{
}
public static function register()
{
if (self::$registered) {
return;
}
self::$registered = true;
Blade::directive('css_assets', function ($expression) { return 'showStyleSheet(' . $expression . '); ?>'; });
Blade::directive('js_assets', function ($expression) { return 'showJavaScript(' . $expression . '); ?>'; });
}
/**
*
* @return AssetRenderer
*/
public static function instance()
{
if (is_null(self::$render)) {
self::$render = new AssetRenderer();
}
return self::$render;
}
public function showJavaScript($position)
{
return $this->show($position, Asset::TYPE_JAVASCRIPT);
}
public function showStyleSheet($position)
{
return $this->show($position, Asset::TYPE_CSS);
}
public function show($position, $type)
{
$assets = AssetManager::instance()->getAssetsFor($position, $type);
if (empty($assets)) {
return '';
}
$html = '';
foreach ($assets as $asset) {
$html .= $this->getAssetHtml($asset);
}
return $html;
}
private function getAssetHtml(Asset $asset)
{
if ($asset->isCss()) {
return $this->getCssHtml($asset);
}
return $this->getJavaAssetHtml($asset);
}
private function getCssHtml(Asset $stylesheet)
{
return '' . "\n";
}
private function getJavaAssetHtml(Asset $javascript)
{
return '' . "\n";
}
}