public function testGetEmptySitePages() { $fs = MockFileSystem::create(); $app = $fs->getApp(); $pages = $app->getEnvironment()->getPages(); $this->assertEquals(1, count($pages)); $this->assertEquals('_index.html', PageHelper::getRelativePath($pages[0])); $this->assertEquals(str_replace('\\', '/', PieCrustDefaults::RES_DIR() . 'theme/_content/pages/_index.html'), str_replace('\\', '/', $pages[0]->getPath())); }
public function __construct($name, $ident = '', $conf = array(), $level = PEAR_LOG_DEBUG) { $conf = array_merge(array('lineFormat' => '%{message}'), $conf); parent::__construct($name, $ident, $conf, $level); $this->color = new \Console_Color2(); $this->hasColorSupport = true; if (PieCrustDefaults::IS_WINDOWS()) { $this->hasColorSupport = false; } }
/** * @dataProvider templateDirectoriesDataProvider */ public function testTemplateDirectories($config, $expectedDirs) { $config = array('site' => array('templates_dirs' => $config)); $fs = MockFileSystem::create()->withTemplatesDir()->withConfig($config); $app = $fs->getApp(); foreach ($expectedDirs as &$dir) { $dir = $fs->url($dir); if (!is_dir($dir)) { mkdir($dir); } } $expectedDirs[] = PieCrustDefaults::RES_DIR() . 'theme/_content/templates/'; $this->assertEquals($expectedDirs, $app->getTemplatesDirs()); }
public function run(ChefContext $context) { $result = $context->getResult(); $app = $context->getApp(); $log = $context->getLog(); // Create the pages directory if it doesn't exist. if ($app->getPagesDir() == false) { $pagesDir = $app->getRootDir() . PieCrustDefaults::CONTENT_PAGES_DIR; $log->info("Creating pages directory: {$pagesDir}"); mkdir($pagesDir, 0777, true); $app->setPagesDir($pagesDir); } // Create the path of the feed. $slug = $result->command->command->args['url']; $slug = ltrim($slug, '/\\'); $fullPath = $app->getPagesDir() . $slug; if (!preg_match('/\\.[a-z0-9]+$/i', $slug)) { $fullPath .= '.html'; } $relativePath = PieCrustHelper::getRelativePath($app, $fullPath); if (file_exists($fullPath)) { throw new PieCrustException("Page already exists: {$relativePath}"); } $log->info("Creating feed: {$relativePath}"); // Get the feed template. $templatePath = PieCrustDefaults::RES_DIR() . 'prepare/rss.html'; if ($result->command->command->options['use_atom']) { $templatePath = PieCrustDefaults::RES_DIR() . 'prepare/atom.html'; } $template = file_get_contents($templatePath); // Write the contents. if (!is_dir(dirname($fullPath))) { mkdir(dirname($fullPath), 0777, true); } $f = fopen($fullPath, 'w'); fwrite($f, $template); fclose($f); $fullUrl = $app->getConfig()->getValue('site/root') . $slug; $log->info("Don't forget to add a link into your main page's header like so:"); $log->info("<link rel=\"alternate\" type=\"application/rss+xml\" href=\"{$fullUrl}\" />"); }
public static function formatTimed($startTime, $message) { static $color = null; if ($color === null) { if (PieCrustDefaults::IS_WINDOWS()) { $color = false; } else { $color = new \Console_Color2(); } } $endTime = microtime(true); $endTimeStr = sprintf('%8.1f ms', ($endTime - $startTime) * 1000.0); if ($color) { $endTimeStr = $color->escape($endTimeStr); $message = $color->escape($message); return $color->convert("[%g{$endTimeStr}%n] {$message}"); } else { return "[{$endTimeStr}] {$message}"; } }
/** * Gets the directory that contains the current theme, if any. */ public function getThemeDir() { if ($this->themeDir === null) { $this->themeDir = $this->rootDir . PieCrustDefaults::CONTENT_THEME_DIR; if (!is_dir($this->themeDir)) { $this->themeDir = PieCrustDefaults::RES_DIR() . 'theme/'; } } return $this->themeDir; }