Skip to content

Commit 431552f

Browse files
committed
[cookbook] Proofread the new apply_to assetic cookbook
1 parent ffe408c commit 431552f

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

cookbook/assetic/apply_to_option.rst

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
How to Apply an Assetic Filter to a Specified File Extension
2-
============================================================
1+
How to Apply an Assetic Filter to a Specific File Extension
2+
===========================================================
33

4-
One of Assetic's filters compiles CoffeeScript files into JavaScript.
5-
This offers the advantages of caching the end result so the compilation
6-
does not run every time whilst also automatically recompiling when ever
7-
the script changes during development.
8-
9-
Whilst Assetic's ``CoffeeScriptFilter`` will do the work for you it does
10-
not do the actual compilation, you will still need to install CoffeeScript
11-
itself along with node.js on which it runs.
4+
Assetic filters can be applied to individual files, groups of files or even,
5+
as you'll see here, files that have a specific extension. To show you how
6+
to handle each option, let's suppose that you want to use Assetic's CoffeeScript
7+
filter, which compiles CoffeeScript files into Javascript.
128

139
The main configuration is just the paths to coffee and node. These default
1410
respectively to ``/usr/bin/coffee`` and ``/usr/bin/node``:
@@ -46,8 +42,10 @@ respectively to ``/usr/bin/coffee`` and ``/usr/bin/node``:
4642
),
4743
));
4844
45+
Filter a Single File
46+
--------------------
4947

50-
You can then serve up CoffeeScript files as JavaScript from within your
48+
You can now serve up a single CoffeeScript file as JavaScript from within your
5149
templates:
5250

5351
.. configuration-block::
@@ -68,9 +66,13 @@ templates:
6866
<script src="<?php echo $view->escape($url) ?>" type="text/javascript"></script>
6967
<?php endforeach; ?>
7068

69+
This is all that's needed to compile this CoffeeScript file and server it
70+
as the compiled JavaScript.
71+
72+
Filter Multiple Files
73+
---------------------
7174

72-
This is all was needed and the file was served up as regular JavaScript.
73-
You can combine multiple CoffeeScript files into a single output file:
75+
You can also combine multiple CoffeeScript files into a single output file:
7476

7577
.. configuration-block::
7678

@@ -92,19 +94,21 @@ You can combine multiple CoffeeScript files into a single output file:
9294
<script src="<?php echo $view->escape($url) ?>" type="text/javascript"></script>
9395
<?php endforeach; ?>
9496

95-
9697
Both the files will now be served up as a single file compiled into regular
9798
JavaScript.
9899

100+
Filtering based on a File Extension
101+
-----------------------------------
102+
99103
One of the great advantages of using Assetic is reducing the number of asset
100-
files to lower ``HTTP`` requests. In order to make full use of this it would
101-
be good to combine all your JavaScript and CoffeeScript files together
104+
files to lower HTTP requests. In order to make full use of this, it would
105+
be good to combine *all* your JavaScript and CoffeeScript files together
102106
since they will ultimately all be served as JavaScript. Unfortunately just
103107
adding the JavaScript files to the files to be combined as above will not
104108
work as the regular JavaScript files will not survive the CoffeeScript compilation.
105109

106-
This problem can be avoid though by using the ``apply_to`` option in the
107-
config, this allows you to specify that a filter is always applied to particular
110+
This problem can be avoided by using the ``apply_to`` option in the config,
111+
which allows you to specify that a filter should always be applied to particular
108112
file extensions. In this case you can specify that the Coffee filter is
109113
applied to all ``.coffee`` files:
110114

@@ -144,11 +148,10 @@ applied to all ``.coffee`` files:
144148
),
145149
));
146150
147-
148-
149-
So you can now remove specifying the filter in the Twig template and list
150-
any regular JavaScript files which will now be combined into the output
151-
file without having been run through coffee:
151+
With this, you no longer need to specify the ``coffee`` filter in the template.
152+
You can also list regular JavaScript files, all of which will be combined
153+
and rendered as a single JavaScript file (with only the ``.coffee`` files
154+
being run through the CoffeeScript filter):
152155

153156
.. configuration-block::
154157

cookbook/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Cookbook
1313
assetic/asset_management
1414
assetic/yuicompressor
1515
assetic/jpeg_optimize
16+
assetic/apply_to_option
1617

1718
doctrine/doctrine_fixtures
1819
doctrine/mongodb

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* :doc:`/cookbook/assetic/asset_management`
1414
* :doc:`/cookbook/assetic/yuicompressor`
1515
* :doc:`/cookbook/assetic/jpeg_optimize`
16+
* :doc:`/cookbook/assetic/apply_to_option`
1617

1718
* **Database Interaction (Doctrine)**
1819

0 commit comments

Comments
 (0)