Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f05016

Browse files
committedAug 4, 2016
assets:publish command
1 parent 2c79771 commit 6f05016

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed
 

‎README.md

+17
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ public function contactAction()
4343
]);
4444
}
4545
```
46+
47+
## Deployment
48+
49+
In production, you better have to pre-render all your templates to improve performances. To do that, you have to add Pug\PugSymfonyBundle\PugSymfonyBundle in your registered bundles.
50+
51+
In **app/AppKernel.php**, in the ```registerBundles()``` method, add the Pug bundle:
52+
```php
53+
public function registerBundles()
54+
{
55+
$bundles = [
56+
...
57+
new Pug\PugSymfonyBundle\PugSymfonyBundle(),
58+
];
59+
```
60+
61+
This will make the ```assets:publish``` command available, now each time you deploy your app, enter the command below:
62+
```php bin/console assets:publish --env=prod```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Jade\JadeSymfonyBundle\Command;
4+
5+
use Jade\Jade;
6+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class AssetsPublishCommand extends ContainerAwareCommand
11+
{
12+
protected function configure()
13+
{
14+
$this
15+
->setName('assets:publish')
16+
->setDescription('Export your assets in the web directory.')
17+
;
18+
}
19+
20+
protected function cacheTemplates(Jade $pug)
21+
{
22+
$success = 0;
23+
$errors = 0;
24+
$directories = array();
25+
foreach ($pug->getOption('assetDirectory') as $assetDirectory) {
26+
$viewDirectory = $assetDirectory . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views';
27+
if (!is_dir($viewDirectory)) {
28+
continue;
29+
}
30+
$directories[] = $viewDirectory;
31+
$data = $pug->cacheDirectory($viewDirectory);
32+
$success += $data[0];
33+
$errors += $data[1];
34+
}
35+
36+
return array($directories, $success, $errors);
37+
}
38+
39+
protected function execute(InputInterface $input, OutputInterface $output)
40+
{
41+
list($directories, $success, $errors) = $this->cacheTemplates(
42+
$this->getContainer()->get('templating.engine.pug')->getEngine()
43+
);
44+
$count = count($directories);
45+
$output->writeln($count . ' ' . ($count === 1 ? 'directory' : 'directories') . ' scanned: ' . implode(', ', $directories) . '.');
46+
$output->writeln($success . ' templates cached.');
47+
$output->writeln($errors . ' templates failed to be cached.');
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Jade\JadeSymfonyBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class JadeSymfonyBundle extends Bundle
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Pug\PugSymfonyBundle\Command;
4+
5+
use Jade\JadeSymfonyBundle\Command\AssetsPublishCommand as Command;
6+
7+
class AssetsPublishCommand extends Command
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Pug\PugSymfonyBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class PugSymfonyBundle extends Bundle
8+
{
9+
}

0 commit comments

Comments
 (0)