7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
10 # FOR A PARTICULAR PURPOSE. |
10 # FOR A PARTICULAR PURPOSE. |
11 # |
11 # |
|
12 from pyams_i18n.interfaces import II18n |
12 |
13 |
13 __docformat__ = 'restructuredtext' |
14 __docformat__ = 'restructuredtext' |
14 |
15 |
15 |
16 |
16 # import standard library |
17 # import standard library |
46 |
47 |
47 |
48 |
48 # |
49 # |
49 # Custom metas headers |
50 # Custom metas headers |
50 # |
51 # |
|
52 |
|
53 @implementer(IMetaHeader) |
|
54 class HTMLTagMeta(object): |
|
55 """HTML tag meta header""" |
|
56 |
|
57 def __init__(self, tag, content, **attrs): |
|
58 self.tag = tag |
|
59 self.content = content |
|
60 self.attrs = attrs |
|
61 |
|
62 def render(self): |
|
63 return '''<{tag} {attrs}>{content}</{tag}>'''.format(tag=self.tag, |
|
64 attrs=' '.join(('{0}="{1}"'.format(*value) for value in |
|
65 self.attrs.items())), |
|
66 content=self.content) |
|
67 |
51 |
68 |
52 @implementer(IMetaHeader) |
69 @implementer(IMetaHeader) |
53 class HTTPEquivMeta(object): |
70 class HTTPEquivMeta(object): |
54 """HTTP-Equiv meta header""" |
71 """HTTP-Equiv meta header""" |
55 |
72 |
131 yield HTTPEquivMeta('X-UA-Compatible', 'IE=edge,chrome=1') |
148 yield HTTPEquivMeta('X-UA-Compatible', 'IE=edge,chrome=1') |
132 yield ContentMeta('HandheldFriendly', 'True') |
149 yield ContentMeta('HandheldFriendly', 'True') |
133 yield ContentMeta('viewport', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no') |
150 yield ContentMeta('viewport', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no') |
134 |
151 |
135 |
152 |
|
153 @adapter_config(name='title', context=(Interface, Interface, Interface), provides=IHTMLContentMetas) |
|
154 class TitleMetasAdapter(ContextRequestViewAdapter): |
|
155 """Title metas adapter""" |
|
156 |
|
157 order = 1 |
|
158 |
|
159 def get_metas(self): |
|
160 title = II18n(self.context).query_attribute('title', request=self.request) |
|
161 yield HTMLTagMeta('title', title) |
|
162 |
|
163 |
136 @adapter_config(name='content-type', context=(Interface, Interface, Interface), provides=IHTMLContentMetas) |
164 @adapter_config(name='content-type', context=(Interface, Interface, Interface), provides=IHTMLContentMetas) |
137 class ContentTypeMetasAdapter(ContextRequestViewAdapter): |
165 class ContentTypeMetasAdapter(ContextRequestViewAdapter): |
138 """Content-type metas adapter""" |
166 """Content-type metas adapter""" |
139 |
167 |
140 order = 10 |
168 order = 10 |