Skip to content

Commit

Permalink
Move compile_string into the Engine class.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Nov 23, 2014
1 parent 5b1bb40 commit 240ea67
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions django/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@
filter_raw_string)

# Compiling templates
from django.template.base import (compile_string, resolve_variable, # NOQA
from django.template.base import (resolve_variable, # NOQA
unescape_string_literal, generic_tag_compiler)

# Library management
from django.template.base import (Library, add_to_builtins, builtins, # NOQA
get_library, get_templatetags_modules, get_text_list, import_library,
libraries)

__all__ = ('Template', 'Context', 'RequestContext', 'compile_string')
__all__ = ('Template', 'Context', 'RequestContext')
14 changes: 1 addition & 13 deletions django/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, template_string, origin=None, name=None, engine=None):
if engine is None:
from .engine import Engine
engine = Engine.get_default()
self.nodelist = compile_string(template_string, origin)
self.nodelist = engine.compile_string(template_string, origin)
self.name = name
self.origin = origin
self.engine = engine
Expand Down Expand Up @@ -165,18 +165,6 @@ def render(self, context):
context.engine = None


def compile_string(template_string, origin):
"Compiles template_string into NodeList ready for rendering"
if settings.TEMPLATE_DEBUG:
from django.template.debug import DebugLexer, DebugParser
lexer_class, parser_class = DebugLexer, DebugParser
else:
lexer_class, parser_class = Lexer, Parser
lexer = lexer_class(template_string, origin)
parser = parser_class(lexer.tokenize())
return parser.parse()


class Token(object):
def __init__(self, token_type, contents):
# token_type must be TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK or
Expand Down
16 changes: 15 additions & 1 deletion django/template/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.utils.functional import cached_property
from django.utils.module_loading import import_string

from .base import Context, Template, TemplateDoesNotExist
from .base import Context, Lexer, Parser, Template, TemplateDoesNotExist


_dirs_undefined = object()
Expand Down Expand Up @@ -200,3 +200,17 @@ def select_template(self, template_name_list, dirs=_dirs_undefined):
continue
# If we get here, none of the templates could be loaded
raise TemplateDoesNotExist(', '.join(not_found))

def compile_string(self, template_string, origin):
"""
Compiles template_string into a NodeList ready for rendering.
"""
if settings.TEMPLATE_DEBUG:
from .debug import DebugLexer, DebugParser
lexer_class, parser_class = DebugLexer, DebugParser
else:
lexer_class, parser_class = Lexer, Parser
lexer = lexer_class(template_string, origin)
tokens = lexer.tokenize()
parser = parser_class(tokens)
return parser.parse()
2 changes: 2 additions & 0 deletions docs/releases/1.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ Miscellaneous
delete a key if ``set()`` fails. This is necessary to ensure the ``cache_db``
session store always fetches the most current session data.

* Private API ``django.template.compile_string`` was removed.

* Private APIs ``override_template_loaders`` and ``override_with_test_loader``
in ``django.test.utils`` were removed. Override ``TEMPLATE_LOADERS`` with
``override_settings`` instead.
Expand Down

0 comments on commit 240ea67

Please sign in to comment.