Move logic for removing inline navbars out of the BasicNewsRecipe class

This commit is contained in:
Kovid Goyal 2010-02-23 10:12:10 -07:00
parent 78c4467960
commit 1a4caa3801
3 changed files with 15 additions and 12 deletions

View File

@ -101,5 +101,10 @@ class RecipeInput(InputFormatPlugin):
return os.path.abspath(f)
def postprocess_book(self, oeb, opts, log):
if opts.no_inline_navbars:
from calibre.ebooks.oeb.base import XPath
for item in oeb.spine:
for div in XPath('//h:div[contains(@class, "calibre_navbar")]')(item.data):
div.getparent().remove(div)
self.recipe_object.postprocess_book(oeb, opts, log)

View File

@ -266,7 +266,7 @@ class BasicNewsRecipe(Recipe):
font-weight: bold;
}
.navbar {
.calibre_navbar {
font-family:monospace;
}
'''
@ -525,7 +525,6 @@ class BasicNewsRecipe(Recipe):
self.username = options.username
self.password = options.password
self.lrf = options.lrf
self.include_navbars = not options.no_inline_navbars
self.output_dir = os.path.abspath(self.output_dir)
if options.test:
@ -597,7 +596,7 @@ class BasicNewsRecipe(Recipe):
if first_fetch and job_info:
url, f, a, feed_len = job_info
body = soup.find('body')
if body is not None and self.include_navbars:
if body is not None:
templ = self.navbar.generate(False, f, a, feed_len,
not self.has_single_feed,
url, __appname__,
@ -1149,13 +1148,12 @@ class BasicNewsRecipe(Recipe):
body = soup.find('body')
if body is not None:
prefix = '/'.join('..'for i in range(2*len(re.findall(r'link\d+', last))))
if self.include_navbars:
templ = self.navbar.generate(True, num, j, len(f),
not self.has_single_feed,
a.orig_url, __appname__, prefix=prefix,
center=self.center_navbar)
elem = BeautifulSoup(templ.render(doctype='xhtml').decode('utf-8')).find('div')
body.insert(len(body.contents), elem)
templ = self.navbar.generate(True, num, j, len(f),
not self.has_single_feed,
a.orig_url, __appname__, prefix=prefix,
center=self.center_navbar)
elem = BeautifulSoup(templ.render(doctype='xhtml').decode('utf-8')).find('div')
body.insert(len(body.contents), elem)
with open(last, 'wb') as fi:
fi.write(unicode(soup).encode('utf-8'))

View File

@ -38,7 +38,7 @@ class NavBarTemplate(Template):
</style>
</head>
<body>
<div class="navbar calibre_rescale_70" style="text-align:${'center' if center else 'left'};">
<div class="calibre_navbar calibre_rescale_70" style="text-align:${'center' if center else 'left'};">
<hr py:if="bottom" />
<p py:if="bottom" style="text-align:left">
This article was downloaded by <b>${__appname__}</b> from <a href="${url}">${url}</a>
@ -167,7 +167,7 @@ class FeedTemplate(Template):
</li>
</py:for>
</ul>
<div class="navbar calibre_rescale_70">
<div class="calibre_navbar calibre_rescale_70">
| <a href="../index.html">Up one level</a> |
</div>
</div>