summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2015-05-29 10:16:41 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2015-05-29 11:56:36 (GMT)
commitb1bb35a952394fe0d0a441a774caf63fcbdbcd65 (patch)
treeba42ff3864fd451832d12bf4f9a877ce8a5e0a73
parent780d437f60fe61c0cf255c3e109812e1700319ed (diff)
downloadcombo-b1bb35a952394fe0d0a441a774caf63fcbdbcd65.zip
combo-b1bb35a952394fe0d0a441a774caf63fcbdbcd65.tar.gz
combo-b1bb35a952394fe0d0a441a774caf63fcbdbcd65.tar.bz2
skeleton: use a more flexible output for empty placeholders (#7411)
-rw-r--r--combo/public/templatetags/combo.py3
-rw-r--r--combo/public/views.py17
-rw-r--r--tests/test_public.py12
3 files changed, 25 insertions, 7 deletions
diff --git a/combo/public/templatetags/combo.py b/combo/public/templatetags/combo.py
index a01f3c0..bb893ef 100644
--- a/combo/public/templatetags/combo.py
+++ b/combo/public/templatetags/combo.py
@@ -29,7 +29,8 @@ register = template.Library()
def skeleton_text(context, placeholder_name):
if context['request'].GET.get('format') == 'ezt':
return '[if-any %s][%s][end]' % (placeholder_name, placeholder_name)
- return '{%% block %s %%}{%% endblock %%}' % placeholder_name
+ return '{%% block placeholder-%s %%}{%% block %s %%}{%% endblock %%}{%% endblock %%}' % (
+ placeholder_name, placeholder_name)
@register.inclusion_tag('combo/placeholder.html', takes_context=True)
def placeholder(context, placeholder_name):
diff --git a/combo/public/views.py b/combo/public/views.py
index 8eb6770..44243cd 100644
--- a/combo/public/views.py
+++ b/combo/public/views.py
@@ -103,6 +103,23 @@ def extend_with_locked_placeholders_cells(cells, page, pages):
def skeleton(request):
+ # Skeleton rendering is used to dynamically produce base templates to use
+ # in other applications, based on configured combo cells.
+ #
+ # It takes a ?source= parameter that should contain the URL we want a
+ # template for; it will be used to match the corresponding page, and thus
+ # the corresponding content. If there's no matching page, an error will be
+ # raised. (403 Access Forbidden)
+ #
+ # While placeholders holding cells will get their cells rendered, empty
+ # placeholders will get themself outputted as template blocks, named
+ # placeholder-$name, and with a default content of a block named $name.
+ #
+ # ex:
+ # {% block placeholder-content %}
+ # {% block content %}
+ # {% endblock %}
+ # {% endblock %}
source = request.GET['source']
selected_page = None
diff --git a/tests/test_public.py b/tests/test_public.py
index 390f998..674172e 100644
--- a/tests/test_public.py
+++ b/tests/test_public.py
@@ -81,13 +81,13 @@ def test_page_skeleton():
# url prefix match
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.net/foo/bar'))
- assert '{% block content %}{% endblock %}' in resp.body
- assert '{% block footer %}{% endblock %}' in resp.body
+ assert '{% block placeholder-content %}{% block content %}{% endblock %}{% endblock %}' in resp.body
+ assert '{% block placeholder-footer %}{% block footer %}{% endblock %}{% endblock %}' in resp.body
# url netloc match
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.net'))
- assert '{% block content %}{% endblock %}' in resp.body
- assert '{% block footer %}{% endblock %}' in resp.body
+ assert '{% block placeholder-content %}{% block content %}{% endblock %}{% endblock %}' in resp.body
+ assert '{% block placeholder-footer %}{% block footer %}{% endblock %}{% endblock %}' in resp.body
# no match
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.com/foo/bar'), status=403)
@@ -96,6 +96,6 @@ def test_page_skeleton():
cell = TextCell(page=page, placeholder='footer', text='Foobar', order=0)
cell.save()
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.net'))
- assert '{% block content %}{% endblock %}' in resp.body
- assert not '{% block footer %}{% endblock %}' in resp.body
+ assert '{% block placeholder-content %}{% block content %}{% endblock %}{% endblock %}' in resp.body
+ assert not '{% block placeholder-footer %}{% block footer %}{% endblock %}{% endblock %}' in resp.body
assert 'Foobar' in resp.body