root/livinglogic.python.xist/src/ll/xist/ns/meta.py @ 3080:f605694ae31a

Revision 3080:f605694ae31a, 5.0 KB (checked in by Walter Doerwald <walter@…>, 12 years ago)

Update copyright year (5 days too early, but XIST 3.0 probably won't get released in the next 5 days).

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