~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/web/feeds/templates.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
 
9
9
class Template(MarkupTemplate):
10
 
    
 
10
 
11
11
    def generate(self, *args, **kwargs):
12
12
        if not kwargs.has_key('style'):
13
13
            kwargs['style'] = ''
17
17
        for arg in args:
18
18
            if isinstance(arg, basestring) and not isinstance(arg, unicode):
19
19
                arg = unicode(arg, 'utf-8', 'replace')
20
 
        
 
20
 
21
21
        return MarkupTemplate.generate(self, *args, **kwargs)
22
 
    
 
22
 
23
23
class NavBarTemplate(Template):
24
 
    
 
24
 
25
25
    def __init__(self):
26
26
        Template.__init__(self, u'''\
27
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 
27
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
28
28
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
29
 
<html xmlns="http://www.w3.org/1999/xhtml" 
 
29
<html xmlns="http://www.w3.org/1999/xhtml"
30
30
      xml:lang="en"
31
31
      xmlns:xi="http://www.w3.org/2001/XInclude"
32
 
      xmlns:py="http://genshi.edgewall.org/" 
33
 
       
 
32
      xmlns:py="http://genshi.edgewall.org/"
 
33
 
34
34
>
35
35
    <head>
36
36
        <style py:if="extra_css" type="text/css">
38
38
        </style>
39
39
    </head>
40
40
    <body>
41
 
        <div class="navbar" style="text-align:${'center' if center else 'left'};">
 
41
        <div class="navbar calibre_rescale_70" style="text-align:${'center' if center else 'left'};">
42
42
            <hr py:if="bottom" />
43
43
            <p py:if="bottom" style="text-align:left">
44
44
                This article was downloaded by <b>${__appname__}</b> from <a href="${url}">${url}</a>
50
50
            <py:if test="art == num - 1 and not bottom">
51
51
            | <a href="${prefix}../../feed_${str(feed+1)}/index.html">Next</a>
52
52
            </py:if>
53
 
            | <a href="${prefix}../index.html#article_${str(art)}">Section menu</a> 
 
53
            | <a href="${prefix}../index.html#article_${str(art)}">Section menu</a>
54
54
            <py:if test="two_levels">
55
55
            | <a href="${prefix}../../index.html#feed_${str(feed)}">Main menu</a>
56
56
            </py:if>
64
64
</html>
65
65
''')
66
66
 
67
 
    def generate(self, bottom, feed, art, number_of_articles_in_feed, 
 
67
    def generate(self, bottom, feed, art, number_of_articles_in_feed,
68
68
                 two_levels, url, __appname__, prefix='', center=True,
69
69
                 extra_css=None):
70
70
        if prefix and not prefix.endswith('/'):
71
71
            prefix += '/'
72
72
        return Template.generate(self, bottom=bottom, art=art, feed=feed,
73
 
                                 num=number_of_articles_in_feed, 
 
73
                                 num=number_of_articles_in_feed,
74
74
                                 two_levels=two_levels, url=url,
75
75
                                 __appname__=__appname__, prefix=prefix,
76
76
                                 center=center, extra_css=extra_css)
77
 
    
 
77
 
78
78
 
79
79
class IndexTemplate(Template):
80
 
    
 
80
 
81
81
    def __init__(self):
82
82
        Template.__init__(self, u'''\
83
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 
83
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
84
84
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
85
 
<html xmlns="http://www.w3.org/1999/xhtml" 
 
85
<html xmlns="http://www.w3.org/1999/xhtml"
86
86
      xml:lang="en"
87
87
      xmlns:xi="http://www.w3.org/2001/XInclude"
88
 
      xmlns:py="http://genshi.edgewall.org/" 
89
 
       
 
88
      xmlns:py="http://genshi.edgewall.org/"
 
89
 
90
90
>
91
91
    <head>
92
92
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
99
99
        </style>
100
100
    </head>
101
101
    <body>
102
 
        <h1 class="calibre_recipe_title">${title}</h1>
103
 
        <p style="text-align:right">${date}</p>
104
 
        <ul class="calibre_feed_list">
105
 
            <py:for each="i, feed in enumerate(feeds)">
106
 
            <li py:if="feed" id="feed_${str(i)}">
107
 
                <a class="feed" href="${'feed_%d/index.html'%i}">${feed.title}</a>
108
 
            </li>
109
 
            </py:for>
110
 
        </ul>
 
102
        <div class="calibre_rescale_100">
 
103
            <h1 class="calibre_recipe_title calibre_rescale_180">${title}</h1>
 
104
            <p style="text-align:right">${date}</p>
 
105
            <ul class="calibre_feed_list">
 
106
                <py:for each="i, feed in enumerate(feeds)">
 
107
                <li py:if="feed" id="feed_${str(i)}">
 
108
                    <a class="feed calibre_rescale_120" href="${'feed_%d/index.html'%i}">${feed.title}</a>
 
109
                </li>
 
110
                </py:for>
 
111
            </ul>
 
112
        </div>
111
113
    </body>
112
114
</html>
113
115
''')
118
120
        date = strftime(datefmt)
119
121
        return Template.generate(self, title=title, date=date, feeds=feeds,
120
122
                                 extra_css=extra_css)
121
 
    
122
 
    
 
123
 
 
124
 
123
125
class FeedTemplate(Template):
124
 
    
 
126
 
125
127
    def __init__(self):
126
128
        Template.__init__(self, u'''\
127
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 
129
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
128
130
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
129
 
<html xmlns="http://www.w3.org/1999/xhtml" 
 
131
<html xmlns="http://www.w3.org/1999/xhtml"
130
132
      xml:lang="en"
131
133
      xmlns:xi="http://www.w3.org/2001/XInclude"
132
 
      xmlns:py="http://genshi.edgewall.org/" 
133
 
       
 
134
      xmlns:py="http://genshi.edgewall.org/"
 
135
 
134
136
>
135
137
    <head>
136
138
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
143
145
        </style>
144
146
    </head>
145
147
    <body style="page-break-before:always">
146
 
        <h2 class="calibre_feed_title">${feed.title}</h2>
 
148
    <div class="calibre_rescale_100">
 
149
        <h2 class="calibre_feed_title calibre_rescale_160">${feed.title}</h2>
147
150
        <py:if test="getattr(feed, 'image', None)">
148
151
        <div class="calibre_feed_image">
149
152
            <img alt="${feed.image_alt}" src="${feed.image_url}" />
150
153
        </div>
151
154
        </py:if>
152
 
        <div class="calibre_feed_description" py:if="getattr(feed, 'description', None)">
 
155
        <div class="calibre_feed_description calibre_rescale_80" py:if="getattr(feed, 'description', None)">
153
156
            ${feed.description}<br />
154
157
        </div>
155
158
        <ul class="calibre_article_list">
156
159
            <py:for each="i, article in enumerate(feed.articles)">
157
 
            <li id="${'article_%d'%i}" py:if="getattr(article, 'downloaded', False)" style="padding-bottom:0.5em">
158
 
                <a class="article" href="${article.url}">${article.title}</a>
 
160
            <li id="${'article_%d'%i}" py:if="getattr(article, 'downloaded',
 
161
            False)" style="padding-bottom:0.5em" class="calibre_rescale_100">
 
162
                <a class="article calibre_rescale_120" href="${article.url}">${article.title}</a>
159
163
                <span class="article_date">${article.localtime.strftime(" [%a, %d %b %H:%M]")}</span>
160
 
                <div class="article_decription" py:if="article.summary">
 
164
                <div class="article_description calibre_rescale_70" py:if="article.summary">
161
165
                    ${Markup(cutoff(article.text_summary))}
162
166
                </div>
163
167
            </li>
164
168
            </py:for>
165
169
        </ul>
166
 
        <div class="navbar" style="text-align:center; font-family:monospace; font-size:8pt">
 
170
        <div class="navbar calibre_rescale_70">
167
171
            | <a href="../index.html">Up one level</a> |
168
172
        </div>
 
173
        </div>
169
174
    </body>
170
175
</html>
171
176
''')
172
 
        
 
177
 
173
178
    def generate(self, feed, cutoff, extra_css=None):
174
 
        return Template.generate(self, feed=feed, cutoff=cutoff, 
 
179
        return Template.generate(self, feed=feed, cutoff=cutoff,
175
180
                                 extra_css=extra_css)
176
181
 
177
182
class EmbeddedContent(Template):
178
 
    
 
183
 
179
184
    def __init__(self):
180
185
        Template.__init__(self, u'''\
181
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
 
186
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
182
187
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
183
 
<html xmlns="http://www.w3.org/1999/xhtml" 
 
188
<html xmlns="http://www.w3.org/1999/xhtml"
184
189
      xml:lang="en"
185
190
      xmlns:xi="http://www.w3.org/2001/XInclude"
186
 
      xmlns:py="http://genshi.edgewall.org/" 
187
 
       
 
191
      xmlns:py="http://genshi.edgewall.org/"
 
192
 
188
193
>
189
194
    <head>
190
195
        <title>${article.title}</title>
191
196
    </head>
192
 
    
 
197
 
193
198
    <body>
194
199
        <h2>${article.title}</h2>
195
200
        <div>
196
201
            ${Markup(article.content if len(article.content if article.content else '') > len(article.summary if article.summary else '') else article.summary)}
197
202
        </div>
198
203
    </body>
199
 
</html> 
 
204
</html>
200
205
''')
201
 
    
 
206
 
202
207
    def generate(self, article):
203
208
        return Template.generate(self, article=article)