root/livinglogic.python.xist/src/ll/xist/ns/meta.py @ 3109:55f21964e0a3

Revision 3109:55f21964e0a3, 5.1 KB (checked in by Walter Doerwald <walter@…>, 12 years ago)

Add docformat.

Line 
1# -*- coding: utf-8 -*-
2
3## Copyright 1999-2008 by LivingLogic AG, Bayreuth/Germany
4## Copyright 1999-2008 by Walter Dörwald
5##
6## All Rights Reserved
7##
8## See xist/__init__.py for the license
9
10
11"""
12<par>An &xist; module that contains elements that simplify
13handling meta data. All elements in this module will generate a
14<pyref module="ll.xist.ns.html" class="meta"><class>html.meta</class></pyref>
15element when converted.</par>
16"""
17
18
19from ll.xist import xsc, sims
20from ll.xist.ns import ihtml, html
21
22
23__docformat__ = "xist"
24
25
26xmlns = "http://xmlns.livinglogic.de/xist/ns/meta"
27
28
29class contenttype(html.meta):
30    """
31    <par>Can be used for a <markup>&lt;meta http-equiv="Content-Type" content="text/html"/&gt;</markup>,
32    where the character set will be automatically inserted on a call to
33    <pyref module="ll.xist.xsc" class="Node" method="publish"><method>publish</method></pyref>.</par>
34
35    <par>Usage is simple: <markup>&lt;meta:contenttype/&gt;</markup></par>
36    """
37    xmlns = xmlns
38    class Attrs(html.meta.Attrs):
39        http_equiv = None
40        name = None
41        content = None
42        class mimetype(xsc.TextAttr):
43            required = True
44            default = u"text/html"
45
46    def convert(self, converter):
47        target = converter.target
48        if target.xmlns in (ihtml.xmlns, html.xmlns):
49            e = target.meta(
50                self.attrs.withoutnames(u"mimetype"),
51                http_equiv=u"Content-Type",
52                content=self[u"mimetype"],
53            )
54        else:
55            raise ValueError("unknown conversion target %r" % target)
56        return e.convert(converter)
57
58    def publish(self, publisher):
59        # fall back to the Element method
60        return xsc.Element.publish(self, publisher) # return a generator-iterator
61
62
63class contentscripttype(html.meta):
64    """
65    <par>Can be used for a <markup>&lt;meta http-equiv="Content-Script-Type" content="..."/&gt;</markup>.</par>
66
67    <par>Usage is simple: <markup>&lt;meta:contentscripttype type="text/javascript"/&gt;</markup></par>
68    """
69    xmlns = xmlns
70    class Attrs(html.meta.Attrs):
71        http_equiv = None
72        name = None
73        content = None
74        class type(xsc.TextAttr): pass
75
76    def convert(self, converter):
77        e = html.meta(self.attrs.withoutnames(u"type"))
78        e[u"http_equiv"] = u"Content-Script-Type"
79        e[u"content"] = self[u"type"]
80        return e.convert(converter)
81
82
83class keywords(html.meta):
84    """
85    <par>Can be used for a <markup>&lt;meta name="keywords" content="..."/&gt;</markup>.</par>
86
87    <par>Usage is simple: <markup>&lt;meta:keywords&gt;foo, bar&lt;/meta:keywords&gt;</markup></par>
88    """
89    xmlns = xmlns
90    model = sims.NoElements()
91    class Attrs(html.meta.Attrs):
92        http_equiv = None
93        name = None
94        content = None
95
96    def convert(self, converter):
97        e = html.meta(self.attrs)
98        e[u"name"] = u"keywords"
99        e[u"content"] = self.content
100        return e.convert(converter)
101
102
103class description(html.meta):
104    """
105    <par>Can be used for a <markup>&lt;meta name="description" content="..."/&gt;</markup>.</par>
106
107    <par>Usage is simple: <markup>&lt;meta:description&gt;This page describes the ...&lt;/meta:description&gt;</markup></par>
108    """
109    xmlns = xmlns
110    model = sims.NoElements()
111    class Attrs(html.meta.Attrs):
112        http_equiv = None
113        name = None
114        content = None
115
116    def convert(self, converter):
117        e = html.meta(self.attrs)
118        e[u"name"] = u"description"
119        e[u"content"] = self.content
120        return e.convert(converter)
121
122
123class stylesheet(html.link):
124    """
125    <par>Can be used for a <markup>&lt;link rel="stylesheet" type="text/css" href="..."/&gt;</markup>.</par>
126
127    <par>Usage is simple: <markup>&lt;meta:stylesheet href="root:stylesheets/main.css"/&gt;</markup></par>
128    """
129    xmlns = xmlns
130    class Attrs(html.link.Attrs):
131        rel = None
132        type = None
133
134    def convert(self, converter):
135        e = html.link(self.attrs, rel=u"stylesheet", type=u"text/css")
136        return e.convert(converter)
137
138
139class made(html.link):
140    """
141    <par>Can be used for a <markup>&lt;link rel="made" href="mailto:..."/&gt;</markup>.</par>
142
143    <par>Usage is simple: <markup>&lt;meta:made href="foobert@bar.org"/&gt;</markup>.</par>
144    """
145    xmlns = xmlns
146    class Attrs(html.link.Attrs):
147        rel = None
148
149    def convert(self, converter):
150        e = html.link(self.attrs, rel=u"made", href=(u"mailto:", self[u"href"]))
151        return e.convert(converter)
152
153
154class author(xsc.Element):
155    """
156    <par>Can be used to embed author information in the header.
157    It will generate <markup>&lt;link rel="made"/&gt;</markup> and
158    <markup>&lt;meta name="author"/&gt;</markup> elements.</par>
159    """
160    xmlns = xmlns
161    model = sims.Empty()
162    class Attrs(xsc.Element.Attrs):
163        class lang(xsc.TextAttr): pass
164        class name(xsc.TextAttr): pass
165        class email(xsc.TextAttr): pass
166
167    def convert(self, converter):
168        e = xsc.Frag()
169        if u"name" in self.attrs:
170            e.append(html.meta(name=u"author", content=self[u"name"]))
171            if u"lang" in self.attrs:
172                e[-1][u"lang"] = self[u"lang"]
173        if u"email" in self.attrs:
174            e.append(html.link(rel=u"made", href=(u"mailto:", self[u"email"])))
175        return e.convert(converter)
176
177
178class refresh(xsc.Element):
179    """
180    <par>A refresh header.</par>
181    """
182    xmlns = xmlns
183    model = sims.Empty()
184    class Attrs(xsc.Element.Attrs):
185        class secs(xsc.IntAttr):
186            default = 0
187        class href(xsc.URLAttr): pass
188
189    def convert(self, converter):
190        e = html.meta(http_equiv=u"Refresh", content=(self[u"secs"], u"; url=", self[u"href"]))
191        return e.convert(converter)
Note: See TracBrowser for help on using the browser.