Add AppBundle and the YouTube and Vimeo Twig functions
This commit is contained in:
parent
2f7d9de95b
commit
3cb4e74448
|
@ -14,7 +14,8 @@ class SculpinKernel extends AbstractKernel
|
|||
{
|
||||
return [
|
||||
'Tsphethean\Sculpin\Bundle\RelatedPostsBundle\SculpinRelatedPostsBundle',
|
||||
'Opdavies\Sculpin\Bundle\ContentGeneratorBundle\SculpinContentGeneratorBundle'
|
||||
'Opdavies\Sculpin\Bundle\ContentGeneratorBundle\SculpinContentGeneratorBundle',
|
||||
'AppBundle\AppBundle'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,5 +19,10 @@
|
|||
"behat/mink-extension": "*",
|
||||
"behat/mink-goutte-driver": "*",
|
||||
"opdavies/sculpin-content-generator-bundle": "@stable"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"AppBundle\\": "src/AppBundle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ tags:
|
|||
- unified-diff
|
||||
---
|
||||
{% block video %}
|
||||
<iframe src="https://player.vimeo.com/video/49827006?title=0&portrait=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
||||
{{ vimeo('49827006')|raw }}
|
||||
{% endblock %}
|
||||
|
|
|
@ -22,7 +22,7 @@ tweets: yes
|
|||
{% endblock %}
|
||||
|
||||
{% block video %}
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/T-miCpHxfds" frameborder="0" allowfullscreen></iframe>
|
||||
{{ youtube('T-miCpHxfds')|raw }}
|
||||
{% endblock %}
|
||||
|
||||
{% block feedback %}
|
||||
|
|
|
@ -27,7 +27,7 @@ I categorised the technical changes into groups for site builders, developers an
|
|||
{% endblock %}
|
||||
|
||||
{% block video %}
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/36zCxPrOOzM" frameborder="0" allowfullscreen></iframe>
|
||||
{{ youtube('36zCxPrOOzM')|raw }}
|
||||
{% endblock %}
|
||||
|
||||
{% block feedback %}
|
||||
|
|
|
@ -28,7 +28,7 @@ You can [view the full slides](/slides/phpsw/building-static-websites-with-sculp
|
|||
{% endblock %}
|
||||
|
||||
{% block video %}
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/aN53arCKZAU" frameborder="0" allowfullscreen></iframe>
|
||||
{{ youtube('aN53arCKZAU')|raw }}
|
||||
{% endblock %}
|
||||
|
||||
{% block feedback %}
|
||||
|
|
9
src/AppBundle/AppBundle.php
Normal file
9
src/AppBundle/AppBundle.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class AppBundle extends Bundle
|
||||
{
|
||||
}
|
20
src/AppBundle/DependencyInjection/AppExtension.php
Normal file
20
src/AppBundle/DependencyInjection/AppExtension.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class AppExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
41
src/AppBundle/Twig/VimeoExtension.php
Normal file
41
src/AppBundle/Twig/VimeoExtension.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Twig;
|
||||
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
class VimeoExtension extends Twig_Extension
|
||||
{
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_SimpleFunction('vimeo', [$this, 'embedCode'])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the embed code for a video.
|
||||
*
|
||||
* @param $videoId
|
||||
* The ID of the video.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function embedCode($videoId)
|
||||
{
|
||||
return sprintf(
|
||||
'<iframe src="https://player.vimeo.com/video/%s?title=0&portrait=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>',
|
||||
$videoId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'vimeo';
|
||||
}
|
||||
|
||||
}
|
44
src/AppBundle/Twig/YouTubeExtension.php
Normal file
44
src/AppBundle/Twig/YouTubeExtension.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\Twig;
|
||||
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
class YouTubeExtension extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new Twig_SimpleFunction('youtube', [$this, 'embedCode'])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the embed code for a video.
|
||||
*
|
||||
* @param $videoId
|
||||
* The ID of the video.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function embedCode($videoId)
|
||||
{
|
||||
return sprintf(
|
||||
'<iframe width="560" height="315" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>',
|
||||
$videoId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'youtube';
|
||||
}
|
||||
|
||||
}
|
9
src/AppBundle/config/services.yml
Normal file
9
src/AppBundle/config/services.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
app.twig.vimeo:
|
||||
class: AppBundle\Twig\VimeoExtension
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
app.twig.youtube:
|
||||
class: AppBundle\Twig\YouTubeExtension
|
||||
tags:
|
||||
- { name: twig.extension }
|
Reference in a new issue