示例#1
0
 public function testCompileWithScope()
 {
     $container = new CM_Frontend_JavascriptContainer();
     $container->append('foo()');
     $container->append('bar()');
     $this->assertSame("(function () { \n  foo();\n  bar()}).call(my_scope);", $container->compile('my_scope'));
 }
示例#2
0
 /**
  * @param string[] $sourceMainPaths
  * @param bool     $generateSourceMaps
  * @throws CM_Exception
  */
 protected function _appendSourceMainBrowserify($sourceMainPaths, $generateSourceMaps)
 {
     if ($generateSourceMaps && !$this->_js->isEmpty()) {
         throw new CM_Exception('Cannot generate source maps when output container already contains code.');
     }
     $sourcePaths = [];
     foreach (array_reverse($this->_site->getModules()) as $moduleName) {
         $sourcePaths[] = $this->_getPathInModule($moduleName, 'client-vendor/source');
     }
     $content = $this->_browserify($sourceMainPaths, $sourcePaths, $generateSourceMaps);
     $this->_js->append($content);
 }
示例#3
0
 /**
  * @return string
  */
 private function _getJs()
 {
     $treeInitJs = new CM_Frontend_JavascriptContainer();
     $treeStoredJs = new CM_Frontend_JavascriptContainer();
     foreach ($this->_getTreeNodes() as $node) {
         $treeInitJs->append($this->_getTreeNodeInitJs($node));
         $treeStoredJs->append($this->_getTreeNodeStoredJs($node));
     }
     $operations = array($this->_onloadHeaderJs->compile(), $treeInitJs->compile(), $this->_onloadPrepareJs->compile(), $treeStoredJs->compile(), $this->_onloadJs->compile(), $this->_onloadReadyJs->compile());
     $operations = array_filter($operations);
     $code = implode(PHP_EOL, $operations);
     return $code;
 }