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

Replace hardcoded html with twig templates. #53

Merged
merged 1 commit into from
Nov 16, 2018
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
6 changes: 6 additions & 0 deletions lib/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\RST\NodeFactory\NodeFactory;
use Doctrine\RST\References\Reference;
use Doctrine\RST\References\ResolvedReference;
use Doctrine\RST\Templates\TemplateRenderer;
use InvalidArgumentException;
use function array_shift;
use function dirname;
Expand Down Expand Up @@ -125,6 +126,11 @@ public function getNodeFactory() : NodeFactory
return $this->configuration->getNodeFactory();
}

public function getTemplateRenderer() : TemplateRenderer
{
return $this->configuration->getTemplateRenderer();
}

public function registerReference(Reference $reference) : void
{
$this->references[$reference->getName()] = $reference;
Expand Down
7 changes: 3 additions & 4 deletions lib/Nodes/DocumentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Exception;
use function array_unshift;
use function count;
use function htmlspecialchars;
use function is_string;
use function sprintf;

Expand Down Expand Up @@ -183,7 +182,7 @@ public function addCss(string $css) : void
}

$this->addHeaderNode($this->environment->getNodeFactory()->createRawNode(
'<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($css) . '" />'
$this->environment->getTemplateRenderer()->render('stylesheet-link.html.twig', ['css' => $css])
));
}

Expand All @@ -196,7 +195,7 @@ public function addJs(string $js) : void
}

$this->addHeaderNode($this->environment->getNodeFactory()->createRawNode(
'<script type="text/javascript" src="' . htmlspecialchars($js) . '"></script>'
$this->environment->getTemplateRenderer()->render('javascript.html.twig', ['js' => $js])
));
}

Expand All @@ -209,7 +208,7 @@ public function addFavicon(string $url = '/favicon.ico') : void
}

$this->addHeaderNode($this->environment->getNodeFactory()->createRawNode(
'<link rel="icon" type="image/x-icon" href="' . htmlspecialchars($url) . '" />'
$this->environment->getTemplateRenderer()->render('favicon.html.twig', ['url' => $url])
));
}

Expand Down
1 change: 1 addition & 0 deletions lib/Templates/default/html/favicon.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="icon" type="image/x-icon" href="{{ url }}" />
1 change: 1 addition & 0 deletions lib/Templates/default/html/javascript.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script type="text/javascript" src="{{ js }}"></script>
1 change: 1 addition & 0 deletions lib/Templates/default/html/stylesheet-link.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<link rel="stylesheet" type="text/css" href="{{ css }}" />