Added "position" attribute to illustration renderers
authorThierry Florac <thierry.florac@onf.fr>
Mon, 03 Sep 2018 11:22:03 +0200
changeset 123 9638eaef9d34
parent 122 d83485dee19a
child 124 62632a9571d5
Added "position" attribute to illustration renderers
src/pyams_default_theme/component/illustration/__init__.py
src/pyams_default_theme/component/illustration/interfaces/__init__.py
src/pyams_default_theme/component/paragraph/templates/html-default.pt
--- a/src/pyams_default_theme/component/illustration/__init__.py	Thu Aug 30 11:07:17 2018 +0200
+++ b/src/pyams_default_theme/component/illustration/__init__.py	Mon Sep 03 11:22:03 2018 +0200
@@ -19,7 +19,8 @@
 # import interfaces
 from pyams_content.component.illustration.interfaces import IIllustration
 from pyams_content.features.renderer.interfaces import IContentRenderer
-from pyams_default_theme.component.illustration.interfaces import IIllustrationWithZoomSettings
+from pyams_default_theme.component.illustration.interfaces import IIllustrationWithZoomSettings, IIllustrationRenderer, \
+    ILLUSTRATION_AFTER_BODY, ILLUSTRATION_BEFORE_BODY
 from pyams_skin.layer import IPyAMSLayer
 
 # import packages
@@ -57,21 +58,26 @@
 # Illustration renderers
 #
 
+@implementer(IIllustrationRenderer)
 class BaseIllustrationRenderer(BaseContentRenderer):
     """Base illustration renderer"""
 
     context_attrs = ('author', )
     i18n_context_attrs = ('title', 'alt_title', 'description', 'data')
 
+    position = None
 
-@adapter_config(name='default', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer)
+
+@adapter_config(name='centered-before-body', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer)
 @template_config(template='templates/illustration-default.pt', layer=IPyAMSLayer)
 class DefaultIllustrationRenderer(BaseIllustrationRenderer):
     """Default illustration renderer"""
 
-    label = _("Centered illustration")
+    label = _("Centered illustration before text")
     weight = 1
 
+    position = ILLUSTRATION_BEFORE_BODY
+
 
 @adapter_config(name='left+zoom', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer)
 @template_config(template='templates/illustration-left.pt', layer=IPyAMSLayer)
@@ -81,6 +87,7 @@
     label = _("Small illustration on the left")
     weight = 2
 
+    position = ILLUSTRATION_BEFORE_BODY
     settings_interface = IIllustrationWithZoomSettings
 
 
@@ -92,4 +99,16 @@
     label = _("Small illustration on the right")
     weight = 3
 
+    position = ILLUSTRATION_BEFORE_BODY
     settings_interface = IIllustrationWithZoomSettings
+
+
+@adapter_config(name='default', context=(IIllustration, IPyAMSLayer), provides=IContentRenderer)
+@template_config(template='templates/illustration-default.pt', layer=IPyAMSLayer)
+class DefaultIllustrationRenderer(BaseIllustrationRenderer):
+    """Default illustration renderer"""
+
+    label = _("Centered illustration after text")
+    weight = 4
+
+    position = ILLUSTRATION_AFTER_BODY
--- a/src/pyams_default_theme/component/illustration/interfaces/__init__.py	Thu Aug 30 11:07:17 2018 +0200
+++ b/src/pyams_default_theme/component/illustration/interfaces/__init__.py	Mon Sep 03 11:22:03 2018 +0200
@@ -18,16 +18,27 @@
 # import interfaces
 
 # import packages
-from zope.interface import Interface
-from zope.schema import Bool
+from zope.interface import Interface, Attribute
+from zope.schema import Bool, Choice
 
 from pyams_default_theme import _
 
 
+ILLUSTRATION_BEFORE_TITLE = 'before-title'
+ILLUSTRATION_BEFORE_BODY = 'before-body'
+ILLUSTRATION_AFTER_BODY = 'after-body'
+
+
+class IIllustrationRenderer(Interface):
+    """Illustration renderer interface"""
+
+    position = Attribute("Illustration position related to it's attached content")
+
+
 class IIllustrationWithZoomSettings(Interface):
     """Illustration with zoom interface"""
 
     zoom_on_click = Bool(title=_("Zoom on click?"),
                          description=_("If 'yes', a click on illustration thumbnail is required to zoom"),
                          required=True,
-                         default=True)
\ No newline at end of file
+                         default=True)
--- a/src/pyams_default_theme/component/paragraph/templates/html-default.pt	Thu Aug 30 11:07:17 2018 +0200
+++ b/src/pyams_default_theme/component/paragraph/templates/html-default.pt	Mon Sep 03 11:22:03 2018 +0200
@@ -1,3 +1,9 @@
-<h3 tal:content="view.title">title</h3>
-<tal:var content="structure view.render_illustration()">Illustration</tal:var>
-<div tal:content="structure tales:html(view.body, 'oid_to_href')">body</div>
+<tal:var define="renderer view.illustration_renderer;
+				 position renderer.position if renderer is not None else None;"
+		 switch="position">
+	<tal:var case="'before-title'">${structure:view.render_illustration()}</tal:var>
+	<h2 tal:condition="position != 'before-title'">${view.title}</h2>
+	<tal:var case="'before-body'">${structure:view.render_illustration()}</tal:var>
+	<div>${structure:tales:html(view.body, 'oid_to_href')}</div>
+	<tal:var case="'after-body'">${structure:view.render_illustration()}</tal:var>
+</tal:var>