root/livinglogic.python.xist/src/ll/xist/ns/meta.py @ 2590:7b6bba35f3a0

Revision 2590:7b6bba35f3a0, 5.1 KB (checked in by Walter Doerwald <walter@…>, 13 years ago)

htmlspecials.pixel() now no longer uses colored pixels, instead color is
done via CSS. The URL for the one remaining transparent pixel can now be
specified via src (either as an XML attribute or via the converter context).

Rename attrs methods with() and without() to withnames() and withoutnames()
(for Python 2.5 compatibility).

Use elinks instead of w3m for asText() and move/rename this method to a
function ll.xist.ns.html.astext().

Try to make XIST independent from PyXML (however PyXML is still required
for parsing via expat and for dtd2xsc.py (because this requires xmlproc)).

Remove the long dperecated method withSep().

Use Py_ssize_t in the C source where appropriate.

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