저자: Beau Simensen (beau@dflydev.com)
 protected function setListItems(SourceSet $sourceSet)
 {
     foreach ($sourceSet->allSources() as $source) {
         if ($source->isGenerated() || !$source->canBeFormatted()) {
             continue;
         }
         $source->data()->set('list', $this->listitems);
     }
 }
예제 #2
0
 public function testReset()
 {
     $source000 = $this->makeTestSource('TestSource:000');
     $source001 = $this->makeTestSource('TestSource:001');
     $source002 = $this->makeTestSource('TestSource:002');
     foreach (array($source000, $source001, $source002) as $source) {
         $source->expects($this->once())->method('setHasNotChanged');
     }
     $sourceSet = new SourceSet(array($source000, $source001, $source002));
     $sourceSet->reset();
 }
예제 #3
0
 /**
  * Generate
  *
  * @param  SourceInterface           $source    Source
  * @param  SourceSet                 $sourceSet Source set
  * @throws \InvalidArgumentException
  *
  * @return string
  */
 public function generate(SourceInterface $source, SourceSet $sourceSet)
 {
     $data = $source->data();
     $generators = array();
     $isGenerator = $source->isGenerator();
     if ($generatorNames = $data->get('generator')) {
         if (!$isGenerator) {
             $source->setIsGenerator();
         }
         $generatorNames = (array) $generatorNames;
         foreach ($generatorNames as $generatorName) {
             if (!isset($this->generators[$generatorName])) {
                 throw new \InvalidArgumentException("Requested generator '{$generatorName}' could not be found; was it registered?");
             }
             $generators[] = $this->generators[$generatorName];
         }
     } else {
         if ($isGenerator) {
             $source->setIsNotGenerator();
         }
         return;
     }
     $targetSources = array($source);
     foreach ($generators as $generator) {
         $newTargetSources = array();
         foreach ($targetSources as $targetSource) {
             foreach ((array) $generator->generate($targetSource) as $generatedSource) {
                 $generatedSource->setIsGenerated();
                 $newTargetSources[] = $generatedSource;
             }
         }
         $targetSources = $newTargetSources;
     }
     foreach ($targetSources as $generatedSource) {
         $sourceSet->mergeSource($generatedSource);
     }
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function refresh(SourceSet $sourceSet)
 {
     $sinceTimeLast = $this->sinceTime;
     $this->sinceTime = date('c');
     // We regenerate the whole site if an excluded file changes.
     $excludedFilesHaveChanged = false;
     $files = $this->finderFactory->createFinder()->files()->ignoreVCS(true)->ignoreDotFiles(false)->date('>=' . $sinceTimeLast)->followLinks()->in($this->sourceDir);
     $sinceTimeLastSeconds = strtotime($sinceTimeLast);
     foreach ($files as $file) {
         if ($sinceTimeLastSeconds > $file->getMTime()) {
             // This is a hack because Finder is actually incapable
             // of resolution down to seconds.
             //
             // Sometimes this may result in the file looking like it
             // has been modified twice in a row when it has not.
             continue;
         }
         foreach ($this->ignores as $pattern) {
             if (!$this->matcher->isPattern($pattern)) {
                 continue;
             }
             if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) {
                 // Ignored files are completely ignored.
                 continue 2;
             }
         }
         foreach ($this->excludes as $pattern) {
             if (!$this->matcher->isPattern($pattern)) {
                 continue;
             }
             if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) {
                 $excludedFilesHaveChanged = true;
                 continue 2;
             }
         }
         $isRaw = false;
         foreach ($this->raws as $pattern) {
             if (!$this->matcher->isPattern($pattern)) {
                 continue;
             }
             if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) {
                 $isRaw = true;
                 break;
             }
         }
         $source = new FileSource($this->analyzer, $this, $file, $isRaw, true);
         $sourceSet->mergeSource($source);
     }
     if ($excludedFilesHaveChanged) {
         // If any of the exluded files have changed we should
         // mark all of the sources as having changed.
         foreach ($sourceSet->allSources() as $source) {
             $source->setHasChanged();
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function refresh(SourceSet $sourceSet)
 {
     if (!is_dir($this->sourceDir)) {
         return;
     }
     $sinceTimeLast = $this->sinceTime;
     $this->sinceTime = date('c');
     // We regenerate the whole site if any config file changes.
     $configFilesHaveChanged = false;
     $files = $this->finderFactory->createFinder()->files()->name('sculpin_site*.yml')->date('>=' . $sinceTimeLast)->in($this->sourceDir);
     $sinceTimeLastSeconds = strtotime($sinceTimeLast);
     foreach ($files as $file) {
         if ($sinceTimeLastSeconds > $file->getMTime()) {
             // This is a hack because Finder is actually incapable
             // of resolution down to seconds.
             //
             // Sometimes this may result in the file looking like it
             // has been modified twice in a row when it has not.
             continue;
         }
         $configFilesHaveChanged = true;
         break;
     }
     if ($configFilesHaveChanged) {
         $newConfig = $this->siteConfigurationFactory->create();
         $this->siteConfiguration->import($newConfig);
         // If any of the config files have changed we should
         // mark all of the sources as having changed.
         foreach ($sourceSet->allSources() as $source) {
             $source->setHasChanged();
         }
     }
 }
예제 #6
0
 /**
  * Updated sources
  *
  * @return array
  */
 public function updatedSources()
 {
     return $this->sourceSet->updatedSources();
 }