Skip to content

Commit

Permalink
assets:publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Aug 4, 2016
1 parent 2c79771 commit 6f05016
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,20 @@ public function contactAction()
]);
}
```

## Deployment

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.

In **app/AppKernel.php**, in the ```registerBundles()``` method, add the Pug bundle:
```php
public function registerBundles()
{
$bundles = [
...
new Pug\PugSymfonyBundle\PugSymfonyBundle(),
];
```

This will make the ```assets:publish``` command available, now each time you deploy your app, enter the command below:
```php bin/console assets:publish --env=prod```
49 changes: 49 additions & 0 deletions src/Jade/JadeSymfonyBundle/Command/AssetsPublishCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Jade\JadeSymfonyBundle\Command;

use Jade\Jade;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class AssetsPublishCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('assets:publish')
->setDescription('Export your assets in the web directory.')
;
}

protected function cacheTemplates(Jade $pug)
{
$success = 0;
$errors = 0;
$directories = array();
foreach ($pug->getOption('assetDirectory') as $assetDirectory) {
$viewDirectory = $assetDirectory . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views';
if (!is_dir($viewDirectory)) {
continue;
}
$directories[] = $viewDirectory;
$data = $pug->cacheDirectory($viewDirectory);
$success += $data[0];
$errors += $data[1];
}

return array($directories, $success, $errors);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
list($directories, $success, $errors) = $this->cacheTemplates(
$this->getContainer()->get('templating.engine.pug')->getEngine()
);
$count = count($directories);
$output->writeln($count . ' ' . ($count === 1 ? 'directory' : 'directories') . ' scanned: ' . implode(', ', $directories) . '.');
$output->writeln($success . ' templates cached.');
$output->writeln($errors . ' templates failed to be cached.');
}
}
9 changes: 9 additions & 0 deletions src/Jade/JadeSymfonyBundle/JadeSymfonyBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Jade\JadeSymfonyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class JadeSymfonyBundle extends Bundle
{
}
9 changes: 9 additions & 0 deletions src/Pug/PugSymfonyBundle/Command/AssetsPublishCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Pug\PugSymfonyBundle\Command;

use Jade\JadeSymfonyBundle\Command\AssetsPublishCommand as Command;

class AssetsPublishCommand extends Command
{
}
9 changes: 9 additions & 0 deletions src/Pug/PugSymfonyBundle/PugSymfonyBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Pug\PugSymfonyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class PugSymfonyBundle extends Bundle
{
}

0 comments on commit 6f05016

Please sign in to comment.