Modules

Gleez_Assets_Core

Gleez Assets Manager

Overview

Gleez Assets Manager allows to include throughout the application different assets (CSS, Javascript, etc.) with dependencies support and use then later.

Gleez Assets Manager makes sure all assets will be included in the correct order, no matter what order they are defined in.

Usage

Call this anywhere in your application, most likely in a template controller:
Assets::css('global', 'assets/css/global.css', array('grid', 'reset'), array('media' => 'screen', 'weight' => -10)); Assets::css('reset', 'assets/css/reset.css', NULL, array('weight' => -10)); Assets::css('grid', 'assets/css/grid.css', 'reset');

Assets::js('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', NULL, FALSE, array('weight' => -10)); Assets::js('global', 'assets/js/global.js', array('jquery')); Assets::js('stats', 'assets/js/stats.js', NULL, TRUE);

Assets::codes('alert', 'alert(\'test\')', NULL, FALSE, array('weight' => -10));

Assets::settings('settings', 'settings');

Assets::group('head', 'keywords', ''); Assets::group('head', 'description', '');

In your view file:
Kohana Assets

package
Gleez\Assets\Core
author
Corey Worrell
Sandeep Sangamreddi - Gleez
copyright
© 2011-2013 Gleez Technologies
license
http://gleezcms.org/license

Class declared in MODPATH/gleez/classes/gleez/assets/core.php on line 51.

Constants

FORMAT_TAG

string(3) "tag"

FORMAT_FILENAME

string(8) "filename"

Properties

public static array $codes

Script blocks

array(0) 

public static array $css

CSS assets

array(0) 

public static array $groups

Other asset groups (meta data, links, etc...)

array(0) 

public static array $js

Javascript assets

array(0) 

public static array $settings

Settings blocks

array(0) 

Methods

public static all_codes( [ boolean $footer = bool FALSE ] ) (defined in Gleez_Assets_Core)

Get all javascript codes of section (header or footer)

Parameters

  • boolean $footer = bool FALSE - FALSE for head, TRUE for footer [Optional]

Return Values

  • string - Asset HTML

Source Code

public static function all_codes($footer = FALSE)
{
	if (empty(Assets::$codes))
	{
		return FALSE;
	}

	Assets::_init_js();

	$assets = array();

	foreach (Assets::$codes as $handle => $data)
	{
		if ($data['footer'] === $footer)
		{
			$assets[$handle] = $data;
		}
	}

	if (empty($assets))
	{
		return FALSE;
	}

	foreach (Assets::_sort($assets) as $handle => $data)
	{
		$sorted[] = Assets::get_codes($handle);
	}

	return implode(PHP_EOL, $sorted)."\n";
}

public static all_css( [ string $format = string(3) "tag" ] ) (defined in Gleez_Assets_Core)

Get all CSS assets, sorted by dependencies

Parameters

  • string $format = string(3) "tag" - Format that be returned [Optional]

Tags

Return Values

  • string - Asset HTML

Source Code

public static function all_css($format = Assets::FORMAT_TAG)
{
	if (empty(Assets::$css))
	{
		return FALSE;
	}

	$assets = array();

	foreach (Assets::_sort(Assets::$css) as $handle => $data)
	{
		$assets[] = Assets::get_css($handle, $format);
	}

	switch ($format)
	{
		case Assets::FORMAT_TAG:
			return implode(PHP_EOL, $assets).PHP_EOL;
		break;

		case Assets::FORMAT_FILENAME:
			return Assets::compile($assets, $format, 'css');
		break;

		default:
			throw new Exception("Unknown format: $format.");
	}
}

public static all_groups( string $group ) (defined in Gleez_Assets_Core)

Get all of a groups assets, sorted by dependencies

Parameters

  • string $group required - Group name

Return Values

  • string - Assets content

Source Code

public static function all_groups($group)
{
	if ( ! isset(Assets::$groups[$group]))
	{
		return FALSE;
	}

	$assets = array();

	foreach (Assets::_sort(Assets::$groups[$group]) as $handle => $data)
	{
		$assets[] = Assets::get_group($group, $handle);
	}

	return implode(PHP_EOL, $assets);
}

public static all_js( [ boolean $footer = bool FALSE , string $format = string(3) "tag" ] ) (defined in Gleez_Assets_Core)

Get all javascript assets of section (header or footer)

Parameters

  • boolean $footer = bool FALSE - FALSE for head, TRUE for footer
  • string $format = string(3) "tag" - Format that be returned [Optional]

Tags

Return Values

  • string - Asset HTML

Source Code

public static function all_js($footer = FALSE, $format = Assets::FORMAT_TAG)
{
	if (empty(Assets::$js))
	{
		return FALSE;
	}

	Assets::_init_js();

	$assets = array();

	foreach (Assets::$js as $handle => $data)
	{
		if ($data['footer'] === $footer)
		{
			$assets[$handle] = $data;
		}
	}

	if (empty($assets))
	{
		return FALSE;
	}

	foreach (Assets::_sort($assets) as $handle => $data)
	{
		$sorted[] = Assets::get_js($handle, $format);
	}

	switch ($format)
	{
		case Assets::FORMAT_TAG:
			return implode(PHP_EOL, $sorted)."\n";
		break;

		case Assets::FORMAT_FILENAME:
			return Assets::compile($sorted);
		break;

		default:
			throw new Exception("Unknown format: $format.");
	}
}

public static codes( mixed $handle [, string $code = NULL , mixed $deps = NULL , boolean $footer = bool FALSE , array $attrs = NULL ] ) (defined in Gleez_Assets_Core)

Javascript code wrapper

Gets or sets javascript code

Parameters

  • mixed $handle required - Asset name if `string`, sets `$footer` if boolean
  • string $code = NULL - Asset code [Optional]
  • mixed $deps = NULL - Dependencies [Optional]
  • boolean $footer = bool FALSE - Whether to show in header or footer [Optional]
  • array $attrs = NULL - An array of attributes for the Documentation comments powered by Disqus