Skip to content

Commit

Permalink
Refactor CSS rulesets
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed May 26, 2021
1 parent a2c6db1 commit 1ba80ec
Show file tree
Hide file tree
Showing 721 changed files with 5,500 additions and 545 deletions.
8 changes: 6 additions & 2 deletions bin/src/Validator/SpecGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public function generate($jsonSpec, $rootNamespace, $destination)
$jsonSpec = $this->adaptJsonSpec($jsonSpec);
$specRuleKeys = $this->collectSpecRuleKeys($jsonSpec);

$this->generateEntityClass('Tag', $fileManager);
$this->generateEntityClass('AttributeList', $fileManager);
$this->generateEntityClass('DeclarationList', $fileManager);
$this->generateEntityClass('DescendantTagList', $fileManager);
$this->generateEntityClass('CssRuleset', $fileManager);
$this->generateEntityClass('Tag', $fileManager);
$this->generateEntityClass('TagWithExtensionSpec', $fileManager, 'interface');
$this->generateEntityClass('ExtensionSpec', $fileManager, 'trait');
$this->generateEntityClass('IterableSection', $fileManager, 'interface');
Expand Down Expand Up @@ -217,6 +218,9 @@ private function generateErrorCodeInterface($jsonSpec, FileManager $fileManager)
*/
private function adaptJsonSpec($jsonSpec)
{
$jsonSpec['cssRulesets'] = $jsonSpec['cssRulesets'];
unset($jsonSpec['cssRulesets']);

$jsonSpec['attributeLists'] = $jsonSpec['attrLists'];
unset($jsonSpec['attrLists']);

Expand Down Expand Up @@ -267,7 +271,7 @@ private function collectSpecRuleKeys($jsonSpec)
}
}
break;
case 'css':
case 'cssRulesets':
case 'doc':
case 'errors':
foreach ($sectionData as $ruleset) {
Expand Down
25 changes: 23 additions & 2 deletions bin/src/Validator/SpecGenerator/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function ensureDirectoriesExist()
$this->destination,
"{$this->destination}/Spec",
"{$this->destination}/Spec/AttributeList",
"{$this->destination}/Spec/CssRuleset",
"{$this->destination}/Spec/DeclarationList",
"{$this->destination}/Spec/DescendantTagList",
"{$this->destination}/Spec/Section",
Expand Down Expand Up @@ -291,6 +292,14 @@ private function getFullyQualifiedName($class)
return $class;
}

if (strpos($class, 'Tag\\') === 0) {
return "AmpProject\\Validator\\Spec\\Tag";
}

if (strpos($class, 'CssSpecRule\\') === 0) {
return "AmpProject\\Validator\\Spec\\CssSpecRule";
}

if (strpos($class, 'AttributeList\\') === 0) {
return "AmpProject\\Validator\\Spec\\AttributeList";
}
Expand All @@ -303,11 +312,23 @@ private function getFullyQualifiedName($class)
return "AmpProject\\Validator\\Spec\\DescendantTagList";
}

if (in_array($class, ['AttributeList', 'DeclarationList', 'DescendantTagList', 'SpecRule'], true)) {
if (
in_array(
$class,
['AttributeList', 'CssRuleset', 'DeclarationList', 'DescendantTagList', 'SpecRule'],
true
)
) {
return "AmpProject\\Validator\\Spec\\{$class}";
}

if (in_array($class, ['AttributeLists', 'DeclarationLists', 'DescendantTagLists'], true)) {
if (
in_array(
$class,
['AttributeLists', 'CssRulesets', 'DeclarationLists', 'DescendantTagLists', 'Tags'],
true
)
) {
return "AmpProject\\Validator\\Spec\\Section\\{$class}";
}

Expand Down
132 changes: 0 additions & 132 deletions bin/src/Validator/SpecGenerator/Section/Css.php

This file was deleted.

Loading

0 comments on commit 1ba80ec

Please sign in to comment.