Skip to content
Browse files

Moved the rendering to the formatter

  • Loading branch information...
1 parent e6a99da commit 496c31b451d21e91cd2cb34a2ae56b192f7dd62a @baldurrensch committed
Showing with 14 additions and 8 deletions.
  1. +1 −8 Annotation/ApiDoc.php
  2. +13 −0 Formatter/HtmlFormatter.php
View
9 Annotation/ApiDoc.php
@@ -12,7 +12,6 @@
namespace Nelmio\ApiDocBundle\Annotation;
use Symfony\Component\Routing\Route;
-use dflydev\markdown\MarkdownParser;
/**
* @Annotation
@@ -331,13 +330,7 @@ public function toArray()
}
if ($fileToInclude = $this->fileToInclude) {
- if (!is_readable($fileToInclude)) {
- throw new \InvalidArgumentException("Could not open: {$fileToInclude}");
- }
-
- $mdParser = new MarkdownParser();
- $fileContents = file_get_contents($fileToInclude);
- $data['fileToInclude'] = $mdParser->transform($fileContents);
+ $data['fileToInclude'] = $fileToInclude;
}
return $data;
View
13 Formatter/HtmlFormatter.php
@@ -12,6 +12,7 @@
namespace Nelmio\ApiDocBundle\Formatter;
use Symfony\Component\Templating\EngineInterface;
+use dflydev\markdown\MarkdownParser;
class HtmlFormatter extends AbstractFormatter
{
@@ -82,9 +83,21 @@ public function setTemplatingEngine(EngineInterface $engine)
/**
* {@inheritdoc}
+ * @throws \InvalidArgumentException if the file to be included cannot be loaded.
*/
protected function renderOne(array $data)
{
+ if (!empty($data['fileToInclude'])) {
+ if (!is_readable($data['fileToInclude'])) {
+ throw new \InvalidArgumentException("Could not open: {$fileToInclude}");
+ }
+
+ $mdParser = new MarkdownParser();
+ $fileContents = file_get_contents($data['fileToInclude']);
+ $data['fileToInclude'] = $mdParser->transform($fileContents);
+
+ }
+
return $this->engine->render('NelmioApiDocBundle::resource.html.twig', array_merge(
array('data' => $data, 'displayContent' => true),
$this->getGlobalVars()

0 comments on commit 496c31b

Please sign in to comment.
Something went wrong with that request. Please try again.