mako\Assets


Description


Asset manager.


Class methods


Toggle source

public __construct()


Constructor.

Return value

NULL

public function __construct()
{
	// Nothing here
}

Toggle source

public static group($name = 'default')


Returns the instance of the chosen asset group.


Parameters

Type Description
string Group name
Return value

mako\Assets

public static function group($name = 'default')
{
	if(!isset(static::$groups[$name]))
	{
		static::$groups[$name] = new static();
	}

	return static::$groups[$name];
}

Toggle source

public static location()


Returns the path or URL of the assets.

Return value

string

public static function location()
{
	static $location;

	if($location === null)
	{
		$location = Config::get('mako.asset_location');
	}

	return $location;
}

Toggle source

protected add($name, $source, $attributes = array ( ))


Add an asset.


Parameters

Type Description
string Asset name
string Asset source
array (optional) Asset attributes
Return value

NULL

protected function add($name, $source, array $attributes = array())
{
	// Prefix source with asset location if it's not a URL

	if(strpos($source, '://') === false)
	{
		$source = static::location() . $source;
	}

	if(pathinfo(strtok($source, '?'), PATHINFO_EXTENSION) === 'css')
	{
		!isset($attributes['media']) && $attributes['media'] = 'all';

		defined('MAKO_XHTML') && $attributes['type'] = 'text/css';

		$this->css[$name] = array('href' => $source, 'rel' => 'stylesheet') + $attributes;
	}
	else
	{
		defined('MAKO_XHTML') && $attributes['type'] = 'text/javascript';

		$this->js[$name] = array('src' => $source) + $attributes;
	}
}

Toggle source

protected css($name = NULL)


Get one or all CSS assets.


Parameters

Type Description
string (optional) Asset name
Return value

string

protected function css($name = null)
{
	if($name === null)
	{
		$css = array();

		foreach($this->css as $key => $value)
		{
			$css[] = $this->css($key);
		}

		return implode("\n", $css);
	}

	if(!isset($this->css[$name]))
	{
		return null;
	}

	return HTML::tag('link', $this->css[$name]);
}

Toggle source

protected js($name = NULL)


Get one or all JavaScript assets.


Parameters

Type Description
string (optional) Asset name
Return value

string

protected function js($name = null)
{
	if($name === null)
	{
		$js = array();

		foreach($this->js as $key => $value)
		{
			$js[] = $this->js($key);
		}

		return implode("\n", $js);
	}

	if(!isset($this->js[$name]))
	{
		return null;
	}

	return HTML::tag('script', $this->js[$name], '');
}

Toggle source

protected all()


Get all assets.

Return value

string

protected function all()
{
	return trim(implode("\n\n", array($this->css(), $this->js())));
}

Toggle source

public __call($name, $arguments)


Performs calls on the chosen group instance.


Parameters

Type Description
string Method name
array Method arguments
Return value

mixed

public function __call($name, $arguments)
{
	return call_user_func_array(array($this, $name), $arguments);
}

Toggle source

public static __callStatic($name, $arguments)


Performs calls on the default group instance.


Parameters

Type Description
string Method name
array Method arguments
Return value

mixed

public static function __callStatic($name, $arguments)
{
	return call_user_func_array(array(static::group(), $name), $arguments);
}