Skip to content
Myr

Merge branch '2.10.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents 6257019, e74640b · Browse files · 11 files+171 added−110 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+171 added−110 removed

  • tests:+43 added−1 removed
  • other:+128 added−109 removed

11 files+171 added−110 removed

modified:docs/api.rst+2 added-2 removed
45 unmodified lines
46 template = env.get_template('mytemplate.html')4748To render it with some variables, just call the :meth:`render` method::4950 print template.render(the='variables', go='here')50 print(template.render(the='variables', go='here'))5152Using a template loader rather than passing strings to :class:`Template`53or :meth:`Environment.from_string` has multiple advantages. Besides being54a lot easier to use it also enables template inheritance.
781 unmodified lines
836837 def is_prime(n):838 if n == 2:839 return True840 for i in xrange(2, int(math.ceil(math.sqrt(n))) + 1):840 for i in range(2, int(math.ceil(math.sqrt(n))) + 1):841 if n % i == 0:842 return False843 return True844
91 unmodified lines
modified:docs/faq.rst+1 added-2 removed
151 unmodified lines
152153Python 2.3 is missing a lot of features that are used heavily in Jinja2. This154decision was made as with the upcoming Python 2.6 and 3.0 versions it becomes155harder to maintain the code for older Python versions. If you really need156Python 2.3 support you either have to use `Jinja 1`_ or other templating156Python 2.3 support you either have to use Jinja 1 or other templating157engines that still support 2.3.158159Python 2.4/2.5/3.1/3.2 support was removed when we switched to supporting160Python 2 and 3 by the same sourcecode (without using 2to3). It was required to
30 unmodified lines
191templates passing information to the parent template. To avoid this192issue rename the macro or variable in the parent template to have an193uncommon prefix.194195.. _Jinja 1: http://jinja.pocoo.org/1/
modified:docs/templates.rst+26 added-3 removed
393 unmodified lines
394this template "extends" another template. When the template system evaluates395this template, it first locates the parent. The extends tag should be the396first tag in the template. Everything before it is printed out normally and397may cause confusion. For details about this behavior and how to take398advantage of it, see :ref:`null-master-fallback`.398advantage of it, see :ref:`null-master-fallback`. Also a block will always be399filled in regardless of whether the surrounding condition is evaluated to be true 400or false.401402The filename of the template depends on the template loader. For example, the403:class:`FileSystemLoader` allows you to access other templates by giving the404filename. You can access templates in subdirectories with a slash::
208 unmodified lines
613As variables in templates retain their object properties, it is possible to614iterate over containers like `dict`::615616 <dl>615 {% for key, value in my_dict.iteritems() %}617 {% for key, value in my_dict.items() %}618 <dt>{{ key|e }}</dt>619 <dd>{{ value|e }}</dd>620 {% endfor %}621 </dl>
615 unmodified lines
12371238/1239 Divide two numbers. The return value will be a floating point number.1240 ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.1239 (Just like ``from __future__ import division``.)12411242//1243 Divide two numbers and return the truncated integer result.1244 ``{{ 20 // 7 }}`` is ``2``.
111 unmodified lines
13561357 {{ ('[%s]' % page.title) if page.title }}135813591360.. _python-methods:13611362Python Methods1363~~~~~~~~~~~~~~13641365You can also use any of the methods of defined on a variable's type.1366The value returned from the method invocation is used as the value of the expression.1367Here is an example that uses methods defined on strings (where ``page.title`` is a string):13681369.. code-block:: text13701371 {{ page.title.capitalize() }}13721373This also works for methods on user-defined types.1374For example, if variable ``f`` of type ``Foo`` has a method ``bar`` defined on it,1375you can do the following:13761377.. code-block:: text13781379 {{ f.bar() }}138013811382.. _builtin-filters:13831384List of Builtin Filters1385-----------------------
374 unmodified lines
modified:tests/conftest.py+43 added-1 removed
14 unmodified lines
15from jinja2.utils import have_async_gen16from jinja2 import Environment171819def pytest_ignore_collect(path, config):19def pytest_ignore_collect(path):20 if 'async' in path.basename and not have_async_gen:21 return True22 return False232425def pytest_configure(config):26 '''Register custom marks for test categories.'''27 custom_markers = [28 'api',29 'byte_code_cache',30 'core_tags',31 'debug',32 'escapeUrlizeTarget',33 'ext',34 'extended',35 'filter',36 'for_loop',37 'helpers',38 'if_condition',39 'imports',40 'includes',41 'inheritance',42 'lexer',43 'lexnparse',44 'loaders',45 'lowlevel',46 'lrucache',47 'lstripblocks',48 'macros',49 'meta',50 'moduleloader',51 'parser',52 'regression',53 'sandbox',54 'set',55 'streaming',56 'syntax',57 'test_tests',58 'tokenstream',59 'undefined',60 'utils',61 'with_',62 ]63 for mark in custom_markers:64 config.addinivalue_line('markers', mark + ': test category')656667@pytest.fixture68def env():69 '''returns a new environment.70 '''
49 unmodified lines
added:.azure-pipelines.yml+61 added
deleted:.coveragerc-11 removed
1[run]2branch = True3source =4 jinja25 tests67[paths]8source =9 jinja210 .tox/*/lib/python*/site-packages/jinja211 .tox/pypy/site-packages/jinja2
deleted:.travis.yml-46 removed
modified:CHANGES.rst+7 added
19 unmodified lines
20.. _#765: https://github.com/pallets/jinja/issues/76521.. _#977: https://github.com/pallets/jinja/issues/977222324Version 2.10.225--------------2627_Unreleased_2829- Fix Python 3.7 deprecation warnings.3031Version 2.10.132--------------3334Released 2019-04-06
598 unmodified lines
deleted:Makefile-21 removed
1test:2 py.test tests --tb=short34develop:5 pip install --editable .67tox-test:8 @tox910release:11 python scripts/make-release.py1213upload-docs:14 $(MAKE) -C docs html dirhtml latex15 $(MAKE) -C docs/_build/latex all-pdf16 cd docs/_build/; mv html jinja-docs; zip -r jinja-docs.zip jinja-docs; mv jinja-docs html17 scp -r docs/_build/dirhtml/* flow.srv.pocoo.org:/srv/websites/jinja.pocoo.org/docs/18 scp -r docs/_build/latex/Jinja2.pdf flow.srv.pocoo.org:/srv/websites/jinja.pocoo.org/docs/jinja-docs.pdf19 scp -r docs/_build/jinja-docs.zip flow.srv.pocoo.org:/srv/websites/jinja.pocoo.org/docs/2021.PHONY: test
modified:setup.cfg+15 added-4 removed
1[bdist_wheel]2universal = 131[metadata]2license_file = LICENSE34[bdist_wheel]5universal = true67[tool:pytest]8minversion = 3.08testpaths = tests910[coverage:run]11branch = True12source =13 jinja214 tests1516[coverage:paths]17source =18 src/jinja219 .tox/*/lib/python*/site-packages/jinja220 .tox/*/site-packages/jinja2
modified:tox.ini+16 added-20 removed
1[tox]2envlist =3 py{37,36,35,34,27,py3,py}3 py{37,36,35,27,py3,py}4 docs-html5 coverage-report5 coverage6skip_missing_interpreters = true78[testenv]8passenv = LANG9usedevelop = true9deps =11 pytest>=310 coverage11 pytest12commands = coverage run -p -m pytest --tb=short -Werror --basetemp={envtmpdir} {posargs}1314commands = coverage run -p -m pytest {posargs}1514[testenv:docs-html]17deps = sphinx18commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs docs/_build/html15deps =16 Sphinx17 Pallets-Sphinx-Themes18 sphinx-issues19commands = sphinx-build -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html2020[testenv:docs-linkcheck]21deps = sphinx22commands = sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/linkcheck2324[testenv:coverage-report]21[testenv:coverage]22deps = coverage23skip_install = true24commands =25 coverage combine29 coverage report26 coverage html27 coverage report2832[testenv:codecov]33passenv = CI TRAVIS TRAVIS_*34deps = codecov29[testenv:coverage-ci]30deps = coverage31skip_install = true32commands =33 coverage combine38 coverage report39 codecov34 # Ignoring errors because 2.7.15 and 3.5.5 on Azure can't parse async files.35 coverage xml --ignore-errors