Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Jan 11, 2024
1 parent 9b44694 commit b92ea6a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
32 changes: 17 additions & 15 deletions config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@
'capture' => 'before', // part to capture, `before` or `after` the separator (`before` by default)
],
],
'generators' => [ // list of pages generators, ordered by weight
10 => 'DefaultPages',
20 => 'VirtualPages',
30 => 'ExternalBody',
40 => 'Section',
50 => 'Taxonomy',
60 => 'Homepage',
70 => 'Pagination',
80 => 'Alias',
90 => 'Redirect',
'generators' => [ // list of pages generators class, ordered by weight
10 => 'Cecil\Generator\DefaultPages',
20 => 'Cecil\Generator\VirtualPages',
30 => 'Cecil\Generator\ExternalBody',
40 => 'Cecil\Generator\Section',
50 => 'Cecil\Generator\Taxonomy',
60 => 'Cecil\Generator\Homepage',
70 => 'Cecil\Generator\Pagination',
80 => 'Cecil\Generator\Alias',
90 => 'Cecil\Generator\Redirect',
],
'default' => [ // default generated pages
'index' => [
Expand Down Expand Up @@ -258,7 +258,9 @@
'dir' => 'resources/translations', // internal translations directory
],
],
'extensions' => [], // Twig extensions
'extensions' => [ // list of Twig extensions class
//'Name' => 'Cecil\Renderer\Extension\Class',
],
],
// themes
'themes' => [
Expand Down Expand Up @@ -369,10 +371,10 @@
'vocabulary' => ['html'],
'term' => ['html', 'atom'],
],
'postprocessors' => [ // list of output post processors
-1 => 'GeneratorMetaTag',
-2 => 'HtmlExcerpt',
-3 => 'MarkdownLink',
'postprocessors' => [ // list of output post processors class
'GeneratorMetaTag' => 'Cecil\Renderer\PostProcessor\GeneratorMetaTag',
'HtmlExcerpt' => 'Cecil\Renderer\PostProcessor\HtmlExcerpt',
'MarkdownLink' => 'Cecil\Renderer\PostProcessor\MarkdownLink',
],
],
'cache' => [
Expand Down
15 changes: 9 additions & 6 deletions src/Renderer/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Cecil\Renderer;

use Cecil\Builder;
use Cecil\Exception\RuntimeException;
use Cecil\Renderer\Extension\Core as CoreExtension;
use Cecil\Util;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
Expand Down Expand Up @@ -108,7 +109,7 @@ public function __construct(Builder $builder, $templatesPath)
// intl
$this->twig->addExtension(new IntlExtension());
if (\extension_loaded('intl')) {
$this->builder->getLogger()->debug('Intl extension is loaded');
$this->builder->getLogger()->debug('PHP Intl extension is loaded');
}
// filters fallback
$this->twig->registerUndefinedFilterCallback(function ($name) {
Expand All @@ -131,11 +132,13 @@ public function __construct(Builder $builder, $templatesPath)
}
// loads custom extensions
if ($this->builder->getConfig()->has('layouts.extensions')) {
foreach ((array) $this->builder->getConfig()->get('layouts.extensions') as $class) {
$name = $class;
$class = "Cecil\Renderer\Extension\\$class";
$this->twig->addExtension(new $class($this->builder));
$this->builder->getLogger()->debug(sprintf('Extension "%s" added', $name));
foreach ((array) $this->builder->getConfig()->get('layouts.extensions') as $name => $class) {
try {
$this->twig->addExtension(new $class($this->builder));
$this->builder->getLogger()->debug(sprintf('Twig extension "%s" added', $name));
} catch (\Exception|\Error $e) {
$this->builder->getLogger()->error(sprintf('Unable to add Twig extension "%s": %s', $class, $e->getMessage()));
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Step/Pages/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public function process(): void
$generatorManager = new GeneratorManager($this->builder);
$generators = (array) $this->config->get('pages.generators');
array_walk($generators, function ($generator, $priority) use ($generatorManager) {
$generator = "Cecil\Generator\\$generator";
if (!class_exists($generator)) {
$message = sprintf('Unable to load generator "%s".', $generator);
$message = sprintf('Unable to load generator "%s" (priority: %s).', $generator, $priority);
$this->builder->getLogger()->error($message);

return;
Expand Down
6 changes: 2 additions & 4 deletions src/Step/Pages/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,9 @@ public function process(): void
// renders each page
$count = 0;
$postprocessors = [];
foreach ($this->config->get('output.postprocessors') as $postprocessor) {
$name = $postprocessor;
$postprocessor = "Cecil\Renderer\PostProcessor\\$postprocessor";
foreach ($this->config->get('output.postprocessors') as $name => $postprocessor) {
if (!class_exists($postprocessor)) {
$this->builder->getLogger()->error(sprintf('Can\'t load output post processor "%s"', $postprocessor));
$this->builder->getLogger()->error(sprintf('Unable to load output post processor "%s"', $postprocessor));
break;
}
$postprocessors[] = new $postprocessor($this->builder);
Expand Down
11 changes: 6 additions & 5 deletions tests/fixtures/website/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
],
'pages' => [
'generators' => [
99 => 'TestError',
100 => 'TitleReplace',
99 => 'Cecil\Generator\TestError',
100 => 'Cecil\Generator\TitleReplace',
],
'default' => [
'sitemap' => [
Expand Down Expand Up @@ -167,8 +167,8 @@
'term' => ['html', 'atom', 'rss'],
],
'postprocessors' => [
'Test',
'Error',
'Cecil\Renderer\PostProcessor\Test',
'Cecil\Renderer\PostProcessor\Error',
],
],
'static' => [
Expand Down Expand Up @@ -226,7 +226,8 @@
],
'layouts' => [
'extensions' => [
'Test',
'Test' => 'Cecil\Renderer\Extension\Test',
'Test error' => 'Cecil\Renderer\Extension\TestError',
],
],
'cache' => [
Expand Down

0 comments on commit b92ea6a

Please sign in to comment.