# HG changeset patch # User Thierry Florac # Date 1530786785 -7200 # Node ID a211d8c17334e43ddd415615c96f5089c7a19b92 # Parent 2b5123202f9f8535c824afc527432e58d726d8a3 Use metas to render title diff -r 2b5123202f9f -r a211d8c17334 src/pyams_skin/metas.py --- a/src/pyams_skin/metas.py Thu Jul 05 09:16:19 2018 +0200 +++ b/src/pyams_skin/metas.py Thu Jul 05 12:33:05 2018 +0200 @@ -9,6 +9,7 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # +from pyams_i18n.interfaces import II18n __docformat__ = 'restructuredtext' @@ -50,6 +51,22 @@ # @implementer(IMetaHeader) +class HTMLTagMeta(object): + """HTML tag meta header""" + + def __init__(self, tag, content, **attrs): + self.tag = tag + self.content = content + self.attrs = attrs + + def render(self): + return '''<{tag} {attrs}>{content}'''.format(tag=self.tag, + attrs=' '.join(('{0}="{1}"'.format(*value) for value in + self.attrs.items())), + content=self.content) + + +@implementer(IMetaHeader) class HTTPEquivMeta(object): """HTTP-Equiv meta header""" @@ -133,6 +150,17 @@ yield ContentMeta('viewport', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no') +@adapter_config(name='title', context=(Interface, Interface, Interface), provides=IHTMLContentMetas) +class TitleMetasAdapter(ContextRequestViewAdapter): + """Title metas adapter""" + + order = 1 + + def get_metas(self): + title = II18n(self.context).query_attribute('title', request=self.request) + yield HTMLTagMeta('title', title) + + @adapter_config(name='content-type', context=(Interface, Interface, Interface), provides=IHTMLContentMetas) class ContentTypeMetasAdapter(ContextRequestViewAdapter): """Content-type metas adapter"""