/** * JavaScript assets can be collected and rendered into `SCRIPT` elements with the `p:document:js` * element. The `href` attribute is used to add an asset to the collection. The `weight` * attribute specifies the weight of that asset. If the `weight` attribute is not specified, * the weight of the asset is defaulted to 100. If the `href` attribute is not specified, * the assets are rendered. If a template is specified the collection is passed as `this`, * otherwise the collection is rendered into an HTML string of `SCRIPT` elements. * * <pre> * <p:document:js * href = string * weight = int> * <!-- Content: p:with-params, template? --> * </p:document:js> * </pre> * * Example: * * <pre> * <p:document:js href="/public/page.js" /> * <p:document:js href="/public/reset.js" weight="-100" /> * <p:document:js /> * </pre> * * will produce: * * <pre> * <script src="/public/reset.css" type="text/javascript"></script> * <script src="/public/page.css" type="text/javascript"></script> * </pre> * * @param array $args * @param Engine $engine * @param mixed $template * * @return void|string */ public static function markup_document_js(array $args, Engine $engine, $template) { $document = \Brickrouge\get_document(); if (isset($args['href'])) { $document->js->add($args['href'], $args['weight'], dirname($engine->get_file())); return null; } return $template ? $engine($template, $document->js) : (string) $document->js; }