/** * Creates a Javascript loader component. */ public function createComponentJs() { $files = new \WebLoader\FileCollection(WWW_DIR . '/js'); $files->addFiles(array('jquery.js', 'main.js', 'netteForms.js', 'bootstrap-3.0.0/dist/js/bootstrap.min.js', 'jqplot/dist/jquery.jqplot.min.js')); $files->addFiles(Finder::findFiles('*.js')->from(WWW_DIR . '/jqplot/dist/plugins')); // include jqplot plugins $compiler = \WebLoader\Compiler::createJsCompiler($files, WWW_DIR . '/webtemp'); return new \WebLoader\Nette\JavaScriptLoader($compiler, $this->template->basePath . '/webtemp'); }
/** * @param string $code * @param WebLoader\Compiler $loader * @param string $file * @return string */ public function __invoke($code, WebLoader\Compiler $loader, $file) { $ree = '~\\/~'; $root = $loader->getFileCollection()->getRoot(); $rootSegments = preg_split($ree, $root); $pathInfo = pathinfo($file); $pathInfoSegments = preg_split($ree, $pathInfo['dirname']); $fileRelativePath = array_diff($pathInfoSegments, $rootSegments); $fileRelativePath[] = $pathInfo['basename']; $fileRelativePath = join(DIRECTORY_SEPARATOR, $fileRelativePath); $this->lilo->appendLoadPath($root); $this->lilo->scan($fileRelativePath); $fileDeps = $this->lilo->getFileChain($fileRelativePath); $code = array_reduce($fileDeps, function ($memo, $dep) { return $memo . $dep['content']; }, ''); return $code; }
/** * Construct * @param IContainer parent * @param string name */ public function __construct($filter, $tempUri) { $files = new \WebLoader\FileCollection(WWW_DIR . "/js/"); $files->addFiles(array("texyla/js/texyla.js", "texyla/js/selection.js", "texyla/js/texy.js", "texyla/js/buttons.js", "texyla/js/dom.js", "texyla/js/view.js", "texyla/js/ajaxupload.js", "texyla/js/window.js", "texyla/languages/cs.js", "texyla/languages/sk.js", "texyla/languages/en.js", "texyla/plugins/keys/keys.js", "texyla/plugins/resizableTextarea/resizableTextarea.js", "texyla/plugins/img/img.js", "texyla/plugins/table/table.js", "texyla/plugins/link/link.js", "texyla/plugins/emoticon/emoticon.js", "texyla/plugins/symbol/symbol.js", "texyla/plugins/files/files.js", "texyla/plugins/color/color.js", "texyla/plugins/textTransform/textTransform.js", "texyla/plugins/youtube/youtube.js", "texyla/plugins/gravatar/gravatar.js", "js/texyla-init.js")); $compiler = \WebLoader\Compiler::createJsCompiler($files, WWW_DIR . "/webtemp"); // setup filter $compiler->addFilter($filter); // minifying JS $compiler->addFilter("JSMin::minify"); parent::__construct($compiler, $tempUri); }
public function createComponentJs() { $files = new \WebLoader\FileCollection(WWW_DIR . '/js'); $loadedData = iterator_to_array(Nette\Utils\Finder::findFiles('*.js')->exclude("angular*")->from(WWW_DIR . '/js')); ksort($loadedData); $files->addFiles($loadedData); $compiler = \WebLoader\Compiler::createJsCompiler($files, WWW_DIR . '/webtemp'); // při development módu vypne spojování souborů $dev = $this->context->parameters['productionMode']; $compiler->setJoinFiles($dev); return new \WebLoader\Nette\JavaScriptLoader($compiler, $this->template->basePath . '/webtemp'); }
/** * Generate compiled file(s) and render link(s) */ public function render() { $hasArgs = func_num_args() > 0; if ($hasArgs) { $backup = $this->compiler->getFileCollection(); $newFiles = new FileCollection($backup->getRoot()); $newFiles->addFiles(func_get_args()); $this->compiler->setFileCollection($newFiles); } // remote files foreach ($this->compiler->getFileCollection()->getRemoteFiles() as $file) { echo $this->getElement($file), PHP_EOL; } foreach ($this->compiler->generate() as $file) { echo $this->getElement($this->tempPath . '/' . $file->file . '?' . $file->lastModified), PHP_EOL; } if ($hasArgs) { $this->compiler->setFileCollection($backup); } }
/** * @param array $fileNames * @param string|FALSE $media * @param string $stylesDir */ private function lessComponentWrapper(array $fileNames, $media = NULL, $stylesDir = NULL) { if ($media === NULL) { $media = 'screen,projection,tv'; } if ($stylesDir === NULL) { $stylesDir = __DIR__ . '/../styles'; } $outputDirName = '/tmp/css'; $fileCollection = new WebLoader\FileCollection($stylesDir); $fileCollection->addFiles($fileNames); $name = strtolower(substr($this->name, strrpos($this->name, ':') + 1)) . '.css'; if (file_exists($stylesDir . '/' . $name)) { $files->addFile($name); } $compiler = WebLoader\Compiler::createCssCompiler($fileCollection, $this->context->parameters['wwwDir'] . $outputDirName); $filter = new WebLoader\Filter\LessFilter(); $compiler->addFileFilter($filter); $control = new WebLoader\Nette\CssLoader($compiler, $this->template->basePath . $outputDirName); if (is_string($media)) { $control->setMedia($media); } return $control; }
/** * @expectedException \WebLoader\InvalidArgumentException */ public function testNonCallableFileFilter() { $this->object->addFileFilter(4); }
public function createComponentJs($givenFiles = NULL) { // if no given files $jsFiles = gettype($givenFiles) == 'array' ? $givenFiles : $this->jsFiles; $files = new \WebLoader\FileCollection(APP_DIR . '/templates/javascript'); // můžeme načíst i externí js //$files->addRemoteFile('http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js'); $files->addFiles($jsFiles); $compiler = \WebLoader\Compiler::createJsCompiler($files, WWW_DIR . '/webtemp'); $filter = new WebLoader\Filter\VariablesFilter(array('guu' => 'guu')); $filter->setDelimiter('__', '__'); foreach ($this->jsVariables as $key => $val) { $filter->{$key} = $val; } $compiler->addFilter($filter); $dev = !empty($this->context->parameters['developmentMode']); $compiler->setJoinFiles(!$dev); return new \WebLoader\Nette\JavaScriptLoader($compiler, $this->template->basePath . '/webtemp'); }
public function createJavaScriptLoader() { $fileCollection = $this->createFileCollection(array_filter($this->files, [$this, 'isJs'])); $compiler = Compiler::createJsCompiler($fileCollection, $this->wwwDir . '/' . $this->outputDir); return new JavaScriptLoader($compiler, $this->httpRequest->url->basePath . $this->outputDir); }