public function testGenerateNameWithRelativePathDoesNotQueryPuliRepoIfCurrentDirNull()
 {
     $this->repo = $this->getMock('Puli\\Repository\\Api\\ResourceRepository');
     $this->repo->expects($this->never())->method('get');
     $this->factory = new PuliAssetFactory($this->repo, self::$fixturesDir);
     $name = $this->factory->generateAssetName(array('style.css'));
     // Don't use "/webmozart/puli" here, because that also corresponds to
     // the root directory of the factory
     $name->setCurrentDir(null);
     $this->assertNotEmpty($name->__toString());
 }
Ejemplo n.º 2
0
 /**
  * Sets the current Puli directory.
  *
  * The current Puli directory is directory of the currently loaded Twig
  * template. For example, if the template "/webmozart/puli/views/index.html"
  * is being loaded, then "/webmozart/puli/views" is the current directory.
  * If asset inputs are given as relative path, the relative paths are
  * searched for in this directory of the Puli repository.
  *
  * The asset name is generated when this method is called. Once generated,
  * the name cannot be changed anymore. Hence this method can be called only
  * once.
  *
  * @param string $currentDir The current Puli directory.
  *
  * @throws RuntimeException If the method was already called before.
  */
 public function setCurrentDir($currentDir)
 {
     if ($this->name) {
         throw new RuntimeException('The current directory must be set only once.');
     }
     $this->name = $this->factory->generateAssetNameForCurrentDir($currentDir, $this->inputs, $this->filters, $this->options);
     // GC
     $this->factory = null;
     $this->inputs = null;
     $this->filters = null;
     $this->options = null;
 }
Ejemplo n.º 3
0
 protected function loadCollection($currentDir = null)
 {
     if ($this->innerCollection) {
         throw new RuntimeException('The asset collection was loaded already.');
     }
     // Load the inner collection
     // The current Puli directory is null if the currently loaded Twig
     // template was not loaded via the Puli loader
     $this->innerCollection = $this->factory->createAssetForCurrentDir($currentDir, $this->inputs, $this->filters, $this->options);
     // GC
     $this->factory = null;
     $this->inputs = null;
     $this->filters = null;
     $this->options = null;
 }
Ejemplo n.º 4
0
 private function createInnerAsset()
 {
     if ($this->innerAsset) {
         throw new RuntimeException('The inner asset must be created only once.');
     }
     $this->innerAsset = $this->factory->parseInputWithFixedValues($this->input, $this->currentDir, $this->roots, $this->vars, $this->values);
     foreach ($this->filters as $filter) {
         $this->innerAsset->ensureFilter($filter);
     }
     if (null !== $this->content) {
         $this->innerAsset->setContent($this->content);
     }
     if (null !== $this->targetPath) {
         $this->innerAsset->setTargetPath($this->targetPath);
     }
     // GC
     $this->factory = null;
     $this->input = null;
     $this->currentDir = null;
     $this->roots = null;
     $this->content = null;
     $this->targetPath = null;
 }
 /**
  * @dataProvider provideTemplates
  */
 public function testRendering($template, $output, $debug = false)
 {
     $this->assetFactory->setDebug($debug);
     $this->assertRegExp('~' . $output . '~', $this->twig->render($template));
 }