-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7ec3d09
Showing
43 changed files
with
5,078 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor/ | ||
composer.lock |
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,108 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the EasyImpress package. | ||
* | ||
* (c) Alexandre Rock Ancelet <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Orbitale\Bundle\EasyImpressBundle\Configuration; | ||
|
||
use Symfony\Component\Config\Definition\Processor; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
class ConfigProcessor | ||
{ | ||
/** | ||
* @param string $file | ||
* | ||
* @return array[] | ||
*/ | ||
public function processConfigurationFile($file) | ||
{ | ||
$yamlArray = Yaml::parse(file_get_contents($file)); | ||
|
||
// Presentation name based on the file name. | ||
$yamlArray['name'] = basename($file, '.yml'); | ||
|
||
$processor = new Processor(); | ||
|
||
$presentationConfig = $processor->processConfiguration(new PresentationConfiguration(), [$yamlArray]); | ||
|
||
foreach ($presentationConfig['slides'] as $k => $slide) { | ||
if (!array_key_exists('id', $slide)) { | ||
if (!is_numeric($k)) { | ||
$slide['id'] = $k; | ||
} else { | ||
$slide['id'] = $presentationConfig['name'].'_'.$k; | ||
} | ||
} | ||
|
||
if (isset($presentationConfig['slides'][$slide['id']])) { | ||
throw new \RuntimeException('Duplicate slide id "'.$slide['id'].'" for presentation "'.$presentationConfig['name'].'".'); | ||
} | ||
|
||
$presentationConfig['slides'][$k] = $processor->processConfiguration(new SlideConfiguration(), [$slide]); | ||
} | ||
|
||
return $this->updatePresentationsConfigs($presentationConfig); | ||
} | ||
|
||
/** | ||
* @param array $config | ||
* | ||
* @return array[] | ||
*/ | ||
private function updatePresentationsConfigs(array $config) | ||
{ | ||
$presentation = []; | ||
|
||
$presentation['inactive_opacity'] = $config['inactive_opacity']; | ||
$presentation['attr'] = $config['attr']; | ||
$presentation['data'] = $config['data']; | ||
$presentation['name'] = $config['name']; | ||
|
||
$presentation['slides'] = []; | ||
$presentation['increments'] = $config['increments']; | ||
|
||
// We need to compute incrementation of the different coordinates. | ||
$baseIncrements = $presentation['increments']; | ||
$currentIncrementsArray = array_filter($baseIncrements); | ||
$incrementsToProcess = array_keys($currentIncrementsArray); | ||
|
||
$parseDown = class_exists('Parsedown') ? new \Parsedown() : null; | ||
|
||
$presentation['slides'] = []; | ||
|
||
foreach ($config['slides'] as $slideArray) { | ||
foreach ($incrementsToProcess as $dataKey) { | ||
// Check if we have to reset value before calculating incrementation values. | ||
if (array_key_exists($dataKey, $slideArray['reset']) && true === $slideArray['reset'][$dataKey]) { | ||
$currentIncrementsArray[$dataKey] = $baseIncrements[$dataKey]; | ||
} | ||
|
||
// Update slide values. | ||
$slideArray['data'][$dataKey] = $currentIncrementsArray[$dataKey]; | ||
|
||
// Update incrementation values. | ||
$currentIncrementsArray[$dataKey] += $baseIncrements[$dataKey]; | ||
} | ||
|
||
switch ($slideArray['content_type']) { | ||
case 'html': | ||
$slideArray['content'] = trim($slideArray['content']); | ||
break; | ||
case 'markdown': | ||
default: | ||
$slideArray['content'] = $parseDown ? $parseDown->text($slideArray['content']) : $slideArray['content']; | ||
} | ||
|
||
$presentation['slides'][] = $slideArray; | ||
} | ||
|
||
return $presentation; | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the EasyImpress package. | ||
* | ||
* (c) Alexandre Rock Ancelet <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Orbitale\Bundle\EasyImpressBundle\Configuration; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class PresentationConfiguration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('presentation'); | ||
|
||
$rootNode | ||
->children() | ||
->scalarNode('name')->isRequired()->end() | ||
|
||
->variableNode('slides')->end() | ||
|
||
->floatNode('inactive_opacity')->defaultValue(1)->end() | ||
|
||
->arrayNode('data') | ||
->addDefaultsIfNotSet() | ||
->normalizeKeys(false) | ||
->children() | ||
->integerNode('transition-duration')->defaultValue(1000)->end() | ||
->integerNode('min-scale')->defaultValue(1)->end() | ||
->end() | ||
->end() | ||
|
||
->arrayNode('attr') | ||
->addDefaultsIfNotSet() | ||
->normalizeKeys(false) | ||
->children() | ||
->scalarNode('style')->defaultValue('')->end() | ||
->scalarNode('class') | ||
->defaultValue('impress_slides_container') | ||
->validate() | ||
->always(function($v){ | ||
if (false === strpos($v, 'impress_slides_container')) { | ||
$v = trim('impress_slides_container '.$v); | ||
} | ||
|
||
return $v; | ||
}) | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
|
||
->arrayNode('increments') | ||
->addDefaultsIfNotSet() | ||
->normalizeKeys(false) | ||
->children() | ||
->integerNode('x')->defaultValue(null)->end() | ||
->integerNode('y')->defaultValue(null)->end() | ||
->integerNode('z')->defaultValue(null)->end() | ||
->integerNode('rotate')->defaultValue(null)->end() | ||
->integerNode('rotate-x')->defaultValue(null)->end() | ||
->integerNode('rotate-y')->defaultValue(null)->end() | ||
->integerNode('rotate-z')->defaultValue(null)->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,89 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the EasyImpress package. | ||
* | ||
* (c) Alexandre Rock Ancelet <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Orbitale\Bundle\EasyImpressBundle\Configuration; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* Validates one single Slide. | ||
*/ | ||
class SlideConfiguration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('slides'); | ||
|
||
$rootNode | ||
->children() | ||
->scalarNode('id')->isRequired()->end() | ||
|
||
->scalarNode('content_type')->defaultValue('markdown')->end() | ||
->scalarNode('content')->defaultValue(null)->end() | ||
|
||
->variableNode('extra')->defaultValue(null)->end() | ||
|
||
->arrayNode('data') | ||
->addDefaultsIfNotSet() | ||
->normalizeKeys(false) | ||
->children() | ||
->integerNode('x')->defaultValue(null)->end() | ||
->integerNode('y')->defaultValue(null)->end() | ||
->integerNode('z')->defaultValue(null)->end() | ||
->integerNode('rotate')->defaultValue(null)->end() | ||
->integerNode('rotate-x')->defaultValue(null)->end() | ||
->integerNode('rotate-y')->defaultValue(null)->end() | ||
->integerNode('rotate-z')->defaultValue(null)->end() | ||
->end() | ||
->end() | ||
|
||
->arrayNode('attr') | ||
->addDefaultsIfNotSet() | ||
->normalizeKeys(false) | ||
->children() | ||
->scalarNode('style')->defaultValue('')->end() | ||
->scalarNode('class') | ||
->defaultValue('step') | ||
->validate() | ||
->always(function($v){ | ||
if (false === strpos($v, 'step')) { | ||
$v = trim('step '.$v); | ||
} | ||
|
||
return $v; | ||
}) | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
|
||
->arrayNode('reset') | ||
->addDefaultsIfNotSet() | ||
->normalizeKeys(false) | ||
->children() | ||
->booleanNode('x')->defaultValue(false)->end() | ||
->booleanNode('y')->defaultValue(false)->end() | ||
->booleanNode('z')->defaultValue(false)->end() | ||
->booleanNode('rotate')->defaultValue(false)->end() | ||
->booleanNode('rotate-x')->defaultValue(false)->end() | ||
->booleanNode('rotate-y')->defaultValue(false)->end() | ||
->booleanNode('rotate-z')->defaultValue(false)->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,63 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the EasyImpress package. | ||
* | ||
* (c) Alexandre Rock Ancelet <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Orbitale\Bundle\EasyImpressBundle\Controller; | ||
|
||
use Orbitale\Bundle\EasyImpressBundle\Impress\EasyImpress; | ||
use Orbitale\Bundle\EasyImpressBundle\Model\Presentation; | ||
use Symfony\Bundle\TwigBundle\TwigEngine; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
class PresentationController | ||
{ | ||
/** | ||
* @var EasyImpress | ||
*/ | ||
private $impress; | ||
|
||
/** | ||
* @var TwigEngine | ||
*/ | ||
private $twig; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $layout; | ||
|
||
public function __construct($layout, EasyImpress $impress, TwigEngine $twig) | ||
{ | ||
$this->impress = $impress; | ||
$this->twig = $twig; | ||
$this->layout = $layout; | ||
} | ||
|
||
/** | ||
* @param string $presentationName | ||
* | ||
* @return Response | ||
*/ | ||
public function presentation($presentationName) | ||
{ | ||
/** @var Presentation $presentation */ | ||
$presentation = $this->impress->getPresentation($presentationName); | ||
|
||
if (!$presentation) { | ||
throw new NotFoundHttpException('Presentation "'.$presentationName.'" not found.'); | ||
} | ||
|
||
return $this->twig->renderResponse('@EasyImpress/presentation.html.twig', [ | ||
'layout' => $this->layout, | ||
'presentation' => $presentation, | ||
]); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Orbitale\Bundle\EasyImpressBundle\DependencyInjection\Compiler; | ||
|
||
use Orbitale\Bundle\EasyImpressBundle\Configuration\ConfigProcessor; | ||
use Symfony\Component\Config\Resource\FileResource; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
class PresentationsPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$finder = (new Finder()) | ||
->files() | ||
->name('*.yml') | ||
->in($container->getParameter('easy_impress.presentations_dir')) | ||
; | ||
|
||
$configProcessor = new ConfigProcessor(); | ||
|
||
$presentations = []; | ||
|
||
foreach ($finder as $file) { | ||
/** @var \SplFileInfo $file */ | ||
$container->addResource(new FileResource($file->getRealPath())); | ||
$presentations[$file->getBasename('.yml')] = $configProcessor->processConfigurationFile($file); | ||
} | ||
|
||
$container->setParameter('easy_impress.presentations', $presentations); | ||
} | ||
} |
Oops, something went wrong.