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())); }
/** * @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}\" />"); }
/** * 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; }