Skip to content

Instantly share code, notes, and snippets.

@cod3beat
Created November 24, 2015 06:59
Show Gist options
  • Save cod3beat/7864a8f479135bf64aed to your computer and use it in GitHub Desktop.
Save cod3beat/7864a8f479135bf64aed to your computer and use it in GitHub Desktop.
View Helper
<?php
if (!function_exists('vAsset')) {
/**
* @param string $file
* @return string
*/
function vAsset($file)
{
static $manifest = null;
if (is_null($manifest)) {
$manifest = json_decode(file_get_contents(base_path() . '/rev-manifest.json'), true);
}
if (isset($manifest[$file])) {
return asset("build/{$manifest[$file]}");
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
}
if (!function_exists('dComponent')) {
function dComponent($name, $type)
{
if (strcmp($type, 'style') === 0) {
$base = "{$name}_style.css";
} else if (strcmp($type, 'script') === 0) {
$base = "{$name}_script.js";
} else {
throw new InvalidArgumentException("Type {$type} is unavailable.");
}
return vAsset($base);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment