Example #1
0
 /**
  * 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);
     }
 }
 public function testTraversableFiles()
 {
     $this->object->addFiles(new \ArrayIterator(array('a.txt')));
     $this->assertEquals(1, count($this->object->getFiles()));
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 /**
  * Attaches BowerLoader to the FileCollection instance.
  * @param FileCollection
  * @param string resource type (eg. "css")
  * @return void
  */
 public function attach(FileCollection $collection, $resource)
 {
     if ($this->prepend) {
         $files = $collection->getFiles();
         $remoteFiles = $collection->getRemoteFiles();
         $collection->clear();
     }
     $collection->addFiles($this->getFiles($resource));
     if ($this->prepend) {
         $collection->addFiles($files);
         $collection->addRemoteFiles($remoteFiles);
     }
 }