diff --git a/combo/public/templatetags/combo.py b/combo/public/templatetags/combo.py index a01f3c01..bb893eff 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 8eb67709..44243cdb 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 390f998e..674172e4 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