Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Move tip admonition from doctrine/doctrine-website #186

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/Directives/Admonition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Doctrine\RST\Directives;

use Doctrine\RST\Nodes\Node;
use Doctrine\RST\Nodes\WrapperNode;
use Doctrine\RST\Parser;

use function sprintf;

class Admonition extends SubDirective
{
/** @var string */
private $name;

/** @var string */
private $backgroundColor;

/** @var string */
private $textColor;

/** @var string */
private $icon;

public function __construct(string $name, string $backgroundColor, string $textColor, string $icon)
{
$this->name = $name;
$this->backgroundColor = $backgroundColor;
$this->textColor = $textColor;
$this->icon = $icon;
}

public function getName(): string
{
return $this->name;
}

/** @param string[] $options */
public function processSub(
Parser $parser,
?Node $document,
string $variable,
string $data,
array $options
): ?Node {
return new WrapperNode($document, sprintf(
'<div class="alert %s-admonition %s %s border"><table width="100%%"><tr><td width="10" class="align-top"><i class="%s mr-2"></i></td><td>',
$this->name,
$this->backgroundColor,
$this->textColor,
$this->icon
), '</td></tr></table></div>');
}
}
13 changes: 13 additions & 0 deletions lib/Directives/Tip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Doctrine\RST\Directives;

class Tip extends Admonition
{
public function __construct()
{
parent::__construct('tip', 'bg-success', 'text-light', 'fas fa-question-circle');
}
}
1 change: 1 addition & 0 deletions lib/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(
new Directives\CodeBlock(),
new Directives\Raw(),
new Directives\Replace(),
new Directives\Tip(),
new Directives\Toctree(),
], $this->configuration->getFormat()->getDirectives(), $directives);

Expand Down
12 changes: 12 additions & 0 deletions tests/Functional/tests/tip-multiline/tip-multiline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="alert tip-admonition bg-success text-light border">
<table width="100%">
<tr>
<td width="10" class="align-top"><i class="fas fa-question-circle mr-2"></i></td>
<td>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</p>
</td>
</tr>
</table>
</div>
5 changes: 5 additions & 0 deletions tests/Functional/tests/tip-multiline/tip-multiline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. tip::

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
10 changes: 10 additions & 0 deletions tests/Functional/tests/tip/tip.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="alert tip-admonition bg-success text-light border">
<table width="100%">
<tr>
<td width="10" class="align-top"><i class="fas fa-question-circle mr-2"></i></td>
<td>
<p>This is a tip</p>
</td>
</tr>
</table>
</div>
2 changes: 2 additions & 0 deletions tests/Functional/tests/tip/tip.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. tip::
This is a tip