mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GwR wip
This commit is contained in:
parent
9d7cf6d9f2
commit
5d91f7515a
@ -126,6 +126,17 @@ class Stylizer(object):
|
|||||||
head = head[0]
|
head = head[0]
|
||||||
else:
|
else:
|
||||||
head = []
|
head = []
|
||||||
|
|
||||||
|
# GwR : Add webkit profile to cssutils before validating
|
||||||
|
if True:
|
||||||
|
wk_macros = {
|
||||||
|
'border-width': '{length}|thin|medium|thick'
|
||||||
|
}
|
||||||
|
wk_props = {
|
||||||
|
'-webkit-border-radius': r'{border-width}(\s+{border-width}){0,3}|inherit'
|
||||||
|
}
|
||||||
|
cssutils.profile.addProfile('webkit', wk_props, wk_macros)
|
||||||
|
|
||||||
parser = cssutils.CSSParser(fetcher=self._fetch_css_file,
|
parser = cssutils.CSSParser(fetcher=self._fetch_css_file,
|
||||||
log=logging.getLogger('calibre.css'))
|
log=logging.getLogger('calibre.css'))
|
||||||
self.font_face_rules = []
|
self.font_face_rules = []
|
||||||
|
@ -280,6 +280,46 @@ class BasicNewsRecipe(Recipe):
|
|||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
#: The CSS that is used to style the touchscreen elements, i.e., the navigation bars and
|
||||||
|
#: the Feed summaries.
|
||||||
|
touchscreen_css = u'''
|
||||||
|
.article_navbar {
|
||||||
|
-webkit-border-radius:4px;
|
||||||
|
background-color:#eee;
|
||||||
|
border:1px solid #888;
|
||||||
|
margin-left: 5%;
|
||||||
|
margin-right: 5%;
|
||||||
|
width: 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feed_navbar {
|
||||||
|
-webkit-border-radius:4px;
|
||||||
|
background-color:#eee;
|
||||||
|
border:1px solid #888;
|
||||||
|
margin-left: 5%;
|
||||||
|
margin-right: 5%;
|
||||||
|
width: 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary_headline {
|
||||||
|
font-weight:bold; text-align:left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary_byline {
|
||||||
|
text-align:left;
|
||||||
|
font-family:monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary_text {
|
||||||
|
text-align:left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.feed {
|
||||||
|
font-family:sans-serif; font-weight:bold; font-size:larger;
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
#: By default, calibre will use a default image for the masthead (Kindle only).
|
#: By default, calibre will use a default image for the masthead (Kindle only).
|
||||||
#: Override this in your recipe to provide a url to use as a masthead.
|
#: Override this in your recipe to provide a url to use as a masthead.
|
||||||
masthead_url = None
|
masthead_url = None
|
||||||
@ -638,6 +678,9 @@ class BasicNewsRecipe(Recipe):
|
|||||||
if self.delay > 0:
|
if self.delay > 0:
|
||||||
self.simultaneous_downloads = 1
|
self.simultaneous_downloads = 1
|
||||||
|
|
||||||
|
if self.touchscreen:
|
||||||
|
self.extra_css += self.touchscreen_css
|
||||||
|
|
||||||
self.navbar = templates.TouchscreenNavBarTemplate() if self.touchscreen else templates.NavBarTemplate()
|
self.navbar = templates.TouchscreenNavBarTemplate() if self.touchscreen else templates.NavBarTemplate()
|
||||||
self.failed_downloads = []
|
self.failed_downloads = []
|
||||||
self.partial_failures = []
|
self.partial_failures = []
|
||||||
@ -661,8 +704,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
templ = self.navbar.generate(False, f, a, feed_len,
|
templ = self.navbar.generate(False, f, a, feed_len,
|
||||||
not self.has_single_feed,
|
not self.has_single_feed,
|
||||||
url, __appname__,
|
url, __appname__,
|
||||||
center=self.center_navbar,
|
center=self.center_navbar)
|
||||||
extra_css=self.extra_css)
|
|
||||||
elem = BeautifulSoup(templ.render(doctype='xhtml').decode('utf-8')).find('div')
|
elem = BeautifulSoup(templ.render(doctype='xhtml').decode('utf-8')).find('div')
|
||||||
body.insert(0, elem)
|
body.insert(0, elem)
|
||||||
if self.remove_javascript:
|
if self.remove_javascript:
|
||||||
@ -783,43 +825,7 @@ class BasicNewsRecipe(Recipe):
|
|||||||
css = self.template_css + '\n\n' +(self.extra_css if self.extra_css else '')
|
css = self.template_css + '\n\n' +(self.extra_css if self.extra_css else '')
|
||||||
|
|
||||||
if self.touchscreen:
|
if self.touchscreen:
|
||||||
touchscreen_css = u'''
|
|
||||||
.summary_headline {
|
|
||||||
font-weight:bold; text-align:left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.summary_byline {
|
|
||||||
text-align:left;
|
|
||||||
font-family:monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
.summary_text {
|
|
||||||
text-align:left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.feed {
|
|
||||||
font-family:sans-serif; font-weight:bold; font-size:larger;
|
|
||||||
}
|
|
||||||
|
|
||||||
.calibre_navbar {
|
|
||||||
font-family:monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
.touchscreen_navbar {
|
|
||||||
-webkit-border-radius:4px;
|
|
||||||
background:#ccc;
|
|
||||||
border:#ccc 1px solid;
|
|
||||||
margin-left: 25%;
|
|
||||||
margin-right: 25%;
|
|
||||||
width: 50%;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
'''
|
|
||||||
|
|
||||||
templ = templates.TouchscreenFeedTemplate()
|
templ = templates.TouchscreenFeedTemplate()
|
||||||
css = touchscreen_css + '\n\n' + (self.extra_css if self.extra_css else '')
|
|
||||||
|
|
||||||
return templ.generate(f, feeds, self.description_limiter,
|
return templ.generate(f, feeds, self.description_limiter,
|
||||||
extra_css=css).render(doctype='xhtml')
|
extra_css=css).render(doctype='xhtml')
|
||||||
|
@ -5,7 +5,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
from lxml import html, etree
|
from lxml import html, etree
|
||||||
from lxml.html.builder import HTML, HEAD, TITLE, STYLE, DIV, BODY, \
|
from lxml.html.builder import HTML, HEAD, TITLE, STYLE, DIV, BODY, \
|
||||||
STRONG, BR, SPAN, A, HR, UL, LI, H2, IMG, P as PT, \
|
STRONG, EM, BR, SPAN, A, HR, UL, LI, H2, IMG, P as PT, \
|
||||||
TABLE, TD, TR
|
TABLE, TD, TR
|
||||||
|
|
||||||
from calibre import preferred_encoding, strftime, isbytestring
|
from calibre import preferred_encoding, strftime, isbytestring
|
||||||
@ -251,39 +251,23 @@ class TouchscreenFeedTemplate(Template):
|
|||||||
feed = feeds[f]
|
feed = feeds[f]
|
||||||
|
|
||||||
# Construct the navbar
|
# Construct the navbar
|
||||||
if False:
|
navbar_t = TABLE(CLASS('feed_navbar'))
|
||||||
navbar = DIV('', CLASS('calibre_navbar', 'calibre_rescale_100'),style='text-align:center')
|
|
||||||
if f > 0:
|
|
||||||
link = A(trim_title('< ' + feeds[f-1].title + ' '), href = '../feed_%d/index.html' % int(f-1))
|
|
||||||
#link.tail = ' |'
|
|
||||||
navbar.append(link)
|
|
||||||
|
|
||||||
link = A("| Sections |", href="../index.html")
|
|
||||||
#link.tail = ' |'
|
|
||||||
navbar.append(link)
|
|
||||||
if f < len(feeds)-1:
|
|
||||||
link = A(trim_title(' '+feeds[f+1].title) + ' >', href = '../feed_%d/index.html' % int(f+1))
|
|
||||||
#link.tail = ' |'
|
|
||||||
navbar.append(link)
|
|
||||||
else:
|
|
||||||
navbar_t = TABLE(width="100%", align="center", border="0",
|
|
||||||
cellspacing="3px", cellpadding="3px")
|
|
||||||
navbar_tr = TR()
|
navbar_tr = TR()
|
||||||
|
|
||||||
link = ''
|
link = ''
|
||||||
if f > 0:
|
if f > 0:
|
||||||
link = A(trim_title('<' + feeds[f-1].title),
|
link = A(EM( '< ' + trim_title(feeds[f-1].title)),
|
||||||
href = '../feed_%d/index.html' % int(f-1))
|
href = '../feed_%d/index.html' % int(f-1))
|
||||||
navbar_tr.append(TD(link, width="40%", align="right"))
|
navbar_tr.append(TD(link, width="40%", align="center"))
|
||||||
|
|
||||||
link = A("Sections", href="../index.html")
|
link = A(STRONG('Sections'), href="../index.html")
|
||||||
navbar_tr.append(TD(link,width="20%", align="center"))
|
navbar_tr.append(TD(link,width="20%",align="center"))
|
||||||
|
|
||||||
link = ''
|
link = ''
|
||||||
if f < len(feeds)-1:
|
if f < len(feeds)-1:
|
||||||
link = A(trim_title(feeds[f+1].title) + '>',
|
link = A(EM(trim_title(feeds[f+1].title) + ' >'),
|
||||||
href = '../feed_%d/index.html' % int(f+1))
|
href = '../feed_%d/index.html' % int(f+1))
|
||||||
navbar_tr.append(TD(link, width="40%", align="left"))
|
navbar_tr.append(TD(link, width="40%", align="center"))
|
||||||
|
|
||||||
navbar_t.append(navbar_tr)
|
navbar_t.append(navbar_tr)
|
||||||
navbar = navbar_t
|
navbar = navbar_t
|
||||||
@ -333,7 +317,8 @@ class TouchscreenFeedTemplate(Template):
|
|||||||
toc.append(tr)
|
toc.append(tr)
|
||||||
|
|
||||||
div.append(toc)
|
div.append(toc)
|
||||||
div.append(DIV(style="border-top:1px solid gray;border-bottom:1em solid white"))
|
#div.append(DIV(style="border-top:1px solid gray;border-bottom:1em solid white"))
|
||||||
|
div.append(BR())
|
||||||
div.append(navbar)
|
div.append(navbar)
|
||||||
self.root = HTML(head, body)
|
self.root = HTML(head, body)
|
||||||
|
|
||||||
@ -348,97 +333,25 @@ class TouchscreenNavBarTemplate(Template):
|
|||||||
if extra_css:
|
if extra_css:
|
||||||
head.append(STYLE(extra_css, type='text/css'))
|
head.append(STYLE(extra_css, type='text/css'))
|
||||||
|
|
||||||
if prefix and not prefix.endswith('/'):
|
navbar = DIV()
|
||||||
prefix += '/'
|
|
||||||
align = 'center' if center else 'left'
|
|
||||||
|
|
||||||
if False:
|
|
||||||
navbar = DIV(CLASS('calibre_navbar', 'calibre_rescale_100',
|
|
||||||
style='text-align:'+align))
|
|
||||||
|
|
||||||
if bottom and False:
|
|
||||||
navbar.append(DIV(style="border-top:1px solid gray;border-bottom:1em solid white"))
|
|
||||||
text = 'This article was downloaded by '
|
|
||||||
p = PT(text, STRONG(__appname__), A(url, href=url), style='text-align:left')
|
|
||||||
p[0].tail = ' from '
|
|
||||||
navbar.append(p)
|
|
||||||
navbar.append(BR())
|
|
||||||
navbar.append(BR())
|
|
||||||
|
|
||||||
# | Previous
|
|
||||||
if art > 0:
|
|
||||||
href = '%s../article_%d/index.html'%(prefix, art-1)
|
|
||||||
navbar.append(A('< Previous', href=href))
|
|
||||||
|
|
||||||
# | Articles | Sections |
|
|
||||||
href = '%s../index.html#article_%d'%(prefix, art)
|
|
||||||
navbar.iterchildren(reversed=True).next().tail = ' | '
|
|
||||||
navbar.append(A('Articles', href=href))
|
|
||||||
|
|
||||||
href = '%s../../index.html#feed_%d'%(prefix, feed)
|
|
||||||
navbar.iterchildren(reversed=True).next().tail = ' | '
|
|
||||||
navbar.append(A("Sections", href=href))
|
|
||||||
|
|
||||||
# | Next
|
|
||||||
next = 'feed_%d'%(feed+1) if art == number_of_articles_in_feed - 1 \
|
|
||||||
else 'article_%d'%(art+1)
|
|
||||||
up = '../..' if art == number_of_articles_in_feed - 1 else '..'
|
|
||||||
href = '%s%s/%s/index.html'%(prefix, up, next)
|
|
||||||
navbar.iterchildren(reversed=True).next().tail = ' | '
|
|
||||||
navbar.append(A('Next >', href=href))
|
|
||||||
|
|
||||||
#navbar.iterchildren(reversed=True).next().tail = ' | '
|
|
||||||
if not bottom:
|
|
||||||
navbar.append(DIV(style="border-top:1px solid gray;border-bottom:1em solid white"))
|
|
||||||
else:
|
|
||||||
'''
|
|
||||||
table.touchscreen_navbar {
|
|
||||||
-webkit-border-radius:4px;
|
|
||||||
background:#ccc;
|
|
||||||
border:#ccc 1px solid;
|
|
||||||
margin-left: 25%;
|
|
||||||
margin-right: 25%;
|
|
||||||
width: 50%;}
|
|
||||||
<table cellpadding="2px" cellspacing="2px">
|
|
||||||
<tr>
|
|
||||||
<td><a href="#link_target_2"> < </a></td>
|
|
||||||
<!--td>⬆</td-->
|
|
||||||
<td><a href="#link_target_2"> Articles </a></td>
|
|
||||||
<!--td>⬇</td-->
|
|
||||||
<td><a href="#link_target_2"> Sections </a></td>
|
|
||||||
<td><a href="#link_target_2"> > </a></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
'''
|
|
||||||
|
|
||||||
navbar = DIV(CLASS('calibre_navbar', 'calibre_rescale_120'))
|
|
||||||
|
|
||||||
if bottom:
|
if bottom:
|
||||||
navbar.append(DIV(style="border-top:1px solid gray;border-bottom:1em solid white"))
|
navbar.append(DIV(style="border-top:1px solid gray;border-bottom:1em solid white"))
|
||||||
|
|
||||||
navbar_t = TABLE(
|
navbar_t = TABLE(CLASS('article_navbar'))
|
||||||
align="center",
|
|
||||||
border="0",
|
|
||||||
cellpadding="3px",
|
|
||||||
cellspacing="3px",
|
|
||||||
width="100%"
|
|
||||||
)
|
|
||||||
|
|
||||||
navbar_tr = TR()
|
navbar_tr = TR()
|
||||||
# | Previous
|
# | Previous
|
||||||
if art > 0:
|
if art > 0:
|
||||||
href = '%s../article_%d/index.html'%(prefix, art-1)
|
href = '%s../article_%d/index.html'%(prefix, art-1)
|
||||||
navbar_tr.append(TD(A(' <Prev ', href=href), width="32%", align="right"))
|
navbar_tr.append(TD(A(EM('< Previous'), href=href), width="32%", align="center"))
|
||||||
else:
|
else:
|
||||||
navbar_tr.append(TD('', width="25%"))
|
navbar_tr.append(TD('', width="25%"))
|
||||||
|
|
||||||
# | Articles | Sections |
|
# | Articles | Sections |
|
||||||
href = '%s../index.html#article_%d'%(prefix, art)
|
href = '%s../index.html#article_%d'%(prefix, art)
|
||||||
navbar_tr.append(TD(A('Articles', href=href),width="18%", align="center"))
|
navbar_tr.append(TD(A(STRONG('Articles'), href=href),width="18%", align="center"))
|
||||||
|
|
||||||
href = '%s../../index.html#feed_%d'%(prefix, feed)
|
href = '%s../../index.html#feed_%d'%(prefix, feed)
|
||||||
navbar_tr.append(TD(A("Sections", href=href),width="18%", align="center"))
|
navbar_tr.append(TD(A(STRONG('Sections'), href=href),width="18%", align="center"))
|
||||||
|
|
||||||
# | Next
|
# | Next
|
||||||
next = 'feed_%d'%(feed+1) if art == number_of_articles_in_feed - 1 \
|
next = 'feed_%d'%(feed+1) if art == number_of_articles_in_feed - 1 \
|
||||||
@ -446,12 +359,9 @@ class TouchscreenNavBarTemplate(Template):
|
|||||||
up = '../..' if art == number_of_articles_in_feed - 1 else '..'
|
up = '../..' if art == number_of_articles_in_feed - 1 else '..'
|
||||||
href = '%s%s/%s/index.html'%(prefix, up, next)
|
href = '%s%s/%s/index.html'%(prefix, up, next)
|
||||||
|
|
||||||
navbar_tr.append(TD(A(' Next> ', href=href),width="32%", align="left"))
|
navbar_tr.append(TD(A(EM('Next >'), href=href),width="32%", align="center"))
|
||||||
navbar_t.append(navbar_tr)
|
navbar_t.append(navbar_tr)
|
||||||
navbar.append(navbar_t)
|
navbar.append(navbar_t)
|
||||||
#print "\n%s\n" % etree.tostring(navbar, pretty_print=True)
|
#print "\n%s\n" % etree.tostring(navbar, pretty_print=True)
|
||||||
|
|
||||||
if not bottom:
|
|
||||||
navbar.append(DIV(style="border-top:1px solid gray;border-bottom:1em solid white"))
|
|
||||||
|
|
||||||
self.root = HTML(head, BODY(navbar))
|
self.root = HTML(head, BODY(navbar))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user