<?php echo $js; echo $css; echo $content; jquery::buildResponse();
public static function renderCodeBlocks($inline = TRUE, $options = array()) { // if options is not an array assume it is the minify option if (!is_array($options)) { $options = array('minify' => (bool) $options); } // ensure our defualt options are populated $options += array('safe' => TRUE, 'minify' => FALSE, 'domReady' => TRUE, 'immediate' => TRUE, 'jquery' => TRUE); extract($options); $cache = Cache::instance(); // have we been asked to build the jquery response // (which is a domready script) if ($domReady && $jquery && class_exists('jquery')) { jquery::buildResponse(FALSE); } // if we are rendering the domready code block on this pass if ($domReady && !empty(self::$scriptBlocks['domready'])) { // check if we are minifing the domready block if ($minify === TRUE || is_array($minify) && in_array('domReady', $minify)) { $minifyThis = TRUE; } else { $minifyThis = FALSE; } // build a var with the domready code blocks $domReadyBlocks = self::$scriptBlocks['domready']; self::$scriptBlocks['domready'] = array(); // sort the domready codeblocks by weight ksort($domReadyBlocks); // loop all the dom ready blocks and determine what needs to go on // this page and in what order $domReadyBlock = array(); foreach ($domReadyBlocks as $codeblocks) { // if we are storing these codeblocks in cache then get them now if (self::$cache) { // since they are in cache we have to do each one foreach ($codeblocks as $cacheName) { // check if we are minify'n these script blocks if ($minifyThis) { // see if we have already minified this $cacheMinName = 'js_min_' . substr($cacheName, 3); $cached = $cache->get($cacheMinName); // if this style is not already cached minified do so if (is_null($cached)) { // try to get the un-minified script $cached = $cache->get($cacheName); if (is_null($cached)) { kohana::log('error', 'Unable to minify cached codeblock ' . $script); continue; } // minify and cache this script $cached = self::minify($cached); $cache->set($cacheMinName, $cached, array(), Kohana::config('cache.default.lifetime')); } // add the minified style to the output buffer $domReadyBlock[] = $cached; } else { // see if we can get this script out of cache $cached = $cache->get($cacheName); if (is_null($cached)) { kohana::log('error', 'Unable to locate cached codeblock ' . $script); continue; } $domReadyBlock[] = $cached; } } } else { // if we are not storing the script in cache then the array // contains the code blocks directly $domReadyBlock = array_merge($domReadyBlock, $codeblocks); } } } // if we are building the code blocks for immediate execution if ($immediate && !empty(self::$scriptBlocks['codeblocks'])) { // the immediate code block always starts with our urlbase var $immediateBlock = array(' var URLBASE = \'' . url::base() . '\';'); // check if we are minifing the immediate block if ($minify === TRUE || is_array($minify) && in_array('immediate', $minify)) { $minifyThis = TRUE; } else { $minifyThis = FALSE; } // build a var with the immediate code blocks $immediateBlocks = self::$scriptBlocks['codeblocks']; self::$scriptBlocks['codeblocks'] = array(); // sort the immediate codeblocks by weight ksort($immediateBlocks); // loop all the immediate blocks and determine what needs to go on // this page and in what order foreach ($immediateBlocks as $codeblocks) { // if we are storing these codeblocks in cache then get them now if (self::$cache) { // since they are in cache we have to do each one foreach ($codeblocks as $cacheName) { // check if we are minify'n these script blocks if ($minifyThis) { // see if we have already minified this $cacheMinName = 'js_min_' . substr($cacheName, 3); $cached = $cache->get($cacheMinName); // if this style is not already cached minified do so if (is_null($cached)) { // try to get the un-minified script $cached = $cache->get($cacheName); if (is_null($cached)) { kohana::log('error', 'Unable to minify cached codeblock ' . $script); continue; } // minify and cache this script $cached = self::minify($cached); $cache->set($cacheMinName, $cached, array(), Kohana::config('cache.default.lifetime')); } // add the minified style to the output buffer $immediateBlock[] = $cached; } else { // see if we can get this script out of cache $cached = $cache->get($cacheName); if (is_null($cached)) { kohana::log('error', 'Unable to locate cached codeblock ' . $script); continue; } $immediateBlock[] = $cached; } } } else { // if we are not storing the script in cache then the array // contains the code blocks directly $immediateBlock = array_merge($immediateBlock, $codeblocks); } } } $codeBlock = "\n"; // if the immediate block is not empty add it to this code block if (!empty($immediateBlock)) { $codeBlock .= implode("\n", $immediateBlock); } // if the dom ready block is not empty add it to this code block if (!empty($domReadyBlock)) { $domReadyBlock = implode("\n", $domReadyBlock); // choose the appropriate tag based on the request type if (request::is_ajax()) { $codeBlock .= sprintf(self::$jstags['ajaxready'], "\n" . $domReadyBlock . "\n"); } else { $codeBlock .= sprintf(self::$jstags['domready'], "\n" . $domReadyBlock . "\n"); } } if ($inline) { if ($codeBlock == "\n") { return; } // if we are making this script HTML safe if ($safe) { $codeBlock = "\n" . '//<![CDATA[' . $codeBlock . "\n" . '//]]>' . "\n"; } echo sprintf(self::$jstags['codeblock'], $codeBlock) . "\n"; } else { if ($codeBlock == "\n") { return; } // if we are making this script HTML safe if ($safe) { $codeBlock = "\n" . '//<![CDATA[' . $codeBlock . "\n" . '//]]>' . "\n"; } return sprintf(self::$jstags['codeblock'], $codeBlock) . "\n"; } }