Add AppBundle and the YouTube and Vimeo Twig functions

This commit is contained in:
Oliver Davies 2016-03-28 19:11:12 +01:00
parent 2f7d9de95b
commit 3cb4e74448
11 changed files with 134 additions and 5 deletions

View file

@ -14,7 +14,8 @@ class SculpinKernel extends AbstractKernel
{ {
return [ return [
'Tsphethean\Sculpin\Bundle\RelatedPostsBundle\SculpinRelatedPostsBundle', 'Tsphethean\Sculpin\Bundle\RelatedPostsBundle\SculpinRelatedPostsBundle',
'Opdavies\Sculpin\Bundle\ContentGeneratorBundle\SculpinContentGeneratorBundle' 'Opdavies\Sculpin\Bundle\ContentGeneratorBundle\SculpinContentGeneratorBundle',
'AppBundle\AppBundle'
]; ];
} }
} }

View file

@ -19,5 +19,10 @@
"behat/mink-extension": "*", "behat/mink-extension": "*",
"behat/mink-goutte-driver": "*", "behat/mink-goutte-driver": "*",
"opdavies/sculpin-content-generator-bundle": "@stable" "opdavies/sculpin-content-generator-bundle": "@stable"
},
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle"
}
} }
} }

View file

@ -14,5 +14,5 @@ tags:
- unified-diff - unified-diff
--- ---
{% block video %} {% 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 %} {% endblock %}

View file

@ -22,7 +22,7 @@ tweets: yes
{% endblock %} {% endblock %}
{% block video %} {% block video %}
<iframe width="560" height="315" src="https://www.youtube.com/embed/T-miCpHxfds" frameborder="0" allowfullscreen></iframe> {{ youtube('T-miCpHxfds')|raw }}
{% endblock %} {% endblock %}
{% block feedback %} {% block feedback %}

View file

@ -27,7 +27,7 @@ I categorised the technical changes into groups for site builders, developers an
{% endblock %} {% endblock %}
{% block video %} {% block video %}
<iframe width="560" height="315" src="https://www.youtube.com/embed/36zCxPrOOzM" frameborder="0" allowfullscreen></iframe> {{ youtube('36zCxPrOOzM')|raw }}
{% endblock %} {% endblock %}
{% block feedback %} {% block feedback %}

View file

@ -28,7 +28,7 @@ You can [view the full slides](/slides/phpsw/building-static-websites-with-sculp
{% endblock %} {% endblock %}
{% block video %} {% block video %}
<iframe width="560" height="315" src="https://www.youtube.com/embed/aN53arCKZAU" frameborder="0" allowfullscreen></iframe> {{ youtube('aN53arCKZAU')|raw }}
{% endblock %} {% endblock %}
{% block feedback %} {% block feedback %}

View file

@ -0,0 +1,9 @@
<?php
namespace AppBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppBundle extends Bundle
{
}

View 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');
}
}

View 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';
}
}

View 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';
}
}

View 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 }