public function assets(Kwf_Assets_Package $assetsPackage, $language = null) { if (!$language) { $language = Kwf_Trl::getInstance()->getTargetLanguage(); } $indent = str_repeat(' ', 8); $ret = ''; foreach ($assetsPackage->getPackageUrls('text/css', $language) as $file) { $ret .= "{$indent}<link rel=\"stylesheet\" type=\"text/css\" href=\"" . htmlspecialchars($file) . "\" />\n"; } foreach ($assetsPackage->getPackageUrls('text/css; media=print', $language) as $file) { $ret .= "{$indent}<link rel=\"stylesheet\" type=\"text/css\" href=\"" . htmlspecialchars($file) . "\" "; if (!Kwf_Config::getValue('debug.assets.usePrintCssForAllMedia')) { $ret .= "media=\"print\" "; } $ret .= "/>\n"; } foreach ($assetsPackage->getPackageUrls('text/javascript', $language) as $file) { $ret .= "{$indent}<script type=\"text/javascript\" src=\"" . htmlspecialchars($file) . "\"></script>\n"; } foreach ($assetsPackage->getPackageUrls('text/javascript; defer', $language) as $file) { $ret .= "<script type=\"text/javascript\">\n var se=document.createElement('script');se.type='text/javascript';se.async=true;\n se.src='" . $file . "';\n var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(se,s);\n </script>"; } return $ret; }
public function testPackage() { $package = new Kwf_Assets_Package($this->_list, 'Foo'); $c = $package->getPackageContents('text/javascript', 'en', 0, false)->getFileContents(); $this->assertContains("('kwf/responsive-el')('.test123', [350,400])", $c); $this->assertContains("('kwf/responsive-el')('.test456', [350])", $c); }
public function testPackageContents3() { $package = new Kwf_Assets_Package($this->_list, 'Kwf.Assets.ModuleDeps.C'); $c = $package->getPackageContents('text/javascript', 'en', 0, false); $c = $c->getFileContents(); $this->assertContains('console.log("C")', $c); }
public function testPackageContents() { $package = new Kwf_Assets_Package($this->_list, 'Frontend'); $contents = $package->getPackageContents('text/css', 'en', 0, false)->getFileContents(); $contents = trim($contents); $contents = str_replace("\n\n", "\n", $contents); $this->assertEquals("p{testComponent:2}", $contents); }
public function testPackageContentsSameDepTwice() { $package = new Kwf_Assets_Package($this->_list, 'Test3'); $contents = $package->getPackageContents('text/javascript', 'en', 0, false)->getFileContents(); $contents = trim($contents); $contents = str_replace("\n\n", "\n", $contents); $this->assertEquals("foo2;\nbar2;\nfoo;\nbar;", $contents); }
public function testPackageUrlsNoDefer() { $p = new Kwf_Assets_Package($this->_list, 'C'); $urls = $p->getPackageUrls('text/javascript', 'en'); $this->assertCount(1, $urls); $urls = $p->getPackageUrls('text/javascript; defer', 'en'); $this->assertCount(0, $urls); }
public function testIt() { $package = new Kwf_Assets_Package(new Kwf_Assets_DefaultDependencies_TestProviderList(), 'Foo'); $contents = $package->getPackageContents('text/javascript', 'en', 0, false)->getFileContents(); $contents = trim($contents); $contents = str_replace("\n\n", "\n", $contents); $this->assertEquals("bar;\nfoo;", $contents); }
public function setAssetsPackage(Kwf_Assets_Package $package) { $t = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($this->getClass(), 'stylesModel')); $urls = $package->getPackageUrls('text/css', Kwf_Trl::getInstance()->getTargetLanguage()); $styleEditorUrl = Kwc_Admin::getInstance($this->getClass())->getControllerUrl() . '/styles-content'; $styleEditorUrl .= '?t=' . $t->getMTime(); $urls[] = $styleEditorUrl; $this->fields['content']->setStylesCssFile($styleEditorUrl); $this->fields['content']->setCssFiles($urls); }
public function testPackageDispatch() { $package = new Kwf_Assets_Package($this->_list, 'Test'); $urls = $package->getPackageUrls('text/javascript', 'en'); $this->assertEquals(1, count($urls)); $url = $urls[0]; $output = Kwf_Assets_Dispatcher::getInstance()->getOutputForUrl($url, Kwf_Media_Output::ENCODING_NONE); $contents = trim($output['contents']); $contents = str_replace("\n\n", "\n", $contents); $this->assertRegExp("/^foo2;\nbar2;\nfoo;\nbar;\n\\/\\/# sourceMappingURL=/", $contents); }
public function testIt() { $pl = new Kwf_Assets_Filter_GeneralPackageFilter_TestProviderList(); $p = new Kwf_Assets_Package($pl, 'Foo'); $c = $p->getPackageContents('text/css', 'en', false); $this->assertEquals($c->getFileContents(), "body { color: #ff0000; }"); Kwf_Assets_Filter_GeneralPackageFilter_Dependency::$contents = 'body { color: $blue; }'; Kwf_Assets_Filter_GeneralPackageFilter_Dependency::$mtime = time(); $pl = new Kwf_Assets_Filter_GeneralPackageFilter_TestProviderList(); $p = new Kwf_Assets_Package($pl, 'Foo'); $c = $p->getPackageContents('text/css', 'en', false); $this->assertEquals($c->getFileContents(), "body { color: #0000ff; }"); }
public function testIt() { $pl = new Kwf_Assets_Filter_GeneralDepFilter_TestProviderList(); $p = new Kwf_Assets_Package($pl, 'Foo1'); $c = $p->getPackageContents('text/css', 'en', false); $this->assertEquals($c->getFileContents(), "p { color: blue; }\nbody { color: #ff0000; }"); //modify contents + mtime and make sure caches are updated correctly Kwf_Assets_Filter_GeneralDepFilter_Dependency1::$contents = 'body { color: $blue; }'; Kwf_Assets_Filter_GeneralDepFilter_Dependency1::$mtime = time(); $pl = new Kwf_Assets_Filter_GeneralDepFilter_TestProviderList(); $p = new Kwf_Assets_Package($pl, 'Foo1'); $c = $p->getPackageContents('text/css', 'en', false); $this->assertEquals($c->getFileContents(), "p { color: blue; }\nbody { color: #0000ff; }"); }
public function getPackageContents($mimeType, $language, $includeSourceMapComment = true) { $ret = parent::getPackageContents($mimeType, $language, $includeSourceMapComment); if ($mimeType == 'text/javascript; defer') { $ret = Kwf_Assets_Package_Filter_LoadDeferred::filter($ret); } return $ret; }
protected function _getFilteredUniqueDependencies($mimeType) { $ret = parent::_getFilteredUniqueDependencies($mimeType); $loadedDeps = array(); foreach ($this->_loadedDependencies as $d) { if ($this->_providerList === Kwf_Assets_Package_Default::getDefaultProviderList()) { $pkg = Kwf_Assets_Package_Default::getInstance($d); } else { $pkg = new Kwf_Assets_Package($this->_providerList, $d); } $loadedDeps = array_merge($loadedDeps, $pkg->_getFilteredUniqueDependencies($mimeType)); } foreach ($ret as $k => $i) { if (in_array($i, $loadedDeps, true)) { unset($ret[$k]); } } $ret = array_values($ret); return $ret; }
public function __construct($testDependenciesIni, $dependencyName = 'TestFiles', $rootComponentClass = null) { $this->_testDependenciesIni = $testDependenciesIni; if (is_null($rootComponentClass)) { $rootComponentClass = Kwf_Component_Data_Root::getComponentClass(); } $this->_rootComponentClass = $rootComponentClass; $testDependenciesIni = str_replace('_', '/', $testDependenciesIni) . '/dependencies.ini'; if (file_exists('tests/' . $testDependenciesIni)) { $testDependenciesIni = 'tests/' . $testDependenciesIni; } else { if (file_exists(KWF_PATH . '/tests/' . $testDependenciesIni)) { $testDependenciesIni = KWF_PATH . '/tests/' . $testDependenciesIni; } } $providers = array(); $providers[] = new Kwf_Assets_Provider_Ini(KWF_PATH . '/dependencies.ini'); $providers[] = new Kwf_Assets_Provider_Ini($testDependenciesIni); $providers = array_merge($providers, Kwf_Assets_ProviderList_Abstract::getVendorProviders()); if (file_exists('dependencies.ini')) { $providers[] = new Kwf_Assets_Provider_Ini('dependencies.ini'); } $providers[] = new Kwf_Assets_Provider_IniNoFiles(); $providers[] = new Kwf_Assets_Provider_Components($rootComponentClass); $providers[] = new Kwf_Assets_Provider_Dynamic(); $providers[] = new Kwf_Assets_TinyMce_Provider(); $providers[] = new Kwf_Assets_Provider_KwfUtils(); $providers[] = new Kwf_Assets_Provider_DefaultAssets(); $providers[] = new Kwf_Assets_Provider_AtRequires(); $providers[] = new Kwf_Assets_Provider_ViewsUser(); $providers[] = new Kwf_Assets_Provider_ErrorHandler(); $providers[] = new Kwf_Assets_Provider_JsClassKwf(); $providers[] = new Kwf_Assets_Modernizr_Provider(); $providerList = new Kwf_Assets_ProviderList_Abstract($providers); parent::__construct($providerList, $dependencyName); }
public function testPackageContents() { $package = new Kwf_Assets_Package($this->_list, 'C'); $c = $package->getPackageContents('text/javascript', 'en', 0, false)->getFileContents(); $this->assertEquals("B\nA\nD\nC", $c); }
public function __construct($dependencyName) { parent::__construct(self::getDefaultProviderList(), $dependencyName); }