{% set sidebar_width = '220px' %}
{% set font_family = 'Georgia, serif' %}
{% set header_font_family = 'Crimson Text, ' ~ font_family %}
-
+
@import url("basic.css");
-
+
/* -- page layout ----------------------------------------------------------- */
-
+
body {
font-family: {{ font_family }};
font-size: 17px;
hr {
border: 1px solid #B1B4B6;
}
-
+
div.body {
background-color: #ffffff;
color: #3E4349;
padding: 0 0 10px 10px;
float: right;
}
-
+
div.footer {
width: {{ page_width }};
margin: 20px auto 30px auto;
div.related {
display: none;
}
-
+
div.sphinxsidebar a {
color: #444;
text-decoration: none;
div.sphinxsidebar a:hover {
border-bottom: 1px solid #999;
}
-
+
div.sphinxsidebar {
font-size: 15px;
line-height: 1.5;
margin: 0;
text-align: center;
}
-
+
div.sphinxsidebar h3,
div.sphinxsidebar h4 {
font-family: {{ font_family }};
div.sphinxsidebar h4 {
font-size: 20px;
}
-
+
div.sphinxsidebar h3 a {
color: #444;
}
div.sphinxsidebar h3 a:hover {
border: none;
}
-
+
div.sphinxsidebar p {
color: #555;
margin: 10px 0;
padding: 0;
color: #000;
}
-
+
div.sphinxsidebar input {
border: 1px solid #ccc;
font-family: {{ font_family }};
div.sphinxsidebar form.search input[name="q"] {
width: 130px;
}
-
+
/* -- body styles ----------------------------------------------------------- */
-
+
a {
color: #aa0000;
text-decoration: underline;
}
-
+
a:hover {
color: #dd0000;
text-decoration: underline;
}
-
+
div.body h1,
div.body h2,
div.body h3,
padding: 0;
color: black;
}
-
+
div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; }
div.body h2 { font-size: 180%; }
div.body h3 { font-size: 150%; }
div.body h4 { font-size: 130%; }
div.body h5 { font-size: 100%; }
div.body h6 { font-size: 100%; }
-
+
a.headerlink {
color: #ddd;
padding: 0 4px;
text-decoration: none;
}
-
+
a.headerlink:hover {
color: #444;
background: #eaeaea;
}
-
+
div.body p, div.body dd, div.body li {
line-height: 1.4em;
}
background-color: #eee;
border: 1px solid #ccc;
}
-
+
div.seealso {
background-color: #ffc;
border: 1px solid #ff6;
}
-
+
div.topic {
background-color: #eee;
}
-
+
p.admonition-title {
display: inline;
}
-
+
p.admonition-title:after {
content: ":";
}
margin: 10px 0 10px 30px;
padding: 0;
}
-
+
pre {
background: #eee;
padding: 7px 30px;
margin-left: -90px;
padding-left: 90px;
}
-
+
tt {
background-color: #E8EFF0;
color: #222;
albeit a shared one.
Most applications will create one :class:`Environment` object on application
-initialization and use that to load templates. In some cases however, it's
+initialization and use that to load templates. In some cases however, it's
useful to have multiple environments side by side, if different configurations
are in use.
For a more complex example you can provide a hint. For example
the :func:`first` filter creates an undefined object that way::
- return environment.undefined('no first item, sequence was empty')
+ return environment.undefined('no first item, sequence was empty')
If it the `name` or `obj` is known (for example because an attribute
was accessed) it should be passed to the undefined object, even if
if n % i == 0:
return False
return True
-
+
You can register it on the template environment by updating the
:attr:`~Environment.tests` dict on the environment::
has the advantage that the C extensions are compiled.
.. _download page: https://pypi.org/project/Jinja2/
-.. _distribute: https://pypi.org/project/distribute/
+.. _distribute: https://pypi.org/project/distribute/
.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
.. _pip: https://pypi.org/project/pip/
writer = Writer()
writer.node_handlers[MyNode] = write_my_node
convert_templates('/path/to/output/folder', writer=writer)
-
+
Here is an example hos to automatically translate your django
variables to jinja2::
-
+
import re
# List of tuple (Match pattern, Replace pattern, Exclusion pattern)
-
+
var_re = ((re.compile(r"(u|user)\.is_authenticated"), r"\1.is_authenticated()", None),
(re.compile(r"\.non_field_errors"), r".non_field_errors()", None),
(re.compile(r"\.label_tag"), r".label_tag()", None),
(re.compile(r"\.as_table"), r".as_table()", None),
(re.compile(r"\.as_widget"), r".as_widget()", None),
(re.compile(r"\.as_hidden"), r".as_hidden()", None),
-
+
(re.compile(r"\.get_([0-9_\w]+)_url"), r".get_\1_url()", None),
(re.compile(r"\.url"), r".url()", re.compile(r"(form|calendar).url")),
(re.compile(r"\.get_([0-9_\w]+)_display"), r".get_\1_display()", None),
(re.compile(r"loop\.revcounter"), r"loop.revindex", None),
(re.compile(r"request\.GET\.([0-9_\w]+)"), r"request.GET.get('\1', '')", None),
(re.compile(r"request\.get_host"), r"request.get_host()", None),
-
+
(re.compile(r"\.all(?!_)"), r".all()", None),
(re.compile(r"\.all\.0"), r".all()[0]", None),
(re.compile(r"\.([0-9])($|\s+)"), r"[\1]\2", None),
(re.compile(r"\.items"), r".items()", None),
)
writer = Writer(var_re=var_re)
-
+
For details about the writing process have a look at the module code.
:copyright: (c) 2009 by the Jinja Team.
"""Performs variable name translation."""
if self.in_loop and var == 'forloop' or var.startswith('forloop.'):
var = var[3:]
-
+
for reg, rep, unless in self.var_re:
no_unless = unless and unless.search(var) or True
if reg.search(var) and no_unless:
join_with = 'and'
if node.link_type == core_tags.IfNode.LinkTypes.or_:
join_with = 'or'
-
+
for idx, (ifnot, expr) in enumerate(node.bool_exprs):
if idx:
writer.write(' %s ' % join_with)
writer._filters_warned.add(name)
writer.warn('Filter %s probably doesn\'t exist in Jinja' %
name)
-
+
if not node.vars_to_resolve:
# No argument, pass the request
writer.start_variable()
writer.write('request|')
writer.write(name)
writer.end_variable()
- return
-
+ return
+
first_var = node.vars_to_resolve[0]
args = node.vars_to_resolve[1:]
writer.start_variable()
-
+
# Copied from Writer.filters()
writer.node(first_var)
-
+
writer.write('|')
writer.write(name)
if args:
else:
writer.literal(var.literal)
writer.write(')')
- writer.end_variable()
+ writer.end_variable()
# get rid of node now, it shouldn't be used normally
del node
# lint Python modules using external checkers.
-#
+#
# This is the main checker controlling the other ones and the reports
# generation. It is itself both a raw checker and an astng checker in order
# to:
# * handle message activation / deactivation at the module level
# * handle some basic but necessary stats'data (number of classes, methods...)
-#
+#
[MASTER]
# Specify a configuration file.
# * undefined variables
# * redefinition of variable from builtins or from an outer scope
# * use of variable before assignment
-#
+#
[VARIABLES]
# Tells whether we should check for unused import in __init__ files.
# try to find bugs in the code using type inference
-#
+#
[TYPECHECK]
# Tells whether missing members accessed in mixin class should be ignored. A
# * dangerous default values as arguments
# * redefinition of function / method / class
# * uses of the global statement
-#
+#
[BASIC]
# Required attributes for module, separated by a comma
# checks for sign of poor/misdesign:
# * number of methods, attributes, local variables...
# * size, complexity of functions, methods
-#
+#
[DESIGN]
# Maximum number of arguments for function / method
# * relative / wildcard imports
# * cyclic imports
# * uses of deprecated modules
-#
+#
[IMPORTS]
# Deprecated modules which should not be used, separated by a comma
# * attributes not defined in the __init__ method
# * supported interfaces implementation
# * unreachable code
-#
+#
[CLASSES]
# List of interface methods to ignore, separated by a comma. This is used for
# checks for similarities and duplicated code. This computation may be
# memory / CPU intensive, so you should disable it if you experiments some
# problems.
-#
+#
[SIMILARITIES]
# Minimum lines number of a similarity.
# checks for:
# * warning notes in the code like FIXME, XXX
# * PEP 263: source code with non ascii character but no encoding declaration
-#
+#
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
# * strict indentation
# * line length
# * use of <> instead of !=
-#
+#
[FORMAT]
# Maximum number of characters on a single line.
c.next()
assert c.current == 2
c.reset()
- assert c.current == 1
+ assert c.current == 1
def test_expressions(self, env):
expr = env.compile_expression("foo")