Skip to content
Myr

Started working on refactoring Jinja integration

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

authored by Armin Ronacher · committed by Armin Ronacher · parent a154c87 · Browse files · 5 files+54 added−8 removed
This commit

State

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

Diff stats

5 files+54 added−8 removed

  • tests:+9 added−0 removed
  • other:+45 added−8 removed

5 files+54 added−8 removed

modified:docs/quickstart.rst+7 added
412 unmodified lines
413Markup(u'&lt;blink&gt;hacker&lt;/blink&gt;')414>>> Markup('<em>Marked up</em> &raquo; HTML').striptags()415u'Marked up \xbb HTML'416417.. versionchanged:: 0.5418419 Autoescaping is no longer enabled for all templates. The following420 extensions for templates trigger autoescaping: ``.html``, ``.htm``,421 ``.xml``, ``.xhtml``. Templates loaded from string will have422 autoescaping disabled.423424.. [#] Unsure what that :class:`~flask.g` object is? It's something you425 can store information on yourself, check the documentation of that426 object (:class:`~flask.g`) and the :ref:`sqlite3` for more427 information.
303 unmodified lines
added:tests/templates/mail.txt+1 added
1{{ foo}} Mail
modified:tests/flask_tests.py+8 added
459 unmodified lines
460 '&lt;p&gt;Hello World!',461 '<p>Hello World!'462 ]463464 def test_no_escaping(self):465 app = flask.Flask(__name__)466 with app.test_request_context():467 assert flask.render_template_string('{{ foo }}',468 foo='<test>') == '<test>'469 assert flask.render_template('mail.txt', foo='<test>') \470 == '<test> Mail'471472 def test_macros(self):473 app = flask.Flask(__name__)474 with app.test_request_context():475 macro = flask.get_template_attribute('_macro.html', 'hello')
423 unmodified lines
modified:CHANGES+4 added
9 unmodified lines
1011- fixed a bug with subdomains that was caused by the inability to12 specify the server name. The server name can now be set with13 the `SERVER_NAME` config key.14- autoescaping is no longer active for all templates. Instead it15 is only active for ``.html``, ``.htm``, ``.xml`` and ``.xhtml``.16 Inside templates this behaviour can be changed with the17 ``autoescape`` tag.1819Version 0.420-----------21
66 unmodified lines
modified:flask.py+34 added-8 removed
786 unmodified lines
787 def __repr__(self):788 return '<%s %s>' % (self.__class__.__name__, dict.__repr__(self))789790791def _select_autoescape(filename):792 """Returns `True` if autoescaping should be active for the given793 template name.794 """795 if filename is None:796 return False797 return filename.endswith(('.html', '.htm', '.xml', '.xhtml'))798799800class Flask(_PackageBoundObject):801 """The flask object implements a WSGI application and acts as the central802 object. It is passed the name of the module or package of the803 application. Once it is created it will act as a central registry for
124 unmodified lines
928 )929930 #: Options that are passed directly to the Jinja2 environment.931 jinja_options = ImmutableDict(923 autoescape=True,932 autoescape=_select_autoescape,933 extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']934 )935936 #: Default configuration parameters.
89 unmodified lines
10261027 #: The Jinja2 environment. It is created from the1028 #: :attr:`jinja_options` and the loader that is returned1029 #: by the :meth:`create_jinja_loader` function.1021 self.jinja_env = Environment(loader=self.create_jinja_loader(),1022 **self.jinja_options)1023 self.jinja_env.globals.update(1024 url_for=url_for,1025 get_flashed_messages=get_flashed_messages1026 )1027 self.jinja_env.filters['tojson'] = _tojson_filter1030 self.jinja_env = self.create_jinja_environment()1031 self.init_jinja_globals()10321033 @property1034 def logger(self):1035 """A :class:`logging.Logger` object for this application. The
28 unmodified lines
1064 logger.addHandler(handler)1065 self._logger = logger1066 return logger10671068 def create_jinja_environment(self):1069 """Creates the Jinja2 environment based on :attr:`jinja_options`1070 and :meth:`create_jinja_loader`.10711072 .. versionadded:: 0.51073 """1074 return Environment(loader=self.create_jinja_loader(),1075 **self.jinja_options)10761077 def create_jinja_loader(self):1078 """Creates the Jinja loader. By default just a package loader for1079 the configured package is returned that looks up templates in the1080 `templates` folder. To add other loaders it's possible to
2 unmodified lines
1083 if pkg_resources is None:1084 return FileSystemLoader(os.path.join(self.root_path, 'templates'))1085 return PackageLoader(self.import_name)10861087 def init_jinja_globals(self):1088 """Callde directly after the environment was created to inject1089 some defaults (like `url_for`, `get_flashed_messages` and the1090 `tojson` filter.10911092 .. versionadded:: 0.51093 """1094 self.jinja_env.globals.update(1095 url_for=url_for,1096 get_flashed_messages=get_flashed_messages1097 )1098 self.jinja_env.filters['tojson'] = _tojson_filter10991100 def update_template_context(self, context):1101 """Update the template context with some commonly used variables.1102 This injects request, session and g into the template context.1103
496 unmodified lines