Skip to content

Commit 3889f77

Browse files
committed
Add code previously excluded due to a filesystem issue
1 parent 034e139 commit 3889f77

File tree

9 files changed

+97
-31
lines changed

9 files changed

+97
-31
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
php:
4+
- 5.3.3
45
- 5.3
56
- 5.4
67

DependencyInjection/Configuration.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,39 @@ protected function addSmartyOptions(ArrayNodeDefinition $rootNode)
169169
->children()
170170
->scalarNode('allow_php_templates')->end()
171171
->scalarNode('auto_literal')->end()
172-
->scalarNode('autoload_filters')->end()
172+
->arrayNode('autoload_filters')
173+
->info('filters that you wish to load on every template invocation')
174+
->canBeUnset()
175+
->children()
176+
->arrayNode('pre')
177+
->example(array('trim', 'stamp'))
178+
->canBeUnset()
179+
->beforeNormalization()
180+
->ifTrue(function($v){ return !is_array($v); })
181+
->then(function($v){ return array($v); })
182+
->end()
183+
->prototype('scalar')->end()
184+
->end()
185+
->arrayNode('post')
186+
->example(array('add_header_comment'))
187+
->canBeUnset()
188+
->beforeNormalization()
189+
->ifTrue(function($v){ return !is_array($v); })
190+
->then(function($v){ return array($v); })
191+
->end()
192+
->prototype('scalar')->end()
193+
->end()
194+
->arrayNode('output')
195+
->example(array('convert'))
196+
->canBeUnset()
197+
->beforeNormalization()
198+
->ifTrue(function($v){ return !is_array($v); })
199+
->then(function($v){ return array($v); })
200+
->end()
201+
->prototype('scalar')->end()
202+
->end()
203+
->end()
204+
->end()
173205
->scalarNode('cache_dir')->defaultValue('%kernel.cache_dir%/smarty/cache')->cannotBeEmpty()->end()
174206
->scalarNode('cache_id')->end()
175207
->scalarNode('cache_lifetime')->end()
@@ -205,7 +237,6 @@ protected function addSmartyOptions(ArrayNodeDefinition $rootNode)
205237
->scalarNode('plugins_dir')->end()
206238
->scalarNode('smarty_debug_id')->end()
207239
->scalarNode('template_dir')->defaultValue('%kernel.root_dir%/Resources/views')->cannotBeEmpty()->end()
208-
->booleanNode('trim_whitespace')->defaultFalse()->end()
209240
->scalarNode('trusted_dir')->end()
210241
->scalarNode('use_include_path')->defaultFalse()->end()
211242
->scalarNode('use_sub_dirs')->defaultTrue()->end()

Resources/doc/assetic.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.. index::
2+
single: Assetic
3+
14
.. _ch_assetic:
25

36
*******

Resources/doc/bootstrap.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.. index::
2+
single: Twitter Bootstrap
3+
14
.. _ch_bootstrap:
25

36
*****************************

Resources/doc/cookbook.rst

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,47 @@
77
Cookbook
88
********
99

10-
Some text
10+
Injecting variables into all templates (i.e. Global Variables)
11+
==============================================================
12+
13+
.. index::
14+
single: Global Variables
15+
16+
As exemplified in the `Symfony Cookbook <http://symfony.com/doc/current/cookbook/templating/global_variables.html>`_ it is possible to make a variable to be accessible to all the templates you use by configuring your `app/config/config.yml` file:
17+
18+
.. code-block:: yaml
19+
20+
# app/config/config.yml
21+
smarty:
22+
# ...
23+
globals:
24+
ga_tracking: UA-xxxxx-x
25+
26+
Now, the variable ga_tracking is available in all Smarty templates:
27+
28+
.. code-block:: html+smarty
29+
30+
<p>Our google tracking code is: {$ga_tracking} </p>
31+
32+
Trim unnecessary whitespace from HTML markup
33+
===================================================
34+
35+
.. index::
36+
single: Trimwhitespace
37+
38+
This technique can speed up your website by eliminating extra whitespace characters and thus reducing page size. It removes HTML comments (except ConditionalComments) and reduces multiple whitespace to a single space everywhere but ``<script>``, ``<pre>``, ``<textarea>`` [#]_.
39+
40+
To enable this feature add the ``trimwhitespace`` output filter in ``app/config/config.yml``:
41+
42+
.. code-block:: yaml
43+
:emphasize-lines: 7
44+
45+
# app/config/config.yml
46+
47+
# Smarty configuration
48+
smarty:
49+
options:
50+
autoload_filters:
51+
output: [trimwhitespace]
52+
53+
.. [#] http://stackoverflow.com/a/9207456/545442

Resources/doc/index.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
6+
77
############
88
SmartyBundle
99
############
@@ -19,7 +19,7 @@ SmartyBundle
1919
.. image:: _static/images/smarty-50.png
2020
:target: http://smarty.net
2121
:height: 50px
22-
22+
2323
.. toctree::
2424
:maxdepth: 3
2525
:numbered:
@@ -28,6 +28,7 @@ SmartyBundle
2828
intro
2929
installation
3030
usage
31+
cookbook
3132
extensions
3233
assetic
3334
forms
@@ -53,13 +54,14 @@ Installation
5354

5455
.. toctree::
5556

56-
Simple usage
57-
============
57+
Basic Usage / Tips & Tricks
58+
============================
5859

5960
.. toctree::
6061
:maxdepth: 3
6162

6263
usage
64+
cookbook
6365

6466
SmartyBundle Extensions
6567
=======================

Resources/doc/usage.rst

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,4 @@ Please see `Symfony2 - Template Naming and Locations <http://symfony.com/doc/2.0
9090
.. note::
9191

9292
The `.html.smarty` extension can simply be replaced by `.smarty`. We are prefixing with `.html` to stick with the Symfony convention of defining the format (`.html`) and engine (`.smarty`) for each template.
93-
94-
Injecting variables into all templates (i.e. Global Variables)
95-
==============================================================
96-
97-
As exemplified in the `Symfony Cookbook <http://symfony.com/doc/current/cookbook/templating/global_variables.html>`_ it is possible to make a variable to be accessible to all the templates you use by configuring your `app/config/config.yml` file:
98-
99-
.. code-block:: yaml
100-
101-
# app/config/config.yml
102-
smarty:
103-
# ...
104-
globals:
105-
ga_tracking: UA-xxxxx-x
106-
107-
Now, the variable ga_tracking is available in all Smarty templates:
108-
109-
.. code-block:: html+smarty
110-
111-
<p>Our google tracking code is: {$ga_tracking} </p>
112-
93+

SmartyEngine.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ public function __construct(\Smarty $smarty, ContainerInterface $container,
8484
// There are no default extensions.
8585
$this->extensions = array();
8686

87-
// trim whitespace
88-
if (true === $options['trim_whitespace']) {
89-
$this->smarty->loadFilter('output','trimwhitespace');
87+
foreach (array('autoload_filters') as $property) {
88+
if (isset($options[$property])) {
89+
$this->smarty->$property = $options[$property];
90+
unset($options[$property]);
91+
}
9092
}
91-
unset($options['trim_whitespace']);
9293

9394
/**
9495
* @warning If you added template dirs to the Smarty instance prior to

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"smarty/smarty": "3.1.*@stable"
2727
},
2828
"require-dev": {
29+
"symfony/security": "2.1.*",
2930
"symfony/yaml": "2.1.*",
3031
"symfony/assetic-bundle": ">=2.0"
3132
},

0 commit comments

Comments
 (0)