summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mandaye/dispatcher.py9
-rw-r--r--mandaye/filters/default.py22
2 files changed, 31 insertions, 0 deletions
diff --git a/mandaye/dispatcher.py b/mandaye/dispatcher.py
index ed59ac8..3adb812 100644
--- a/mandaye/dispatcher.py
+++ b/mandaye/dispatcher.py
@@ -6,6 +6,7 @@ from urlparse import urlparse
from importlib import import_module
from mandaye import config
+from mandaye.filters.default import MandayeFilter
from mandaye.http import HTTPRequest, HTTPResponse
from mandaye.log import logger
from mandaye.mappers import default
@@ -66,6 +67,14 @@ class Dispatcher(object):
"""
if not mapper.has_key('method') or \
mapper['method'] == self.env['REQUEST_METHOD']:
+ if mapper.has_key('scripts'):
+ req_mapping["on_response"].append(
+ {
+ 'filter': MandayeFilter.add_js_header,
+ 'values': {'scripts': mapper['scripts']},
+ 'content-types': ['text/html']
+ }
+ )
for hookname in req_mapping:
if mapper.has_key(hookname):
if isinstance(req_mapping[hookname], list):
diff --git a/mandaye/filters/default.py b/mandaye/filters/default.py
index 3cfd74a..5be4cb8 100644
--- a/mandaye/filters/default.py
+++ b/mandaye/filters/default.py
@@ -59,6 +59,28 @@ class MandayeFilter(object):
return response
@staticmethod
+ def add_js_header(env, values, request, response):
+ if response.msg:
+ if not "mjQuery = jQuery.noConflict" in response.msg:
+ response.msg = re.sub(
+ r'<head(.*?)>',
+ r"""<head\1>
+ <script src="%s/js/jquery-1.11.1.min.js" type="text/javascript"></script>
+ <script>
+ mjQuery = jQuery.noConflict( true );
+ </script>""" % (config.static_url),
+ response.msg, 1, re.IGNORECASE)
+ scripts_html = ""
+ for script in values["scripts"]:
+ scripts_html += '<script src="%s/%s" charset="UTF-8" type="text/javascript"></script>' % \
+ (config.static_url, script)
+ response.msg = re.sub(
+ '</head>',
+ '%s</head>' % scripts_html,
+ response.msg, 1, re.IGNORECASE)
+ return response
+
+ @staticmethod
def addtoolbar(env, values, request, response):
if config.mandaye_offline_toolbar or \
env['beaker.session'].has_key('unique_id'):