Add :reader

Uses wheezy.template, which is said to be fast and light. Provided template file is really basic, custom css suggested.
master
pictuga 2014-05-29 14:12:16 +02:00
parent 814ff46fbd
commit f90958149e
4 changed files with 62 additions and 2 deletions

View File

@ -10,6 +10,13 @@ from StringIO import StringIO
import json
import csv
try:
from wheezy.template.engine import Engine
from wheezy.template.loader import DictLoader
from wheezy.template.ext.core import CoreExtension
except ImportError:
Engine = DictLoader = CoreExtension = None
json.encoder.c_make_encoder = None
try:
@ -353,6 +360,15 @@ class FeedParser(FeedBase):
out.seek(0)
return out.read()
def tohtml(self):
if DictLoader is None:
log('dep wheezy.template needed')
loader = DictLoader({'reader': open('reader.html.template').read()})
engine = Engine(loader=loader, extensions=[CoreExtension()])
template = engine.get_template('reader')
return template.render({'feed':self}).encode('utf-8')
class FeedParserRSS(FeedParser):
"""
RSS Parser

View File

@ -644,6 +644,8 @@ def After(rss, options):
return rss.tojson()
elif options.csv:
return rss.tocsv()
elif options.reader:
return rss.tohtml()
else:
return rss.tostring(xml_declaration=True, encoding='UTF-8')
@ -692,7 +694,7 @@ def cgi_app(environ, start_response):
headers['status'] = '200 OK'
headers['etag'] = '"%s"' % int(time.time())
if options.html:
if options.html or options.reader:
headers['content-type'] = 'text/html'
elif options.debug or options.txt:
headers['content-type'] = 'text/plain'

View File

@ -0,0 +1,41 @@
@require(feed)
<!DOCTYPE html>
<html>
<head>
<title>@feed.title &#8211; via morss</title>
<meta charset="UTF-8" />
<meta name="description" content="@feed.desc (via morss)" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
<link rel="stylesheet" href="https://thisisdallas.github.io/Simple-Grid/simpleGrid.css" />
</head>
<body>
<div id="header">
<h1>@feed.title</h1>
@if feed.desc:
<h2>@feed.desc</h2>
@end
<p>- via morss</p>
</div>
<div id="content" class="grid grid-pad">
@for item in feed.items:
<div class="col-1-3">
<div class="item">
<a class="title link" href="@item.link" target="_blank">@item.title</a>
<div class="article">@item.content</div>
</div>
</div>
@end
</div>
<script>
var items = document.getElementsByClassName('item')
for (var i in items)
items[i].onclick = function()
{
this.classList.toggle('active')
}
</script>
</body>
</html>

View File

@ -13,6 +13,7 @@ setup( name='morss',
'python-dateutil <= 1.5',
'lxml',
'html2text',
'ordereddict'
'ordereddict',
'wheezy.template'
]
)