skeleton: use a more flexible output for empty placeholders (#7411)

This commit is contained in:
Frédéric Péters 2015-05-29 12:16:41 +02:00
parent 780d437f60
commit b1bb35a952
3 changed files with 25 additions and 7 deletions

View File

@ -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):

View File

@ -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

View File

@ -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