diff --git a/runtests.py b/runtests.py
index 4dd0476706..027d611581 100755
--- a/runtests.py
+++ b/runtests.py
@@ -85,6 +85,7 @@ if not settings.configured:
PASSWORD_HASHERS=(
'django.contrib.auth.hashers.MD5PasswordHasher', # don't use the intentionally slow default password hasher
),
+ COMPRESS_ENABLED=False, # disable compression so that we can run tests on the content of the compress tag
WAGTAILSEARCH_BACKENDS=WAGTAILSEARCH_BACKENDS,
WAGTAIL_SITE_NAME='Test Site'
)
diff --git a/wagtail/tests/wagtail_hooks.py b/wagtail/tests/wagtail_hooks.py
new file mode 100644
index 0000000000..91c76c9f40
--- /dev/null
+++ b/wagtail/tests/wagtail_hooks.py
@@ -0,0 +1,10 @@
+from wagtail.wagtailadmin import hooks
+
+def editor_css():
+ return """"""
+hooks.register('insert_editor_css', editor_css)
+
+
+def editor_js():
+ return """"""
+hooks.register('insert_editor_js', editor_js)
diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html
index 1cd9b3a384..9c6e832e8e 100644
--- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html
+++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html
@@ -1,4 +1,4 @@
-{% load compress %}
+{% load compress wagtailadmin_tags %}
{% comment %}
CSS declarations to be included on the 'create page' and 'edit page' views
@@ -16,6 +16,8 @@
{# we'll want tag-it included, for the benefit of any modals that use it, like images. #}
{# TODO: a method of injecting these sorts of things on demand when the modal is spawned #}
+
+ {% hook_output 'insert_editor_css' %}
{% endcompress %}
{{ edit_handler.form.media.css }}
diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html
index e171373b82..6efaecf12d 100644
--- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html
+++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html
@@ -1,5 +1,4 @@
-{% load compress %}
-{% load localize %}
+{% load wagtailadmin_tags compress localize %}
{% comment %}
Javascript declarations to be included on the 'create page' and 'edit page' views
@@ -22,15 +21,17 @@
{% comment %}
- TODO: have a mechanism to specify image-chooser.js (and hallo-wagtailimage.js)
- within the wagtailimages app -
- ideally wagtailadmin shouldn't have to know anything at all about wagtailimages
+ TODO: use the insert_editor_js hook to inject things like image-chooser.js and hallo-wagtailimage.js
+ from their respective apps such as wagtailimages -
+ ideally wagtailadmin shouldn't have to know anything at all about wagtailimages.
TODO: a method of injecting these sorts of things on demand when the modal is spawned.
{% endcomment %}
+
+ {% hook_output 'insert_editor_js' %}
{% endcompress %}
{% comment %}
diff --git a/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py b/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py
index c694e95d15..a7aaf38fe9 100644
--- a/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py
+++ b/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py
@@ -116,3 +116,15 @@ def page_permissions(context, page):
# Now retrieve a PagePermissionTester from it, specific to the given page
return context['user_page_permissions'].for_page(page)
+
+
+@register.simple_tag
+def hook_output(hook_name):
+ """
+ Example: {% hook_output 'insert_editor_css' %}
+ Whenever we have a hook whose functions take no parameters and return a string, this tag can be used
+ to output the concatenation of all of those return values onto the page.
+ Note that the output is not escaped - it is the hook function's responsibility to escape unsafe content.
+ """
+ snippets = [fn() for fn in hooks.get_hooks(hook_name)]
+ return u''.join(snippets)
diff --git a/wagtail/wagtailadmin/tests.py b/wagtail/wagtailadmin/tests.py
index c3c529417a..84b00b3355 100644
--- a/wagtail/wagtailadmin/tests.py
+++ b/wagtail/wagtailadmin/tests.py
@@ -308,3 +308,21 @@ class TestPageMove(TestCase):
def test_page_set_page_position(self):
response = self.client.get(reverse('wagtailadmin_pages_set_page_position', args=(self.test_page.id, )))
self.assertEqual(response.status_code, 200)
+
+
+class TestEditorHooks(TestCase):
+ def setUp(self):
+ self.homepage = Page.objects.get(id=2)
+ login(self.client)
+
+ def test_editor_css_and_js_hooks_on_add(self):
+ response = self.client.get(reverse('wagtailadmin_pages_create', args=('tests', 'simplepage', self.homepage.id)))
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response, '')
+ self.assertContains(response, '')
+
+ def test_editor_css_and_js_hooks_on_edit(self):
+ response = self.client.get(reverse('wagtailadmin_pages_edit', args=(self.homepage.id, )))
+ self.assertEqual(response.status_code, 200)
+ self.assertContains(response, '')
+ self.assertContains(response, '')