예제 #1
0
 /**
  * Bakes the website.
  */
 public function bake()
 {
     $overallStart = microtime(true);
     // Display the banner.
     $bannerLevel = PEAR_LOG_DEBUG;
     if ($this->parameters['info_only']) {
         $bannerLevel = PEAR_LOG_NOTICE;
     }
     $this->logger->log("PieCrust Baker v." . PieCrustDefaults::VERSION, $bannerLevel);
     $this->logger->log("  website :  " . $this->pieCrust->getRootDir(), $bannerLevel);
     $this->logger->log("  output  :  " . $this->getBakeDir(), $bannerLevel);
     $this->logger->log("  url     :  " . $this->pieCrust->getConfig()->getValueUnchecked('site/root'), $bannerLevel);
     if ($this->parameters['info_only']) {
         return;
     }
     // Setup the PieCrust environment.
     if ($this->parameters['copy_assets']) {
         $this->pieCrust->getEnvironment()->getPageRepository()->setAssetUrlBaseRemap('%site_root%%uri%');
     }
     $this->pieCrust->getConfig()->setValue('baker/is_baking', true);
     // Create the bake record.
     $blogKeys = $this->pieCrust->getConfig()->getValueUnchecked('site/blogs');
     $bakeInfoPath = false;
     if ($this->pieCrust->isCachingEnabled()) {
         $bakeInfoPath = $this->pieCrust->getCacheDir() . self::BAKE_INFO_FILE;
     }
     $this->bakeRecord = new BakeRecord($blogKeys, $bakeInfoPath);
     // Get the cache validity information.
     $cacheInfo = new PieCrustCacheInfo($this->pieCrust);
     $cacheValidity = $cacheInfo->getValidity(false);
     // Figure out if we need to clean the cache.
     if ($this->pieCrust->isCachingEnabled()) {
         $this->cleanCacheIfNeeded($cacheValidity);
     }
     // Bake!
     $this->bakePosts();
     $this->bakePages();
     $this->bakeRecord->collectTagCombinations($this->pieCrust->getEnvironment()->getLinkCollector());
     $this->bakeTags();
     $this->bakeCategories();
     $dirBaker = new DirectoryBaker($this->pieCrust, $this->getBakeDir(), array('smart' => $this->parameters['smart'], 'mounts' => $this->parameters['mounts'], 'processors' => $this->parameters['processors'], 'skip_patterns' => $this->parameters['skip_patterns'], 'force_patterns' => $this->parameters['force_patterns']), $this->logger);
     $dirBaker->bake();
     // Save the bake record and clean up.
     if ($bakeInfoPath) {
         $this->bakeRecord->saveBakeInfo($bakeInfoPath);
     }
     $this->bakeRecord = null;
     $this->pieCrust->getConfig()->setValue('baker/is_baking', false);
     $this->logger->info('-------------------------');
     $this->logger->notice(self::formatTimed($overallStart, 'done baking'));
 }
예제 #2
0
 public function testThemeMountOverride()
 {
     $fs = MockFileSystem::create()->withAsset('normal-styles.css', ".rule { color: blue; }")->withAsset('extra-styles.css', ".override { color: white; }")->withAsset('_content/theme/_content/theme_config.yml', '')->withAsset('_content/theme/extra-styles.css', ".other { color: black; }");
     $app = $fs->getApp();
     $bakeDir = $fs->url('counter');
     $baker = new DirectoryBaker($app, $bakeDir);
     $baker->bake();
     $this->assertFileEquals($fs->url('kitchen/normal-styles.css'), $fs->url('counter/normal-styles.css'));
     $this->assertFileEquals($fs->url('kitchen/extra-styles.css'), $fs->url('counter/extra-styles.css'));
     $bakedFiles = $baker->getBakedFiles();
     $overriddenInfo = $bakedFiles[$fs->url('kitchen/_content/theme/extra-styles.css')];
     $this->assertFalse($overriddenInfo['was_baked']);
     $this->assertTrue($overriddenInfo['was_overridden']);
 }
예제 #3
0
 /**
  * Bakes the website.
  */
 public function bake()
 {
     $overallStart = microtime(true);
     // Pre-bake notification.
     $this->callAssistants('onBakeStart', array($this));
     // Display debug information.
     $this->logger->debug("  Bake Output: " . $this->getBakeDir());
     $this->logger->debug("  Root URL: " . $this->pieCrust->getConfig()->getValue('site/root'));
     // Setup the PieCrust environment.
     if ($this->parameters['copy_assets']) {
         $this->pieCrust->getEnvironment()->getPageRepository()->setAssetUrlBaseRemap('%site_root%%uri%');
     }
     $this->pieCrust->getConfig()->setValue('baker/is_baking', true);
     // Create the bake record.
     $bakeRecordPath = false;
     $this->bakeRecord = new TransitionalBakeRecord($this->pieCrust);
     if ($this->pieCrust->isCachingEnabled()) {
         $start = microtime(true);
         $bakeRecordPath = $this->pieCrust->getCacheDir() . self::BAKE_RECORD_PATH . md5($this->getBakeDir()) . DIRECTORY_SEPARATOR . 'record.json';
         $this->bakeRecord->loadPrevious($bakeRecordPath);
         $this->logger->debug(self::formatTimed($start, "loaded bake record"));
     }
     // Create the execution context.
     $executionContext = $this->pieCrust->getEnvironment()->getExecutionContext(true);
     // Get the cache validity information.
     $cacheInfo = new PieCrustCacheInfo($this->pieCrust);
     $cacheValidity = $cacheInfo->getValidity(false);
     $executionContext->isCacheValid = $cacheValidity['is_valid'];
     // Figure out if we need to clean the cache.
     $this->parameters['__smart_content'] = $this->parameters['smart'];
     if ($this->pieCrust->isCachingEnabled()) {
         if ($this->cleanCacheIfNeeded($cacheValidity)) {
             $executionContext->wasCacheCleaned = true;
             $this->parameters['__smart_content'] = false;
         } else {
             // If we didn't clean the cache, at least clean the level 0 bake cache,
             // where bake-only plugins can cache things.
             $this->cleanLevel0Cache();
         }
     }
     $this->ensureLevel0Cache();
     // Bake!
     $this->bakePosts();
     $this->bakePages();
     $this->bakeTaxonomies();
     $dirBaker = new DirectoryBaker($this->pieCrust, $this->getBakeDir(), array('smart' => $this->parameters['smart'], 'mounts' => $this->parameters['mounts'], 'processors' => $this->parameters['processors'], 'skip_patterns' => $this->parameters['skip_patterns'], 'force_patterns' => $this->parameters['force_patterns']), $this->logger);
     $dirBaker->bake();
     $this->bakeRecord->getCurrent()->addAssetEntries($dirBaker->getBakedFiles());
     $this->handleDeletions();
     // Post-bake notification.
     $this->callAssistants('onBakeEnd', array($this));
     // Save the bake record and clean up.
     if ($bakeRecordPath) {
         $start = microtime(true);
         $this->bakeRecord->collapse();
         $this->bakeRecord->saveCurrent($bakeRecordPath);
         $this->logger->debug(self::formatTimed($start, "saved bake record"));
     }
     $this->bakeRecord = null;
     $this->pieCrust->getConfig()->setValue('baker/is_baking', false);
     $this->logger->info('-------------------------');
     $this->logger->notice(self::formatTimed($overallStart, 'done baking'));
 }
예제 #4
0
 protected function prebake($server = null, $path = null)
 {
     // Things like the plugin loader will add paths to the PHP include path.
     // Let's save it and restore it later.
     $includePath = get_include_path();
     $pieCrust = new PieCrust(array('root' => $this->rootDir, 'cache' => $this->options['cache']), $server);
     $parameters = $pieCrust->getConfig()->getValue('baker');
     if ($parameters == null) {
         $parameters = array();
     }
     $parameters = array_merge(array('smart' => true, 'mounts' => array(), 'processors' => '*', 'skip_patterns' => array(), 'force_patterns' => array()), $parameters);
     $dirBaker = new DirectoryBaker($pieCrust, $this->bakeCacheDir, array('smart' => $parameters['smart'], 'mounts' => $parameters['mounts'], 'processors' => $parameters['processors'], 'skip_patterns' => $parameters['skip_patterns'], 'force_patterns' => $parameters['force_patterns']), $this->logger);
     $dirBaker->bake($path);
     // Restore the include path.
     set_include_path($includePath);
     return $dirBaker->getBakedFiles();
 }