motd configuration

This commit is contained in:
Patryk Szlagowski 2013-04-08 11:44:43 +02:00
parent 3b6e9da91a
commit 0eb538083a
6 changed files with 36 additions and 0 deletions

View File

@ -23,6 +23,12 @@ class Configuration implements ConfigurationInterface
->root('nelmio_api_doc') ->root('nelmio_api_doc')
->children() ->children()
->scalarNode('name')->defaultValue('API documentation')->end() ->scalarNode('name')->defaultValue('API documentation')->end()
->arrayNode('motd')
->addDefaultsIfNotSet()
->children()
->scalarNode('template')->defaultValue('NelmioApiDocBundle::Components/motd.html.twig')->end()
->end()
->end()
->arrayNode('request_listener') ->arrayNode('request_listener')
->beforeNormalization() ->beforeNormalization()
->ifTrue(function ($a) { return is_bool($a); }) ->ifTrue(function ($a) { return is_bool($a); })

View File

@ -28,6 +28,7 @@ class NelmioApiDocExtension extends Extension
$configuration = new Configuration(); $configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $configs); $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.api_name', $config['name']);
$container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']); $container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']);
$container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']); $container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']);

View File

@ -55,6 +55,11 @@ class HtmlFormatter extends AbstractFormatter
*/ */
private $authentication; private $authentication;
/**
* @var string
*/
private $motdTemplate;
/** /**
* @param array $authentication * @param array $authentication
*/ */
@ -119,6 +124,22 @@ class HtmlFormatter extends AbstractFormatter
$this->defaultRequestFormat = $format; $this->defaultRequestFormat = $format;
} }
/**
* @param string $motdTemplate
*/
public function setMotdTemplate($motdTemplate)
{
$this->motdTemplate = $motdTemplate;
}
/**
* @return string
*/
public function getMotdTemplate()
{
return $this->motdTemplate;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -162,6 +183,7 @@ class HtmlFormatter extends AbstractFormatter
'date' => date(DATE_RFC822), 'date' => date(DATE_RFC822),
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'), 'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
'motdTemplate' => $this->motdTemplate
); );
} }
} }

View File

@ -28,6 +28,9 @@
<call method="setTemplatingEngine"> <call method="setTemplatingEngine">
<argument type="service" id="templating" /> <argument type="service" id="templating" />
</call> </call>
<call method="setMotdTemplate">
<argument>%nelmio_api_doc.motd.template%</argument>
</call>
<call method="setApiName"> <call method="setApiName">
<argument>%nelmio_api_doc.api_name%</argument> <argument>%nelmio_api_doc.api_name%</argument>
</call> </call>

View File

@ -0,0 +1,3 @@
<p id="colophon">
Documentation auto-generated on {{ date }}
</p>

View File

@ -27,6 +27,7 @@
</div> </div>
<br style="clear: both;" /> <br style="clear: both;" />
</div> </div>
{% include motdTemplate %}
<div class="container" id="resources_container"> <div class="container" id="resources_container">
<ul id="resources"> <ul id="resources">
{% block content %}{% endblock %} {% block content %}{% endblock %}