mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 00:07:57 -05:00
Remove legacy buffet template renderer abstraction layer.
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
import os
|
||||
import mimetypes
|
||||
|
||||
from mako.lookup import TemplateLookup
|
||||
from pylons.error import handle_mako_error
|
||||
from pylons import config
|
||||
|
||||
import r2.config
|
||||
@@ -72,28 +74,39 @@ def load_environment(global_conf={}, app_conf={}, setup_globals=True):
|
||||
#override the default response options
|
||||
config['pylons.response_options']['headers'] = {}
|
||||
|
||||
# The following template options are passed to your template engines
|
||||
tmpl_options = config['buffet.template_options']
|
||||
tmpl_options['mako.filesystem_checks'] = getattr(g, 'reload_templates', False)
|
||||
tmpl_options['mako.default_filters'] = ["mako_websafe"]
|
||||
tmpl_options['mako.imports'] = \
|
||||
["from r2.lib.filters import websafe, unsafe, mako_websafe",
|
||||
"from pylons import c, g, request",
|
||||
"from pylons.i18n import _, ungettext"]
|
||||
|
||||
# when mako loads a previously compiled template file from its cache, it
|
||||
# doesn't check that the original template path matches the current path.
|
||||
# in the event that a new plugin defines a template overriding a reddit
|
||||
# template, unless the mtime newer, mako doesn't update the compiled
|
||||
# template. as a workaround, this makes mako store compiled templates with
|
||||
# the original path in the filename, forcing it to update with the path.
|
||||
def mako_module_path(filename, uri):
|
||||
module_directory = tmpl_options['mako.module_directory']
|
||||
filename = filename.lstrip('/').replace('/', '-')
|
||||
path = os.path.join(module_directory, filename + ".py")
|
||||
return os.path.abspath(path)
|
||||
if "cache_dir" in app_conf:
|
||||
module_directory = os.path.join(app_conf['cache_dir'], 'templates')
|
||||
|
||||
tmpl_options['mako.modulename_callable'] = mako_module_path
|
||||
def mako_module_path(filename, uri):
|
||||
filename = filename.lstrip('/').replace('/', '-')
|
||||
path = os.path.join(module_directory, filename + ".py")
|
||||
return os.path.abspath(path)
|
||||
else:
|
||||
# we're probably in "paster run standalone" mode. we'll just avoid
|
||||
# caching templates since we don't know where they should go.
|
||||
module_directory = mako_module_path = None
|
||||
|
||||
# set up the templating system
|
||||
config["pylons.g"].mako_lookup = TemplateLookup(
|
||||
directories=paths["templates"],
|
||||
error_handler=handle_mako_error,
|
||||
module_directory=module_directory,
|
||||
input_encoding="utf-8",
|
||||
default_filters=["mako_websafe"],
|
||||
filesystem_checks=getattr(g, "reload_templates", False),
|
||||
imports=[
|
||||
"from r2.lib.filters import websafe, unsafe, mako_websafe",
|
||||
"from pylons import c, g, request",
|
||||
"from pylons.i18n import _, ungettext",
|
||||
],
|
||||
modulename_callable=mako_module_path,
|
||||
)
|
||||
|
||||
if setup_globals:
|
||||
g.setup_complete()
|
||||
|
||||
@@ -142,8 +142,7 @@ class ErrorController(RedditController):
|
||||
else:
|
||||
template_name = '/ratelimit_throttled.html'
|
||||
|
||||
loader = pylons.buffet.engines['mako']['engine']
|
||||
template = loader.load_template(template_name)
|
||||
template = g.mako_lookup.get_template(template_name)
|
||||
return template.render(logo_url=static(g.default_header_url))
|
||||
|
||||
def send503(self):
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
import pylons
|
||||
from pylons import g
|
||||
import hashlib
|
||||
from mako.template import Template as mTemplate
|
||||
from mako.exceptions import TemplateLookupException
|
||||
@@ -31,9 +31,8 @@ from r2.lib.utils import Storage
|
||||
import inspect, re, os
|
||||
|
||||
class tp_manager:
|
||||
def __init__(self, engine = 'mako', template_cls = mTemplate):
|
||||
def __init__(self, template_cls=mTemplate):
|
||||
self.templates = {}
|
||||
self.engine = engine
|
||||
self.Template = template_cls
|
||||
|
||||
def add(self, name, style, file = None):
|
||||
@@ -70,8 +69,7 @@ class tp_manager:
|
||||
break
|
||||
else:
|
||||
try:
|
||||
_loader = pylons.buffet.engines[self.engine]['engine']
|
||||
template = _loader.load_template(template_or_name)
|
||||
template = g.mako_lookup.get_template(template_or_name)
|
||||
if cache:
|
||||
self.templates[key] = template
|
||||
# also store a hash for the template
|
||||
|
||||
Reference in New Issue
Block a user