private function setPageAssets(Template $template, &$pageData) { $excludes = $this->getExcludes(); $jsAssets = $template->getAssets('js', $excludes); $cssAssets = $template->getAssets('css', $excludes); $paths = $this->getAssetsPath(); if (count($paths)) { foreach ($paths as $path) { if (strpos($path, 'css') > -1) { $cssAssets = array_merge($cssAssets, $this->searchAssets($path, 'css', $excludes)); sort($cssAssets); } else { if (strpos($path, 'js') > -1) { $jsAssets = array_merge($jsAssets, $this->searchAssets($path, 'js', $excludes)); sort($jsAssets); } } } } if (is_array($pageData) && $pageData['pagina']) { $pageData['pagina']['scripts'] = $this->setPublicRelativePath($jsAssets); $pageData['pagina']['stylesheets'] = $this->setPublicRelativePath($cssAssets); } return ''; }
/** * @covers Columnis\Model\Template::getDefinedAssets * @covers Columnis\Model\Template::searchAssets */ public function testGetAssets() { $template = new Template(); $path = $this->getExampleTemplatePath(); $template->setPath($path); $name = 'example-template'; $template->setName($name); $extensions = array('css', 'js'); $extension = $extensions[array_rand($extensions)]; $searchAssets = array('css' => array(realpath($path . DIRECTORY_SEPARATOR . 'css/example.css'), realpath($path . DIRECTORY_SEPARATOR . 'css/example2.css')), 'js' => array(realpath($path . DIRECTORY_SEPARATOR . 'js/example.js'))); $definedAssets = array('css' => array(realpath(Bootstrap::getTestFilesDir() . 'public.dist/css/jquery-ui.css')), 'js' => array(realpath(Bootstrap::getTestFilesDir() . 'public.dist/js/jquery-1.8.2.min.js'))); $expectedDefinedAssets = $definedAssets[$extension]; $expectedSearchAssets = $searchAssets[$extension]; sort($expectedSearchAssets); $expectedAssets = array_merge($expectedDefinedAssets, $expectedSearchAssets); $this->assertEquals($expectedAssets, $template->getAssets($extension)); }
/** * Returns true if it is a valid template * * @param string $templatePath * @return boolean */ public function validTemplate($templatePath) { if (!is_dir($templatePath)) { return false; } $template = new Template(); $template->setPath($templatePath); return $template->isValid(); }
/** * Creats a Template instance from an array with page Data. * * @param array $data * @throws TemplateNameNotSetException * @return Template */ public function createFromData(array $data) { if (isset($data['template']) && !empty($data['template'])) { $templateName = $data['template']; } else { throw new TemplateNameNotSetException("Template not set in page response."); } if (isset($data['template_path']) && !empty($data['template_path'])) { $path = $data['template_path']; } else { $path = $this->getExistantTemplatePath($templateName); } $template = new Template(); $template->setName($templateName); $template->setPath($path); return $template; }