Skip to content

Commit

Permalink
Merge pull request #809 from Boldie/epub
Browse files Browse the repository at this point in the history
Epub
  • Loading branch information
thinkle committed Jan 2, 2016
2 parents af1e0f9 + 76b8214 commit e520d7a
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 6 deletions.
15 changes: 15 additions & 0 deletions data/style/epubdefault.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
div.recipe, div.index { font-style: Times, Serif; font-size: 12pt; margin-left: 7%; margin-right: 10%; padding: 1em; margin-top: 1em;}
div.recipe img {float: right; padding: 1em}
body {}
span.label { font-weight: bold;min-width: 10em; display: inline-block;}
p.title { font-size: 120%; text-align: center}
p.title span.label {display: none}
div.header p {margin-top: 0; margin-bottom: 0.2em}
div.ing { padding: 1em; border: solid 1px; background-color: #eef}
ul.ing { padding-left: 0.6em; }
li.ing { list-style: none; border-top: 0.3em }
div.ingamount{ display:inline-block; min-width:3em;}
div.ingunit{ display:inline-block; min-width:3em;}
img{ max-width: 90%; display: block; margin-left: auto; margin-right: auto; }
div.header{margin-top: 1em; margin-bottom: 1em;}
div.ing h2{margin-top: 0}
26 changes: 20 additions & 6 deletions gourmet/exporters/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class ExporterMultirec (SuspendableThread, Pluggable):

name = 'Exporter'

def __init__ (self, rd, recipes, out, one_file=True,
def __init__ (self, rd, recipes, out, one_file=True, open_files = True,
ext='txt',
conv=None,
imgcount=1,
Expand All @@ -474,7 +474,16 @@ def __init__ (self, rd, recipes, out, one_file=True,
"""Output all recipes in recipes into a document or multiple
documents. if one_file, then everything is in one
file. Otherwise, we treat 'out' as a directory and put
individual recipe files within it."""
individual recipe files within it.
@param one_file If True works in one_file mode. For this the class will
create the file which is accessible by self.ofi
If this is set to False a directory will be created and the
name of the directory will be passed via self.outdir and self.ofi
@param open_files If this parameter is True the files will be created
otherwise to create the file is up to the user.
"""
self.timer=TimeAction('exporterMultirec.__init__()')
self.rd = rd
self.recipes = recipes
Expand All @@ -490,6 +499,7 @@ def __init__ (self, rd, recipes, out, one_file=True,
convert.FRACTIONS_ASCII)
self.DEFAULT_ENCODING = self.exporter.DEFAULT_ENCODING
self.one_file = one_file
self.open_files = open_files

def _grab_attr_ (self, obj, attr):
if attr=='category':
Expand Down Expand Up @@ -540,7 +550,11 @@ def do_run (self):
self.outdir=self.unique_name(self.outdir)
os.makedirs(self.outdir)
else: os.makedirs(self.outdir)
if self.one_file and type(self.out)==str:

oneFileOpenByMyself = self.one_file and type(self.out)==str and self.open_files
multiFileOpenByMyself = not self.one_file and self.open_files

if oneFileOpenByMyself:
self.ofi=open(self.out,'wb')
else: self.ofi = self.out
self.write_header()
Expand All @@ -553,7 +567,7 @@ def do_run (self):
msg = _("Exported %(number)s of %(total)s recipes")%{'number':self.rcount,'total':self.rlen}
self.emit('progress',float(self.rcount)/float(self.rlen), msg)
fn=None
if not self.one_file:
if multiFileOpenByMyself:
fn=self.generate_filename(r,self.ext,add_id=True)
self.ofi=open(fn,'wb')
if self.padding and not first:
Expand All @@ -562,12 +576,12 @@ def do_run (self):
self.connect_subthread(e)
e.do_run()
self.recipe_hook(r,fn,e)
if not self.one_file:
if multiFileOpenByMyself:
self.ofi.close()
self.rcount += 1
first = False
self.write_footer()
if self.one_file:
if oneFileOpenByMyself:
self.ofi.close()
self.timer.end()
self.emit('progress',1,_("Export complete."))
Expand Down
8 changes: 8 additions & 0 deletions gourmet/plugins/import_export/epub.gourmet-plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Gourmet Plugin]
Module=epub_plugin
Version=1.0
API_Version=1.0
_Name=EPub Export
_Comment=Create an epub book from recipes.
_Category=Importer/Exporter
Authors=Sven Steckmann <[email protected]>
3 changes: 3 additions & 0 deletions gourmet/plugins/import_export/epub_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import epub_exporter_plugin

plugins = [epub_exporter_plugin.EpubExporterPlugin]
Loading

0 comments on commit e520d7a

Please sign in to comment.