From 0eb538083a2332ad404039448b1ce8bd81d3ff72 Mon Sep 17 00:00:00 2001 From: Patryk Szlagowski Date: Mon, 8 Apr 2013 11:44:43 +0200 Subject: [PATCH] motd configuration --- DependencyInjection/Configuration.php | 6 +++++ DependencyInjection/NelmioApiDocExtension.php | 1 + Formatter/HtmlFormatter.php | 22 +++++++++++++++++++ Resources/config/formatters.xml | 3 +++ Resources/views/Components/motd.html.twig | 3 +++ Resources/views/layout.html.twig | 1 + 6 files changed, 36 insertions(+) create mode 100644 Resources/views/Components/motd.html.twig diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 50550a3..7a90cb6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,6 +23,12 @@ class Configuration implements ConfigurationInterface ->root('nelmio_api_doc') ->children() ->scalarNode('name')->defaultValue('API documentation')->end() + ->arrayNode('motd') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('template')->defaultValue('NelmioApiDocBundle::Components/motd.html.twig')->end() + ->end() + ->end() ->arrayNode('request_listener') ->beforeNormalization() ->ifTrue(function ($a) { return is_bool($a); }) diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 2718679..ce10263 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -28,6 +28,7 @@ class NelmioApiDocExtension extends Extension $configuration = new Configuration(); $config = $processor->processConfiguration($configuration, $configs); + $container->setParameter('nelmio_api_doc.motd.template', $config['motd']['template']); $container->setParameter('nelmio_api_doc.api_name', $config['name']); $container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']); $container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']); diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 9d5449f..d4520fc 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -55,6 +55,11 @@ class HtmlFormatter extends AbstractFormatter */ private $authentication; + /** + * @var string + */ + private $motdTemplate; + /** * @param array $authentication */ @@ -119,6 +124,22 @@ class HtmlFormatter extends AbstractFormatter $this->defaultRequestFormat = $format; } + /** + * @param string $motdTemplate + */ + public function setMotdTemplate($motdTemplate) + { + $this->motdTemplate = $motdTemplate; + } + + /** + * @return string + */ + public function getMotdTemplate() + { + return $this->motdTemplate; + } + /** * {@inheritdoc} */ @@ -162,6 +183,7 @@ class HtmlFormatter extends AbstractFormatter 'date' => date(DATE_RFC822), 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), 'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'), + 'motdTemplate' => $this->motdTemplate ); } } diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index 98f29c5..8a21d80 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -28,6 +28,9 @@ + + %nelmio_api_doc.motd.template% + %nelmio_api_doc.api_name% diff --git a/Resources/views/Components/motd.html.twig b/Resources/views/Components/motd.html.twig new file mode 100644 index 0000000..db686d5 --- /dev/null +++ b/Resources/views/Components/motd.html.twig @@ -0,0 +1,3 @@ +

+ Documentation auto-generated on {{ date }} +

\ No newline at end of file diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 967c105..6f2c29d 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -27,6 +27,7 @@
+ {% include motdTemplate %}