Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Commit 1da3225

Browse files
Abstract creation of the patterns (#29)
* Abstract creation of the patterns * Fix prioritisation * NodeName includes the prefix * Handle lang inheritance correctly * Improve xpath and naming * Support JATS articles directly * Add helpers * Restore method * Not needed * Treat template as nullable * Keep it wrapped in a Libero item * Make a dedicated bundle * Cross bundle so create a function * Test * Avoid setting a fake argument * Not meant * Move Libero XML to its own bundle * Not meant * Revert patterns update * No longer needed * Add JATS italics * Remove inline handling since that's a new feature * Not needed * Add missing tests * Trigger Travis build
1 parent a88bdd9 commit 1da3225

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1892
-292
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"tests\\Libero\\Browser\\": "tests/",
1414
"tests\\Libero\\ContentPageBundle\\": "vendor-extra/ContentPageBundle/tests/",
1515
"tests\\Libero\\JatsContentBundle\\": "vendor-extra/JatsContentBundle/tests/",
16-
"tests\\Libero\\LiberoContentBundle\\": "vendor-extra/LiberoContentBundle/tests/"
16+
"tests\\Libero\\LiberoContentBundle\\": "vendor-extra/LiberoContentBundle/tests/",
17+
"tests\\Libero\\ViewsBundle\\": "vendor-extra/ViewsBundle/tests/"
1718
}
1819
},
1920
"require": {
@@ -25,6 +26,7 @@
2526
"libero/jats-content-bundle": "^1.0@dev",
2627
"libero/libero-content-bundle": "^1.0@dev",
2728
"libero/patterns-bundle": "^1.0@dev",
29+
"libero/views-bundle": "^1.0@dev",
2830
"symfony/asset": "^4.1",
2931
"symfony/config": "^4.1",
3032
"symfony/console": "^4.1",

composer.lock

Lines changed: 44 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Libero\JatsContentBundle\JatsContentBundle::class => ['all' => true],
99
Libero\LiberoContentBundle\LiberoContentBundle::class => ['all' => true],
1010
Libero\LiberoPatternsBundle\LiberoPatternsBundle::class => ['all' => true],
11+
Libero\ViewsBundle\ViewsBundle::class => ['all' => true],
1112
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
1213
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
1314
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<testsuite name="LiberoContentBundle">
2525
<directory suffix=".php">vendor-extra/LiberoContentBundle/tests</directory>
2626
</testsuite>
27+
<testsuite name="ViewsBundle">
28+
<directory suffix=".php">vendor-extra/ViewsBundle/tests</directory>
29+
</testsuite>
2730
</testsuites>
2831

2932
<filter>
@@ -32,6 +35,7 @@
3235
<directory>vendor-extra/ContentPageBundle/src</directory>
3336
<directory>vendor-extra/JatsContentBundle/src</directory>
3437
<directory>vendor-extra/LiberoContentBundle/src</directory>
38+
<directory>vendor-extra/ViewsBundle/src</directory>
3539
</whitelist>
3640
</filter>
3741

symfony.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
"libero/patterns-bundle": {
5757
"version": "1.0.x-dev"
5858
},
59+
"libero/views-bundle": {
60+
"version": "1.0.x-dev"
61+
},
5962
"monolog/monolog": {
6063
"version": "1.24.0"
6164
},

vendor-extra/ContentPageBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"fluentdom/fluentdom": "^7.0",
1717
"guzzlehttp/guzzle": "^6.3",
1818
"libero/patterns-bundle": "^1.0@dev",
19+
"libero/views-bundle": "^1.0@dev",
1920
"psr/http-message": "^1.0",
2021
"punic/punic": "^3.3",
2122
"symfony/config": "^4.1",

vendor-extra/ContentPageBundle/src/DependencyInjection/ContentPageExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Libero\ContentPageBundle\Controller\ContentController;
88
use Libero\ContentPageBundle\Routing\ContentPageRouteLoader;
9+
use Libero\ViewsBundle\Views\ViewConverter;
910
use Symfony\Component\Config\Definition\ConfigurationInterface;
1011
use Symfony\Component\Config\FileLocator;
1112
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -46,6 +47,7 @@ private function addPage(string $name, array $config, ContainerBuilder $containe
4647
$definition->setArgument(1, $config['service']);
4748
$definition->setArgument(2, new Reference('twig'));
4849
$definition->setArgument(3, $config['page_template']);
50+
$definition->setArgument(4, new Reference(ViewConverter::class));
4951
$definition->addTag('controller.service_arguments');
5052
$definition->addTag('libero.content_page.controller', ['handler' => $config['handler']]);
5153

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace tests\Libero\ContentPageBundle;
6+
7+
use FluentDOM\DOM\Element;
8+
use Libero\ViewsBundle\Views\CallbackViewConverter;
9+
use Libero\ViewsBundle\Views\View;
10+
use Libero\ViewsBundle\Views\ViewConverter;
11+
12+
trait ViewConvertingTestCase
13+
{
14+
final protected function createConverter() : ViewConverter
15+
{
16+
return new CallbackViewConverter(
17+
function (Element $object, ?string $template, array $context) : View {
18+
return new View($template, ['element' => $object->getNodePath(), 'context' => $context]);
19+
}
20+
);
21+
}
22+
}

vendor-extra/JatsContentBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"php": "^7.2",
1313
"fluentdom/fluentdom": "^7.0",
1414
"libero/content-page-bundle": "^1.0@dev",
15+
"libero/views-bundle": "^1.0@dev",
1516
"symfony/config": "^4.1",
1617
"symfony/dependency-injection": "^4.1",
1718
"symfony/http-kernel": "^4.1"

vendor-extra/JatsContentBundle/src/Handler/JatsContentHandler.php

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44

55
namespace Libero\JatsContentBundle\Handler;
66

7-
use FluentDOM\DOM\Attribute;
87
use FluentDOM\DOM\Document;
98
use FluentDOM\DOM\Element;
10-
use FluentDOM\DOM\Xpath;
119
use Libero\ContentPageBundle\Handler\ContentHandler;
10+
use Libero\ViewsBundle\Views\ViewConverter;
1211
use UnexpectedValueException;
1312
use function array_merge;
14-
use function Libero\ContentPageBundle\text_direction;
1513

1614
final class JatsContentHandler implements ContentHandler
1715
{
16+
private $converter;
17+
18+
public function __construct(ViewConverter $converter)
19+
{
20+
$this->converter = $converter;
21+
}
22+
1823
public function handle(Element $documentElement, array $context) : array
1924
{
2025
/** @var Document $document */
@@ -39,60 +44,14 @@ public function handle(Element $documentElement, array $context) : array
3944
throw new UnexpectedValueException('Could not find a front');
4045
}
4146

42-
$title = $xpath->firstOf('jats:article-meta/jats:title-group/jats:article-title', $front);
43-
44-
if (!$title instanceof Element) {
45-
throw new UnexpectedValueException('Could not find a title');
46-
}
47-
48-
$contentHeader = [
49-
'template' => '@LiberoPatterns/content-header.html.twig',
50-
'arguments' => [
51-
'attributes' => [],
52-
'contentTitle' => [
53-
'attributes' => [],
54-
'text' => (string) $title,
55-
],
56-
],
57-
];
58-
59-
$contentHeader['arguments']['attributes'] += $this->determineLangAndDir($xpath, $front, $context);
60-
$contentHeader['arguments']['contentTitle']['attributes'] += $this->determineLangAndDir(
61-
$xpath,
62-
$title,
63-
array_merge(
64-
$context,
65-
$contentHeader['arguments']['attributes']
66-
)
67-
);
47+
$contentHeader = $this->converter->convert($front, '@LiberoPatterns/content-header.html.twig', $context);
6848

6949
return array_merge(
7050
$context,
7151
[
72-
'title' => $contentHeader['arguments']['contentTitle']['text'],
52+
'title' => $contentHeader->getArgument('contentTitle')['text'],
7353
'content' => [$contentHeader],
7454
]
7555
);
7656
}
77-
78-
private function determineLangAndDir(Xpath $xpath, Element $element, array $context) : array
79-
{
80-
$return = [];
81-
82-
$newLang = $xpath->firstOf('ancestor-or-self::*[@xml:lang][1]/@xml:lang', $element);
83-
84-
if (!$newLang instanceof Attribute) {
85-
return $return;
86-
}
87-
88-
if ($context['lang'] !== $newLang->nodeValue) {
89-
$return['lang'] = $newLang->nodeValue;
90-
91-
if ($context['dir'] !== $newDir = text_direction($return['lang'])) {
92-
$return['dir'] = $newDir;
93-
}
94-
}
95-
96-
return $return;
97-
}
9857
}

0 commit comments

Comments
 (0)