-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Assetic dependency and add configuration
- Loading branch information
Florens Verschelde
committed
Sep 23, 2016
1 parent
3442702
commit 8b464e9
Showing
14 changed files
with
145 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Gradientz\TwigExpressBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
|
||
class Configuration implements ConfigurationInterface { | ||
|
||
public function getConfigTreeBuilder() { | ||
$treeBuilder = new TreeBuilder(); | ||
$treeBuilder->root('twig_express') | ||
->children() | ||
->arrayNode('bundles') | ||
->info('List of enabled bundles, with optional per-bundle config') | ||
->prototype('array') | ||
->beforeNormalization() | ||
->ifString()->then(function($v) { return ['name' => $v]; }) | ||
->end() | ||
->children() | ||
->scalarNode('name') | ||
->info('Bundle name') | ||
->isRequired() | ||
->end() | ||
->scalarNode('slug') | ||
->info('Short name to use in the URL') | ||
->defaultValue(null) | ||
->end() | ||
->scalarNode('root') | ||
->info('Document root folder from the bundle') | ||
->defaultValue('Resources/views/static') | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end(); | ||
return $treeBuilder; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Gradientz\TwigExpressBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
|
||
|
||
class GradientzTwigExpressExtension extends Extension { | ||
|
||
public function getAlias() { | ||
return 'twig_express'; | ||
} | ||
|
||
public function load(array $configs, ContainerBuilder $container) { | ||
$config = $this->processConfiguration(new Configuration(), $configs); | ||
|
||
// Make sure we have a base_url parameter so we can use it in routes | ||
$baseUrl = $container->getParameter('twig_express.base_url'); | ||
if (is_string($baseUrl)) $baseUrl = trim($baseUrl, '/'); | ||
if (!$baseUrl) $container->setParameter('twig_express.base_url', 'static'); | ||
|
||
// Expose configured bundle information | ||
// (Is there a better way to get access to our config from controllers???) | ||
$bundles = []; | ||
foreach($config['bundles'] as $item) { | ||
$name = $item['name']; | ||
$slug = $item['slug']; | ||
// Create slug if necessary, and clean it up | ||
if (!$slug) { | ||
$slug = strtolower($name); | ||
if (substr($slug, -6) === 'bundle') $slug = substr($slug, 0, -6); | ||
} | ||
$slug = str_replace('/', '', $slug); | ||
$root = trim($item['root'], '/'); | ||
if (!array_key_exists($slug, $bundles)) { | ||
$bundles[$slug] = ['name' => $name, 'root' => $root]; | ||
} | ||
} | ||
$container->setParameter('twig_express.bundles', $bundles); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
# Enable bundle for Assetic and GradientzTwigExpressBundle use | ||
assetic: | ||
bundles: [ GradientzTwigExpressBundle ] | ||
# REQUIRED: enable this bundle to be used with GradientzTwigExpressBundle | ||
twig_express: | ||
bundles: | ||
- name: GradientzTwigExpressBundle | ||
slug: twig-express-demo | ||
root: Resources/views/demo | ||
|
||
# (Optional) Add to Twig global variables, using a namespace to avoid collisions | ||
# (especially if you have more than one bundle with 'static' views). | ||
twig: | ||
globals: | ||
gradientz_twig_express: | ||
twig_express_demo: | ||
test: 'It works.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
gradientz_twig_express_root: | ||
path: "/static/" | ||
path: "/%twig_express.base_url%/" | ||
defaults: | ||
_controller: GradientzTwigExpressBundle:Static:root | ||
|
||
gradientz_twig_express_find: | ||
path: "/static/{bundle}{path}" | ||
path: "/%twig_express.base_url%/{slug}{path}" | ||
defaults: | ||
_controller: GradientzTwigExpressBundle:Static:find | ||
requirements: | ||
bundle: "[A-Za-z0-9_]+" | ||
slug: "[A-Za-z0-9_-]+" | ||
path: "(\\/?[\\/\\.A-Za-z0-9_-]+)?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include '@GradientzTwigExpress/demo/includes/error.twig' %} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.