Skip to content
This repository was archived by the owner on Oct 29, 2018. It is now read-only.

Commit

Permalink
TASK: Remove special handling of content attribute in html-tags
Browse files Browse the repository at this point in the history
The special rule for-content attributes in html-tags is removed. The only supported way to define content of html-tags
is creating children that can be a single expression or a list of nodes or expressions.

Background. The special handling of the content-attributes always was was a bit strange and since the latest changes
allow child-content to be defined as a single expression instead of an array aswell it is
no longer needed.
  • Loading branch information
mficzel authored Jun 19, 2017
2 parents 5b3d3f3 + 806f8f2 commit 7a6064f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
25 changes: 6 additions & 19 deletions Classes/Service/AfxService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,20 @@ protected static function astNodeToFusion($payload, $indentation = '')
{
$tagName = $payload['identifier'];

$attributePrefix = null;
$attributePrefixExceptions = [];

// Tag
if (strpos($tagName, ':') !== false) {
// Named fusion-object
$fusion = $tagName . ' {' . PHP_EOL;
// Attributes are not prefixed
$attributePrefix = '';
} else {
// Neos.Fusion:Tag
$fusion = 'Neos.Fusion:Tag {' . PHP_EOL;
$fusion .= $indentation . self::INDENTATION .'tagName = \'' . $tagName . '\'' . PHP_EOL;

// Attributes are rendered as tag-attributes
$attributePrefix = 'attributes.';
$attributePrefixExceptions = ['content'];

$hasContent = false;
if ($payload['props'] && count($payload['props']) > 0) {
foreach ($payload['props'] as $propName => $prop) {
if ($propName == 'content') {
$hasContent = true;
}
}
}

if ($payload['selfClosing'] === true && $hasContent === false) {
// Self closing Tags stay self closing
if ($payload['selfClosing'] === true) {
$fusion .= $indentation . self::INDENTATION .'selfClosingTag = true' . PHP_EOL;
}
}
Expand All @@ -150,10 +139,8 @@ protected static function astNodeToFusion($payload, $indentation = '')
} else {
if ($propName{0} === '@') {
$fusionName = $propName;
} elseif ($attributePrefix && !in_array($propName, $attributePrefixExceptions)) {
$fusionName = $attributePrefix . $propName;
} else {
$fusionName = $propName;
$fusionName = $attributePrefix . $propName;
}
$propFusion = self::astToFusion($prop, $indentation . self::INDENTATION);
if ($propFusion !== null) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ All whitepaces around the outer elements are ignored. Whitepaces that are connec

### HTML-Tags (Tags without Namespace)

HTML-Tags are converted to `Neos.Fusion:Tag` Objects. All attributes except `content` are rendered as attributes and the content/children are directly rendered as property-names. All other attributes are rendered as tag-attributes.
HTML-Tags are converted to `Neos.Fusion:Tag` Objects. All attributes of the afx-tag are rendered as tag-attributes.

The following html:
```
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/AfxServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public function attributesInHtmlTagsAreConvertedToTagAttributes()
$expectedFusion = <<<'EOF'
Neos.Fusion:Tag {
tagName = 'h1'
content = 'bar'
selfClosingTag = true
attributes.content = 'bar'
attributes.class = 'fooo'
}
EOF;
Expand Down

0 comments on commit 7a6064f

Please sign in to comment.