|
1 ### -*- coding: utf-8 -*- #################################################### |
|
2 ############################################################################## |
|
3 # |
|
4 # Copyright (c) 2008-2010 Thierry Florac <tflorac AT ulthar.net> |
|
5 # All Rights Reserved. |
|
6 # |
|
7 # This software is subject to the provisions of the Zope Public License, |
|
8 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
12 # FOR A PARTICULAR PURPOSE. |
|
13 # |
|
14 ############################################################################## |
|
15 |
|
16 __docformat__ = "restructuredtext" |
|
17 |
|
18 # import standard packages |
|
19 |
|
20 # import Zope3 interfaces |
|
21 from zope.tales.interfaces import ITALESFunctionNamespace |
|
22 |
|
23 # import local interfaces |
|
24 from ztfy.baseskin.interfaces import IPresentationTarget |
|
25 from ztfy.baseskin.interfaces.metas import IPageMetasHeaders |
|
26 from ztfy.baseskin.tal.interfaces import ISkinTalesAPI, IContentMetasAPI |
|
27 |
|
28 # import Zope3 packages |
|
29 from zope.component import queryMultiAdapter |
|
30 from zope.interface import implements |
|
31 |
|
32 # import local packages |
|
33 |
|
34 |
|
35 class SkinTalesAPI(object): |
|
36 |
|
37 implements(ISkinTalesAPI, ITALESFunctionNamespace) |
|
38 |
|
39 def __init__(self, context): |
|
40 self.context = context |
|
41 |
|
42 def setEngine(self, engine): |
|
43 self.request = engine.vars['request'] |
|
44 |
|
45 def presentation(self): |
|
46 adapter = queryMultiAdapter((self.context, self.request), IPresentationTarget) |
|
47 if adapter is not None: |
|
48 interface = adapter.target_interface |
|
49 return interface(self.context) |
|
50 |
|
51 |
|
52 class ContentMetasTalesAPI(object): |
|
53 |
|
54 implements(IContentMetasAPI, ITALESFunctionNamespace) |
|
55 |
|
56 def __init__(self, context): |
|
57 self.context = context |
|
58 |
|
59 def setEngine(self, engine): |
|
60 self.request = engine.vars['request'] |
|
61 |
|
62 def items(self): |
|
63 headers = queryMultiAdapter((self.context, self.request), IPageMetasHeaders) |
|
64 if headers is None: |
|
65 return [] |
|
66 else: |
|
67 return headers.metas |
|
68 |
|
69 def render(self): |
|
70 headers = queryMultiAdapter((self.context, self.request), IPageMetasHeaders) |
|
71 if headers is None: |
|
72 return u'' |
|
73 else: |
|
74 return '\n'.join((meta.render() for meta in headers.metas)) |