From 7326397a5b8a4fac766762e0cf88f8ac78c41b64 Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Sat, 23 Sep 2023 10:31:58 +0200 Subject: [PATCH 1/2] [TASK] Move directives topic and wrap to GeneralDirectiveNode Add Integration tests for them and move the themes to guides-restructured text, these are rst-specific constructs --- .../html/body/directive/topic.html.twig | 20 ++++++++++ .../html/body/directive/wrap.html.twig | 5 +++ .../Directives/TopicDirective.php | 38 ------------------- .../Directives/WrapDirective.php | 31 --------------- .../tests/directive-topic/expected/index.html | 21 ++++++++++ .../tests/directive-topic/input/index.rst | 11 ++++++ .../tests/directive-wrap/expected/index.html | 16 ++++++++ .../tests/directive-wrap/input/index.rst | 7 ++++ 8 files changed, 80 insertions(+), 69 deletions(-) create mode 100644 packages/guides-restructured-text/resources/template/html/body/directive/topic.html.twig create mode 100644 packages/guides-restructured-text/resources/template/html/body/directive/wrap.html.twig delete mode 100644 packages/guides-restructured-text/src/RestructuredText/Directives/TopicDirective.php delete mode 100644 packages/guides-restructured-text/src/RestructuredText/Directives/WrapDirective.php create mode 100644 tests/Integration/tests/directive-topic/expected/index.html create mode 100644 tests/Integration/tests/directive-topic/input/index.rst create mode 100644 tests/Integration/tests/directive-wrap/expected/index.html create mode 100644 tests/Integration/tests/directive-wrap/input/index.rst diff --git a/packages/guides-restructured-text/resources/template/html/body/directive/topic.html.twig b/packages/guides-restructured-text/resources/template/html/body/directive/topic.html.twig new file mode 100644 index 000000000..ba8a88348 --- /dev/null +++ b/packages/guides-restructured-text/resources/template/html/body/directive/topic.html.twig @@ -0,0 +1,20 @@ +{# +A topic is like a block quote with a title, or a self-contained section with no subsections. Use the "topic" directive to indicate a self-contained idea that is separate from the flow of the document. Topics may occur anywhere a section or transition may occur. Body elements and topics may not contain nested topics. + +The directive's sole argument is interpreted as the topic title; the next line +must be blank. All subsequent lines make up the topic body, interpreted as body +elements. For example: + +.. topic:: Topic Title + + Subsequent indented lines comprise + the body of the topic, and are + interpreted as body elements. + +https://docutils.sourceforge.io/docs/ref/rst/directives.html#topic +#} + +
+

{{ renderNode(node.content) }}

+ {{ renderNode(node.value) }} +
diff --git a/packages/guides-restructured-text/resources/template/html/body/directive/wrap.html.twig b/packages/guides-restructured-text/resources/template/html/body/directive/wrap.html.twig new file mode 100644 index 000000000..ae8364ec2 --- /dev/null +++ b/packages/guides-restructured-text/resources/template/html/body/directive/wrap.html.twig @@ -0,0 +1,5 @@ +{%- if node.classes %} +
{{ renderNode(node.value) }}
+{% else %} + {{ renderNode(node.value) }} +{% endif -%} diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/TopicDirective.php b/packages/guides-restructured-text/src/RestructuredText/Directives/TopicDirective.php deleted file mode 100644 index 3fa3eba6c..000000000 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/TopicDirective.php +++ /dev/null @@ -1,38 +0,0 @@ -getData(), - $collectionNode->getChildren(), - ); - } - - public function getName(): string - { - return 'topic'; - } -} diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/WrapDirective.php b/packages/guides-restructured-text/src/RestructuredText/Directives/WrapDirective.php deleted file mode 100644 index 17c15c37b..000000000 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/WrapDirective.php +++ /dev/null @@ -1,31 +0,0 @@ - + + + Directive tests + + + +
+

Directive tests

+ + +
+

This is the topic

+

Lorem Ipsum Dolor

Some Rubric
+

Dolor sit!

+
+ +
+ + + diff --git a/tests/Integration/tests/directive-topic/input/index.rst b/tests/Integration/tests/directive-topic/input/index.rst new file mode 100644 index 000000000..9eaae2d78 --- /dev/null +++ b/tests/Integration/tests/directive-topic/input/index.rst @@ -0,0 +1,11 @@ +Directive tests +=============== + +.. topic:: This is the **topic** + :class: someClass + + Lorem Ipsum Dolor + + .. rubric:: Some Rubric + + Dolor sit! diff --git a/tests/Integration/tests/directive-wrap/expected/index.html b/tests/Integration/tests/directive-wrap/expected/index.html new file mode 100644 index 000000000..64cec7db6 --- /dev/null +++ b/tests/Integration/tests/directive-wrap/expected/index.html @@ -0,0 +1,16 @@ + + + + Directive tests + + + +
+

Directive tests

+ +

Lorem Ipsum Dolor

+ +
+ + + diff --git a/tests/Integration/tests/directive-wrap/input/index.rst b/tests/Integration/tests/directive-wrap/input/index.rst new file mode 100644 index 000000000..61c96f2af --- /dev/null +++ b/tests/Integration/tests/directive-wrap/input/index.rst @@ -0,0 +1,7 @@ +Directive tests +=============== + +.. wrap:: + :class: someClass + + Lorem Ipsum Dolor From 14e9e4de2b32226f5d2f4504d1f3c5891e3ad1ce Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Sat, 23 Sep 2023 10:39:49 +0200 Subject: [PATCH 2/2] [TASK] Let Directives with no node inherit form ActionDirective We have had ActionDirective since a while but didn't apply it to older existing directives --- .../RestructuredText/Directives/MetaDirective.php | 12 +++--------- .../RestructuredText/Directives/TitleDirective.php | 12 +++--------- .../RestructuredText/Directives/TodoDirective.php | 13 +++++-------- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/MetaDirective.php b/packages/guides-restructured-text/src/RestructuredText/Directives/MetaDirective.php index e501fbc80..b0fdd15be 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/MetaDirective.php +++ b/packages/guides-restructured-text/src/RestructuredText/Directives/MetaDirective.php @@ -5,7 +5,6 @@ namespace phpDocumentor\Guides\RestructuredText\Directives; use phpDocumentor\Guides\Nodes\Metadata\MetaNode; -use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\RestructuredText\Parser\BlockContext; use phpDocumentor\Guides\RestructuredText\Parser\Directive; @@ -15,24 +14,19 @@ * .. meta:: * :key: value */ -class MetaDirective extends BaseDirective +class MetaDirective extends ActionDirective { public function getName(): string { return 'meta'; } - /** {@inheritDoc} */ - public function process( - BlockContext $blockContext, - Directive $directive, - ): Node|null { + public function processAction(BlockContext $blockContext, Directive $directive): void + { $document = $blockContext->getDocumentParserContext()->getDocument(); foreach ($directive->getOptions() as $option) { $document->addHeaderNode(new MetaNode($option->getName(), (string) $option->getValue())); } - - return null; } } diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/TitleDirective.php b/packages/guides-restructured-text/src/RestructuredText/Directives/TitleDirective.php index 7ffdb64cb..78d96b3fe 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/TitleDirective.php +++ b/packages/guides-restructured-text/src/RestructuredText/Directives/TitleDirective.php @@ -4,7 +4,6 @@ namespace phpDocumentor\Guides\RestructuredText\Directives; -use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\RestructuredText\Parser\BlockContext; use phpDocumentor\Guides\RestructuredText\Parser\Directive; @@ -13,21 +12,16 @@ * * .. title:: Page title */ -class TitleDirective extends BaseDirective +class TitleDirective extends ActionDirective { public function getName(): string { return 'title'; } - /** {@inheritDoc} */ - public function process( - BlockContext $blockContext, - Directive $directive, - ): Node|null { + public function processAction(BlockContext $blockContext, Directive $directive): void + { $document = $blockContext->getDocumentParserContext()->getDocument(); $document->setMetaTitle($directive->getData()); - - return null; } } diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/TodoDirective.php b/packages/guides-restructured-text/src/RestructuredText/Directives/TodoDirective.php index ba5b43e0a..dcfb3f4e8 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/TodoDirective.php +++ b/packages/guides-restructured-text/src/RestructuredText/Directives/TodoDirective.php @@ -4,24 +4,21 @@ namespace phpDocumentor\Guides\RestructuredText\Directives; -use phpDocumentor\Guides\Nodes\CollectionNode; -use phpDocumentor\Guides\Nodes\Node; +use phpDocumentor\Guides\RestructuredText\Parser\BlockContext; use phpDocumentor\Guides\RestructuredText\Parser\Directive; /** * Todo directives are treated as comments, omitting all content or options */ -class TodoDirective extends SubDirective +class TodoDirective extends ActionDirective { public function getName(): string { return 'todo'; } - protected function processSub( - CollectionNode $collectionNode, - Directive $directive, - ): Node|null { - return null; + public function processAction(BlockContext $blockContext, Directive $directive): void + { + // Todo directives are treated as comments } }