[svn] Proofread the rest of the docs.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Georg Brandl · committed by Georg Brandl · parent bb960d4 · Browse files · 7 files·+67 added−67 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+67 added−67 removed
- other:+67 added−67 removed
Provenance
- Commit
2d53a86- Tree
ef1f912- Author
Georg Brandl <georg@python.org>- Committer
Georg Brandl <georg@python.org>- Parent
bb960d4
7 files changed+67 added−67 removed
modified:docs/src/devintro.txt+43 added-43 removed
1 ====================2 Developer Quickstart3 ====================4 5-This part of the documentation shows you how to embedd Jinja into your5+This part of the documentation shows you how to embed Jinja into your6 application.7 8 Starting Up9 ===========10 unmodified lines20 This example should output the following string after execution::21 22 Hello John Doe!23 24-If you receive an error check if you have a typo in your code. If not have24+If you receive an error, check if you have a typo in your code. If not, have25 a look at the `installation`_ page for troubleshooting.26 27 The Environment28 ===============29 30-The core component of Jinja is the `Environment`. It helds important shared30+The core component of Jinja is the `Environment`. It contains important shared31 variables like configuration, filters, tests, globals and other stuff.32 33-Here the possible initialisation parameters:33+Here the possible initialization parameters:34 35-=========================== ==================================================36-``block_start_string`` * the string marking the begin of a block. this37- defaults to ``'{%'``.38-``block_end_string`` * the string marking the end of a block. defaults39- to ``'%}'``.40-``variable_start_string`` * the string marking the begin of a print41- statement. defaults to ``'{{'``.42-``comment_start_string`` * the string marking the begin of a43- comment. defaults to ``'{#'``.44-``comment_end_string`` * the string marking the end of a comment.45- defaults to ``'#}'``.46-``trim_blocks`` * If this is set to ``True`` the first newline47- after a block is removed (block, not48- variable tag!). Defaults to ``False``.49-``auto_escape`` If this is set to ``True`` Jinja will50- automatically escape all variables using xml51- escaping methods. If you don't want to escape a52- string you have to wrap it in a ``Markup``53- object from the ``jinja.datastructure`` module.54-``template_charset`` The charset of the templates. Defaults55- to ``'utf-8'``.56-``charset`` Charset of all string input data. Defaults57- to ``'utf-8'``.58-``namespace`` Global namespace for all templates.59-``loader`` Specify a template loader.60-``filters`` dict of filters or the default filters if not61- defined.62-``tests`` dict of tests of the default tests if not defined.63-=========================== ==================================================35+========================= ==================================================36+`block_start_string` * the string marking the begin of a block. this37+ defaults to ``'{%'``.38+`block_end_string` * the string marking the end of a block. defaults39+ to ``'%}'``.40+`variable_start_string` * the string marking the begin of a print41+ statement. defaults to ``'{{'``.42+`comment_start_string` * the string marking the begin of a43+ comment. defaults to ``'{#'``.44+`comment_end_string` * the string marking the end of a comment.45+ defaults to ``'#}'``.46+`trim_blocks` * If this is set to ``True`` the first newline47+ after a block is removed (block, not48+ variable tag!). Defaults to ``False``.49+`auto_escape` If this is set to ``True`` Jinja will50+ automatically escape all variables using xml51+ escaping methods. If you don't want to escape a52+ string you have to wrap it in a ``Markup``53+ object from the ``jinja.datastructure`` module.54+`template_charset` The charset of the templates. Defaults55+ to ``'utf-8'``.56+`charset` Charset of all string input data. Defaults57+ to ``'utf-8'``.58+`namespace` Global namespace for all templates.59+`loader` Specify a template loader.60+`filters` dict of filters or the default filters if not61+ defined.62+`tests` dict of tests of the default tests if not defined.63+========================= ==================================================64 65-All of this variables except those marked with a star(*) are modifyable after66-environment initialisation.65+All of these variables except those marked with a star (*) are modifiable after66+environment initialization.67 68-The environment provides the following useful functions and properties69-additional to the initialisation values:68+The environment provides the following useful functions and properties in69+addition to the initialization values:70 71 =========================== ==================================================72 ``parse(source, filename)`` Parse the sourcecode and return the abstract73 syntax tree. This tree of nodes is used by the74 `translators`_ to convert the template into75 executable source- or bytecode.76 ``from_string(source)`` Load and parse a template source and translate it77- into evaluable python code. This code is wrapped78- with in a `Template` class that allows you to77+ into eval-able Python code. This code is wrapped78+ within a `Template` class that allows you to79 render it.80-``get_template(name)`` load a template from a loader. If the template81- does not exist you will get a `TemplateNotFound`80+``get_template(name)`` Load a template from a loader. If the template81+ does not exist, you will get a `TemplateNotFound`82 exception.83 =========================== ==================================================84 85 There are also some internal functions on the environment used by the template21 unmodified lines107 108 Adding Filters109 ==============110 111-If you want to add additional filters to the environment the best way is to111+If you want to add additional filters to the environment, the best way is to112 modify the ``filters`` attribute and not to pass a dict to the environment.113 If you pass it a dict it will not include the default filters!114 115 .. sourcecode:: python5 unmodified lines121 122 Adding Tests123 ============124 125-Adding additional tests works analog to filters:125+Adding additional tests works analogous to filters:126 127 .. sourcecode:: python128 129 from mylib import my_cool_test10 unmodified linesmodified:docs/src/filters.txt+5 added-5 removed
10 unmodified lines11 12 Writing Filters13 ===============14 15-A filter basically is a factory function. Thus a function that returns another16-function. We do this because filters can get an unlimited amount of position15+A filter basically is a factory function, a function that returns another16+function. We do this because filters can get an unlimited amount of positional17 arguments and aditionally should gain access to the environment, context and18 piped value. A simple filter looks like this:19 20 .. sourcecode:: python11 unmodified lines32 .. sourcecode:: python33 34 env.filters['join'] = do_join35 36-In fact this filter is already bundled so you won't see any effect. But its36+In fact this filter is already bundled so you won't see any effect. But it37 should explain how such a filter looks like. The template designer can just38-trigger the outer code (eg: call do_join with or without arguments). The38+trigger the outer code (i.e. call `join` with or without arguments). The39 returned function is then processed by the jinja template engine once all40 filters are created.41 42-If you want to create filters that just operate on string (in fact unicode42+If you want to create filters that just operate on a string (in fact unicode43 objects) you can use the `stringfilter` decorator:44 45 .. sourcecode:: python46 11 unmodified linesmodified:docs/src/frameworks.txt+1 added-1 removed
2 unmodified lines3 =====================4 5 Jinja registers itself in the baker template plugin system. If your framework6 supports baker (currently `TurboGears`_ and `pylons`_) you can add it very7-easy.7+easily.8 9 Pylons10 ------11 22 unmodified linesmodified:docs/src/fromdjango.txt+10 added-10 removed
1 ===============================2 Differences To Django Templates3 ===============================4 5-If you have previously worked with Django templates you should feel very6-familiar. In fact most of the syntax elements look and work the same.5+If you have previously worked with Django templates, you should find Jinja very6+familiar. In fact, most of the syntax elements look and work the same.7 8-However Jinja provides some more syntax elements covered in the documentation8+However, Jinja provides some more syntax elements covered in the documentation9 and some work a bit different.10 11 Method Calls12 ============13 14-In Django method calls work implicit. With Jinja you have to tell it that you15-want to call it. Thus this Django code:14+In Django method calls work implicitly. With Jinja you have to specify that you15+want to call an object. Thus this Django code:16 17 .. sourcecode:: django18 19 {% for page in user.get_created_pages %}51 unmodified lines71 72 Filter Arguments73 ================74 75-Jinja provides more than one argument for a filter. Also the syntax for argument75+Jinja provides more than one argument for filters. Also the syntax for argument76 passing is different. A template that looks like this in Django:77 78 .. sourcecode:: django79 4 unmodified lines84 .. sourcecode:: jinja85 86 {{ items|join(', ') }}87 88-In fact it's a bit more to write but it allows different type of arguments including89-variables and more then one of them.88+In fact it's a bit more verbose but it allows different types of arguments - including89+variables - and more than one of them.90 91 Tests92 =====93 94-Additionally to filters there also exists tests you can perform using the `is`95-operator. Here some examples:94+In addition to filters there also are tests you can perform using the `is` operator.95+Here are some examples:96 97 .. sourcecode:: jinja98 99 {% if user.user_id is odd %}9 unmodified linesmodified:docs/src/loaders.txt+6 added-6 removed
10 unmodified lines11 12 Developing Loaders13 ==================14 15-Template loaders are just normal python classes that have to provide some16-functions used to load and translate templates. Here a simple loader implementation17-you can use as base for your own loader:15+Template loaders are just normal Python classes that have to provide some16+functions used to load and translate templates. Here is a simple loader implementation17+you can use as the base for your own loader:18 19 .. sourcecode:: python20 21 from os.path import join9 unmodified lines31 self.searchpath = searchpath32 33 def get_source(self, environment, name, parent):34 """35- The get_source function is unused at the moment. However future35+ The get_source function is unused at the moment. However, future36 versions of jinja will use this function for the debugging37 system. It also works as helper functions for `parse` and38 `load`.39 """15 unmodified lines55 56 def load(self, environment, name, translator):57 """58 Parse and translate a template. Currently only translation to59- python code is possible, later jinja versions however will59+ python code is possible, later Jinja versions however will60 support translating templates to javascript too.61 """62 return translator.process(environment, self.parse(environment, name, None))63 64 65 .. admonition:: Note66 67- Once a loader is bound to an environment you have to omit the environment67+ Once a loader is bound to an environment, you have to omit the environment68 argument for the public functions `get_source`, `parse` and `load`.modified:docs/src/tests.txt+1 added-1 removed
1 ==============2 Test Functions3 ==============4 5-Additionally to filters Jinja also supports test functions. Test functions5+In addition to filters, Jinja also supports test functions. Test functions6 always return either ``True`` or ``False``. Inside the template they are available7 using the `is` operator.8 9 Jinja comes with some builtin tests listed in the `designer documentation`_.21 unmodified linesmodified:docs/src/translators.txt+1 added-1 removed
3 unmodified lines4 5 Jinja translates the template sourcecode into executable python code behind6 the secenes. This is done by the python translator which is currently the7 only shipped translator. Because the interface isn't stable it's also not8-recommended to write other translators. However for the next Jinja version8+recommended yet to write other translators. However for the next Jinja version9 a JavaScript translator is planned which allows you to translate Jinja10 templates into executable JavaScript code.