# HG changeset patch # User Thierry Florac # Date 1527228352 -7200 # Node ID bca2dd39ef7f1c4a30d9279771afd873e87f0ad2 # Parent 7f8ae123d371b6ff941fea790593ac9a1729b514 Add default renderers for HTML paragraphs diff -r 7f8ae123d371 -r bca2dd39ef7f src/pyams_default_theme/component/paragraph/__init__.py --- a/src/pyams_default_theme/component/paragraph/__init__.py Fri May 18 08:50:30 2018 +0200 +++ b/src/pyams_default_theme/component/paragraph/__init__.py Fri May 25 08:05:52 2018 +0200 @@ -12,8 +12,33 @@ __docformat__ = 'restructuredtext' + # import standard library # import interfaces +from pyams_content.component.paragraph.interfaces import IBaseParagraph +from pyams_default_theme.layer import IPyAMSDefaultLayer +from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION # import packages +from pyams_default_theme.page import BaseIndexPage +from pyams_pagelet.pagelet import pagelet_config + + +@pagelet_config(name='preview.html', context=IBaseParagraph, layer=IPyAMSDefaultLayer, + permission=VIEW_SYSTEM_PERMISSION) +class ParagraphPreviewPage(BaseIndexPage): + """Paragraph preview page""" + + def __init__(self, context, request): + super(ParagraphPreviewPage, self).__init__(context, request) + self.language = request.params.get('lang') + self.renderer = context.get_renderer(request) + + def update(self): + super(ParagraphPreviewPage, self).update() + self.renderer.language = self.language + self.renderer.update() + + def render(self): + return self.renderer.render() diff -r 7f8ae123d371 -r bca2dd39ef7f src/pyams_default_theme/component/paragraph/html.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/component/paragraph/html.py Fri May 25 08:05:52 2018 +0200 @@ -0,0 +1,73 @@ +# +# Copyright (c) 2008-2018 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from pyams_content.component.illustration import IIllustration +from pyams_content.component.paragraph.interfaces.html import IRawParagraph, IHTMLParagraph +from pyams_content.features.renderer.interfaces import IContentRenderer +from pyams_skin.layer import IPyAMSLayer + +# import packages +from pyams_content.features.renderer.skin import BaseContentRenderer +from pyams_template.template import template_config +from pyams_utils.adapter import adapter_config + +from pyams_default_theme import _ + + +# +# Raw paragraph default renderer +# + +@adapter_config(name='default', context=(IRawParagraph, IPyAMSLayer), provides=IContentRenderer) +@template_config(template='templates/raw-default.pt', layer=IPyAMSLayer) +class RawParagraphDefaultRenderer(BaseContentRenderer): + """Raw paragraph default renderer""" + + label = _("Default raw HTML renderer") + + i18n_context_attrs = ('title', 'body', ) + + +# +# HTML paragraph default renderer +# + +@adapter_config(name='default', context=(IHTMLParagraph, IPyAMSLayer), provides=IContentRenderer) +@template_config(template='templates/html-default.pt', layer=IPyAMSLayer) +class HTMLParagraphDefaultRenderer(BaseContentRenderer): + """HTML paragraph default renderer""" + + label = _("Default rich text renderer") + + i18n_context_attrs = ('title', 'body', ) + + illustration = None + illustration_renderer = None + + def update(self): + super(HTMLParagraphDefaultRenderer, self).update() + self.illustration = IIllustration(self.context) + if self.illustration.data: + renderer = self.illustration_renderer = self.illustration.get_renderer() + if renderer is not None: + renderer.update() + + def render_illustration(self): + if not self.illustration_renderer: + return '' + return self.illustration_renderer.render() diff -r 7f8ae123d371 -r bca2dd39ef7f src/pyams_default_theme/component/paragraph/templates/html-default.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/component/paragraph/templates/html-default.pt Fri May 25 08:05:52 2018 +0200 @@ -0,0 +1,3 @@ +

title

+
body
+Illustration diff -r 7f8ae123d371 -r bca2dd39ef7f src/pyams_default_theme/component/paragraph/templates/raw-default.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_default_theme/component/paragraph/templates/raw-default.pt Fri May 25 08:05:52 2018 +0200 @@ -0,0 +1,2 @@ +

title

+
body