Skip to content

Commit

Permalink
Merge pull request #22 from ninsuo/add-strict-variables-support
Browse files Browse the repository at this point in the history
added strict variables support, fixes #21
  • Loading branch information
ninsuo authored Dec 21, 2016
2 parents 35c6cee + 50ff07c commit 29eed95
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
1 change: 0 additions & 1 deletion cli/config/services/managers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ services:
fiddle_agent:
class: '%fiddle_agent.class%'
arguments: ['@error_manager']
shared: false

error_manager:
class: '%error_manager.class%'
Expand Down
7 changes: 5 additions & 2 deletions cli/src/Fuz/Process/TwigEngine/V1TwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public function load($sourceDirectory, $cacheDirectory, $executionDirectory)
require $sourceDirectory.DIRECTORY_SEPARATOR.'/lib/Twig/Autoloader.php';
\Twig_Autoloader::register();

$twigLoader = new \Twig_Loader_Filesystem($executionDirectory, $cacheDirectory);
$twigEnvironment = new \Twig_Environment($twigLoader, array('cache' => $cacheDirectory));
$twigLoader = new \Twig_Loader_Filesystem($executionDirectory, $cacheDirectory);
$twigEnvironment = new \Twig_Environment($twigLoader, array(
'cache' => $cacheDirectory,
'strict_variables' => $this->agent->getFiddle()->isWithStrictVariables(),
));

return $twigEnvironment;
}
Expand Down
5 changes: 4 additions & 1 deletion cli/src/Fuz/Process/TwigEngine/V2TwigEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public function load($sourceDirectory, $cacheDirectory, $executionDirectory)
});

$twigLoader = new \Twig_Loader_Filesystem($executionDirectory);
$twigEnvironment = new \Twig_Environment($twigLoader, array('cache' => $cacheDirectory));
$twigEnvironment = new \Twig_Environment($twigLoader, array(
'cache' => $cacheDirectory,
'strict_variables' => $this->agent->getFiddle()->isWithStrictVariables(),
));

return $twigEnvironment;
}
Expand Down
28 changes: 28 additions & 0 deletions web/src/Fuz/AppBundle/Entity/Fiddle.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ class Fiddle implements TagContainerInterface
*/
protected $withCExtension = false;

/**
* @var bool
*
* @ORM\Column(name="with_strict_variables", type="boolean")
* @Serializer\Type("boolean")
*/
protected $withStrictVariables = false;

/**
* @ORM\Column(name="twig_extension", type="string", length=32, nullable=true)
* @Serializer\Type("string")
Expand Down Expand Up @@ -402,6 +410,26 @@ public function isWithCExtension()
return $this->withCExtension;
}

/**
* @param bool $withStrictVariables
*
* @return Fiddle
*/
public function setWithStrictVariables($withStrictVariables)
{
$this->withStrictVariables = $withStrictVariables;

return $this;
}

/**
* @return bool
*/
public function isWithStrictVariables()
{
return $this->withStrictVariables;
}

/**
* @param string $twigExtension
*
Expand Down
3 changes: 3 additions & 0 deletions web/src/Fuz/AppBundle/Form/FiddleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public function buildFiddleOptions(FormBuilderInterface $builder, array $options
->add('withCExtension', Type\CheckboxType::class, array(
'required' => false,
))
->add('withStrictVariables', Type\CheckboxType::class, array(
'required' => false,
))
->add('twigExtension', Type\ChoiceType::class, array(
'required' => false,
'choices' => array_combine($this->twigExtensions, $this->twigExtensions),
Expand Down
11 changes: 11 additions & 0 deletions web/src/Fuz/AppBundle/Resources/views/Fiddle/options.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
</div>
</div>
<div class="error-container" id="errors-{{ form.withCExtension.vars.id }}">{{ form_errors(form.withCExtension) }}</div>

<div class="input-group full-width">
<div class="input-group-addon" style="width: 37px;">{{ form_widget(form.withStrictVariables) }}</div>
<div class="form-control">
<label for="{{ form.withStrictVariables.vars.id }}">
Enable Strict Variables mode
(<a class="dark" href="http://twig.sensiolabs.org/doc/templates.html#variables" target="_blank">read more</a>)
</label>
</div>
</div>
<div class="error-container" id="errors-{{ form.withStrictVariables.vars.id }}">{{ form_errors(form.withStrictVariables) }}</div>
</div>

</div>
Expand Down

0 comments on commit 29eed95

Please sign in to comment.