9use Ubiquity\utils\base\UArray;
25 private static function gString($template, $variable, $attributes = []) {
26 $implode = UArray::implodeAsso ( $attributes,
' ',
'=',
'' );
27 return \sprintf ( $template, $variable, $implode );
30 private static function script($src, $attributes = []) {
31 return self::gString (
'<script src="%s" %s></script>', $src, $attributes );
34 private static function stylesheet($link, $attributes = []) {
35 $attributes[
'type']??=
'text/css';
36 return self::gString (
'<link href="%s" rel="stylesheet" %s>', $link, $attributes );
39 private static function image($src, $attributes = []) {
40 $attributes[
'alt']??=
'Alternate text required';
41 return self::gString (
'<img src="%s" %s>', $src, $attributes );
50 public static function start(&$config) {
51 $siteURL = $config [
'siteUrl'] ??
'';
52 self::$siteURL = \rtrim (
$siteURL,
'/' );
66 public static function getUrl($resource, $absolute =
false) {
67 if (\strpos ( $resource,
'//' ) !==
false) {
71 return self::$siteURL . self::$assetsFolder . $resource;
73 return \ltrim ( self::$assetsFolder,
'/' ) . $resource;
96 public static function getThemeUrl($theme, $resource, $absolute =
false) {
98 return self::$siteURL . self::$assetsFolder . $theme .
'/' . $resource;
100 return \ltrim ( self::$assetsFolder,
'/' ) . $theme .
'/' . $resource;
111 public static function js($resource, $attributes = [], $absolute =
false) {
112 return self::script ( self::getUrl ( $resource, $absolute ), $attributes );
123 public static function css($resource, $attributes = [], $absolute =
false) {
124 return self::stylesheet ( self::getUrl ( $resource, $absolute ), $attributes );
135 public static function img($src, $attributes = [], $absolute =
false) {
136 return self::image ( self::getUrl ( $src, $absolute ), $attributes );
147 public static function js_($resource, $attributes = [], $absolute =
false) {
148 return self::script ( self::getActiveThemeUrl ( $resource, $absolute ), $attributes );
159 public static function css_($resource, $attributes = [], $absolute =
false) {
160 return self::stylesheet ( self::getActiveThemeUrl ( $resource, $absolute ), $attributes );
171 public static function img_($src, $attributes = [], $absolute =
false) {
172 return self::image ( self::getActiveThemeUrl ( $src, $absolute ), $attributes );
Assets manager for css and js inclusions in templates.
static js_($resource, $attributes=[], $absolute=false)
Returns the script inclusion for a javascript resource in activeTheme.
static image($src, $attributes=[])
static img($src, $attributes=[], $absolute=false)
Returns the image tag for inclusion.
static css($resource, $attributes=[], $absolute=false)
Returns the css inclusion for a stylesheet resource.
static img_($src, $attributes=[], $absolute=false)
Returns the image tag for inclusion in activeTheme.
static gString($template, $variable, $attributes=[])
static start(&$config)
Starts the assets manager.
static js($resource, $attributes=[], $absolute=false)
Returns the script inclusion for a javascript resource.
static css_($resource, $attributes=[], $absolute=false)
Returns the css inclusion for a stylesheet resource in activeTheme.
static script($src, $attributes=[])
static getActiveThemeUrl($resource, $absolute=false)
Returns the absolute or relative url for a resource in the activeTheme.
static getThemeUrl($theme, $resource, $absolute=false)
Returns the absolute or relative url for a resource in a theme.
static getUrl($resource, $absolute=false)
Returns the absolute or relative url to the resource.
static setAssetsFolder($assetsFolder='/assets/')
static stylesheet($link, $attributes=[])