Skip to content

Commit

Permalink
EZP-31028: Fixed formatting involving soft return placed inside a Cus…
Browse files Browse the repository at this point in the history
…tom Template (#78)
  • Loading branch information
adamwojs authored and lserwatka committed Oct 29, 2019
1 parent c0812f3 commit c9399e5
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 59 deletions.
5 changes: 5 additions & 0 deletions src/lib/eZ/RichText/Converter/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public function convert(DOMDocument $document)

return $document;
}

public function addConverter(Converter $converter): void
{
$this->converters[] = $converter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
</xsl:element>
</xsl:template>

<xsl:template match="docbook:section/docbook:literallayout/text()">
<xsl:call-template name="breakLine">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>

<xsl:template match="docbook:para">
<xsl:element name="p" namespace="{$outputNamespace}">
<xsl:if test="@xml:id">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
</xsl:element>
</xsl:template>

<xsl:template match="docbook:section/docbook:literallayout">
<xsl:template match="docbook:section/docbook:literallayout/text()">
<xsl:call-template name="breakLine">
<xsl:with-param name="text" select="node()"/>
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/eZ/RichText/Converter/Xslt/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected function formatValidationErrors($outputFile, array $errors)
}

/**
* @return \EzSystems\EzPlatformRichText\eZ\RichText\Converter\Xslt
* @return \EzSystems\EzPlatformRichText\eZ\RichText\Converter
*/
protected function getConverter()
{
Expand Down
80 changes: 80 additions & 0 deletions tests/lib/eZ/RichText/Converter/Xslt/DebugRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\Tests\EzPlatformRichText\eZ\RichText\Converter\Xslt;

use EzSystems\EzPlatformRichText\eZ\RichText\RendererInterface;

final class DebugRenderer implements RendererInterface
{
private const TEMPLATE_FORMAT = '<template-output name="%s" type="%s" is-inline="%s">%s</template-output>';
private const EMBED_CONTENT_FORMAT = '<embed-content-output content-id="%d" view-type="%s" is-inline="%s">%s</embed-content-output>';
private const EMBED_LOCATION_FORMAT = '<embed-location-output location-id="%d" view-type="%s" is-inline="%s">%s</embed-location-output>';

public function renderTag($name, array $parameters, $isInline): string
{
return $this->renderTemplate($name, 'tag', $parameters, $isInline);
}

public function renderTemplate($name, $type, array $parameters, $isInline): string
{
return sprintf(
self::TEMPLATE_FORMAT,
$name,
$type,
$this->serializeIsInline($isInline),
$this->serializeParameters($parameters)
);
}

public function renderContentEmbed($contentId, $viewType, array $parameters, $isInline): string
{
return sprintf(
self::EMBED_CONTENT_FORMAT,
$contentId,
$viewType,
$this->serializeIsInline($isInline),
$this->serializeParameters($parameters)
);
}

public function renderLocationEmbed($locationId, $viewType, array $parameters, $isInline): string
{
return sprintf(
self::EMBED_LOCATION_FORMAT,
$locationId,
$viewType,
$this->serializeIsInline($isInline),
$this->serializeParameters($parameters)
);
}

private function serializeParameters(array $parameters): string
{
$lines = [];

foreach ($parameters as $name => $value) {
if (is_array($value)) {
if (!empty($value)) {
$lines[] = sprintf('<param name="%s">', $name);
$lines[] = $this->serializeParameters($value);
$lines[] = sprintf('</param>');
}
} else {
$lines[] = sprintf('<param name="%s">%s</param>', $name, $value);
}
}

return implode('', $lines);
}

private function serializeIsInline(bool $isInline): string
{
return $isInline ? 'true' : 'false';
}
}
34 changes: 25 additions & 9 deletions tests/lib/eZ/RichText/Converter/Xslt/DocbookToXhtml5OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

namespace EzSystems\Tests\EzPlatformRichText\eZ\RichText\Converter\Xslt;

use EzSystems\EzPlatformRichText\eZ\RichText\Converter;
use EzSystems\EzPlatformRichText\eZ\RichText\Converter\Aggregate;
use EzSystems\EzPlatformRichText\eZ\RichText\Converter\Render\Template;
use EzSystems\EzPlatformRichText\eZ\RichText\Converter\Xslt;

/**
* Tests conversion from docbook to xhtml5 output format.
*/
Expand Down Expand Up @@ -84,15 +89,26 @@ protected function getCustomConversionTransformationStylesheets()
];
}

/**
* Return an array of absolute paths to conversion result validation schemas.
*
* @return string[]
*/
protected function getConversionValidationSchema()
protected function getConverter(): Converter
{
return [
__DIR__ . '/_fixtures/xhtml5/output/custom_schemas/youtube.xsd',
];
if ($this->converter === null) {
$this->converter = new Aggregate();

$this->converter->addConverter(
new Template(
new DebugRenderer(),
$this->converter
)
);

$this->converter->addConverter(
new Xslt(
$this->getConversionTransformationStylesheet(),
$this->getCustomConversionTransformationStylesheets()
)
);
}

return $this->converter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ Highlighted block with multiple lines
Highlighted block with multiple lines</literallayout>
</ezcontent>
</eztemplate>
<eztemplate name="highlighted_block" type="style">
<ezcontent>
<literallayout>Highlighted block with multiple lines and emphasis
<emphasis role="strong">Highlighted block with multiple lines and emphasis</emphasis>
Highlighted block with multiple lines and emphasis</literallayout>
</ezcontent>
</eztemplate>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" data-ezalign="right">Highlighted block with "right" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" data-ezalign="center">Highlighted block with "center" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block">Highlighted block with multiple lines<br/>Highlighted block with multiple lines<br/>Highlighted block with multiple lines</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block">Highlighted block with multiple lines and emphasis<br/><strong>Highlighted block with multiple lines and emphasis</strong><br/>Highlighted block with multiple lines and emphasis</div>
</section>
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5"/>
<?xml version="1.0"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5">
<template-output is-inline="false" name="factbox" type="tag">
<param name="name">factbox</param>
<param name="params">
<param name="title">Factoids</param>
</param>
<param name="content">
<section>
<table title="tableTitle">
<caption>About factoids</caption>
<tbody>
<tr>
<th>
<h3 style="text-align:center;">Some facts about factoids</h3>
</th>
</tr>
<tr>
<td>
<p>A factoid is a questionable or spurious (unverified, false, or fabricated) statement presented as a fact, but without supporting evidence.</p>
</td>
</tr>
<tr>
<td>
<p>Factoids may give rise to, or arise from, common misconceptions and urban legends.</p>
</td>
</tr>
</tbody>
</table>
</section>
</param>
<param name="align">left</param>
</template-output>
<template-output is-inline="false" name="externalimage" type="tag">
<param name="name">externalimage</param>
<param name="params">
<param name="src">http://upload.wikimedia.org/wikipedia/commons/c/c6/R-S_mk2.gif</param>
<param name="height">365</param>
<param name="width">500</param>
<param name="alt">flip-flop</param>
<param name="caption">bistable multivibrator</param>
</param>
<param name="align">right</param>
</template-output>
<template-output is-inline="false" name="factoidbox" type="tag">
<param name="name">factoidbox</param>
<param name="content">
<section>It is widely known that the bistable multivibrator hums z's in the middle octave key of E.</section>
</param>
<param name="align">center</param>
</template-output>
<template-output is-inline="false" name="factoidbox" type="tag">
<param name="name">factoidbox</param>
<param name="align">center</param>
</template-output>
</section>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5">
<p>Some for the otherwise unremarkable paragraph.</p>
<p>This paragraph is just showing off its .</p>
<p>The equation ties together five of the most important mathematical constants.</p>
<p>This paragraph contains some .</p>
<p>Some <template-output is-inline="true" name="emojicake" type="tag"><param name="name">emojicake</param></template-output> for the otherwise unremarkable paragraph.</p>
<p>This paragraph is just showing off its <template-output is-inline="true" name="emojicrocodile" type="tag"><param name="name">emojicrocodile</param><param name="params"><param name="size">large</param></param></template-output>.</p>
<p>The equation <template-output is-inline="true" name="tex" type="tag"><param name="name">tex</param><param name="params"><param name="color">red</param></param><param name="content"><section>e^{\pi i}+1=0</section></param></template-output> ties together five of the most important mathematical constants.</p>
<p>This paragraph contains some <template-output is-inline="true" name="bold" type="tag"><param name="name">bold</param><param name="content"><section>styled <template-output is-inline="true" name="strikedthrough" type="tag"><param name="name">strikedthrough</param><param name="content"><section>text</section></param></template-output></section></param></template-output>.</p>
</section>
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5"/>
<?xml version="1.0"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5">
<template-output is-inline="false" name="highlighted_block" type="style">
<param name="name">highlighted_block</param>
<param name="content">
<section>Highlighted block with "left" align.</section>
</param>
<param name="align">left</param>
</template-output>
<template-output is-inline="false" name="highlighted_block" type="style">
<param name="name">highlighted_block</param>
<param name="content">
<section>Highlighted block with "right" align.</section>
</param>
<param name="align">right</param>
</template-output>
<template-output is-inline="false" name="highlighted_block" type="style">
<param name="name">highlighted_block</param>
<param name="content">
<section>Highlighted block with "center" align.</section>
</param>
<param name="align">center</param>
</template-output>
<template-output is-inline="false" name="highlighted_block" type="style">
<param name="name">highlighted_block</param>
<param name="content">
<section>Highlighted block with multiple lines<br/>Highlighted block with multiple lines<br/>Highlighted block with multiple lines</section>
</param>
</template-output>
<template-output is-inline="false" name="highlighted_block" type="style">
<param name="name">highlighted_block</param>
<param name="content">
<section>Highlighted block with multiple lines and emphasis<br/><strong>Highlighted block with multiple lines and emphasis</strong><br/>Highlighted block with multiple lines and emphasis</section>
</param>
</template-output>
</section>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5">
<p>Some for the otherwise unremarkable paragraph.</p>
<p>Some <template-output is-inline="true" name="highlighted_word" type="style"><param name="name">highlighted_word</param><param name="content"><section>highlighted words<br/>with line break</section></param></template-output> for the otherwise unremarkable paragraph.</p>
</section>
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5" />
<?xml version="1.0"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5">
<template-output is-inline="false" name="factbox" type="tag">
<param name="name">factbox</param>
<param name="params">
<param name="title">Factoids</param>
</param>
<param name="content">
<section>
<template-output is-inline="false" name="externalimage" type="tag">
<param name="name">externalimage</param>
<param name="params">
<param name="src">
http://upload.wikimedia.org/wikipedia/commons/c/c6/R-S_mk2.gif
</param>
<param name="height">365</param>
<param name="width">500</param>
<param name="alt">flip-flop</param>
<param name="caption">bistable multivibrator</param>
</param>
<param name="align">right</param>
</template-output>
</section>
</param>
<param name="align">left</param>
</template-output>
</section>
Loading

0 comments on commit c9399e5

Please sign in to comment.