1. Wojtek Walczak
  2. sphinx-rst2pdf-builder

Commits

ral...@hp  committed 336f527

support pdf_documents similar to latex_documents

  • Participants
  • Parent commits 6ee168e
  • Branches default

Comments (0)

Files changed (1)

File sphinx/builders/pdf.py

View file
 from sphinx.builders import Builder
 from sphinx.writers.pdf import PDFWriter
 from sphinx.util.console import darkgreen
+from sphinx.util import SEP
 import rst2pdf.log
 import logging
 from pprint import pprint
 
     def init(self):
         self.docnames = []
-        self.document_data = self.config.master_doc
+        self.document_data = []
 
     def write(self, *ignored):
+        
+        self.init_document_data()
+        
         if self.config.pdf_verbosity > 1:
             rst2pdf.log.log.setLevel(logging.DEBUG)
         elif self.config.pdf_verbosity > 0:
             rst2pdf.log.log.setLevel(logging.INFO)
-
-        docwriter = PDFWriter(self,
+    
+        for entry in self.document_data:
+            docname, targetname, title, author = entry[:4]
+            print docname, targetname, title, author
+            docwriter = PDFWriter(self,
                             stylesheets=self.config.pdf_stylesheets,
                             language=self.config.pdf_language,
                             breaklevel=self.config.pdf_break_level,
                             compressed=self.config.pdf_compressed,
                             inline_footnotes=self.config.pdf_inline_footnotes,
                             )
-        tgt_file = path.join(self.outdir, self.config.master_doc + self.out_suffix)
-        destination = FileOutput(destination_path=tgt_file, encoding='utf-8')
-        doctree = self.assemble_doctree(self.document_data)
-        docwriter.write(doctree, destination)
+            tgt_file = path.join(self.outdir, targetname + self.out_suffix)
+            destination = FileOutput(destination_path=tgt_file, encoding='utf-8')
+            doctree = self.assemble_doctree(docname)
+            docwriter.write(doctree, destination)
+        
+    def init_document_data(self):
+        preliminary_document_data = map(list, self.config.pdf_documents)
+        if not preliminary_document_data:
+            self.warn('no "pdf_documents" config value found; no documents '
+                      'will be written')
+            return
+        # assign subdirs to titles
+        self.titles = []
+        for entry in preliminary_document_data:
+            docname = entry[0]
+            if docname not in self.env.all_docs:
+                self.warn('"pdf_documents" config value references unknown '
+                          'document %s' % docname)
+                continue
+            self.document_data.append(entry)
+            if docname.endswith(SEP+'index'):
+                docname = docname[:-5]
+            self.titles.append((docname, entry[2]))
 
     def assemble_doctree(self, indexfile):
+        print indexfile
         self.docnames = set([indexfile])
         self.info(darkgreen(indexfile) + " ", nonl=1)
         def process_tree(docname, tree):
             tree.append(index_nodes)
 
         # Generate Contents topic manually
-        
+      
         output='.. raw:: pdf\n\n    PageBreak \n\n'
         pb=docutils.core.publish_doctree(output)[0]
         contents=nodes.topic(classes=['contents'])
         pending=nodes.topic()
         contents.append(pending)
         pending.details={}
-        tree.insert(-2,pb)
-        tree.insert(-2,contents)
+        tree.insert(0,pb)
+        tree.insert(0,contents)
         contTrans=PDFContents(tree)
         contTrans.startnode=pending
         contTrans.apply()
 
-
+        # Generate cover page
+        
         for pendingnode in tree.traverse(addnodes.pending_xref):
             # This needs work, need to keep track of all targets
             # so I don't replace and create hanging refs, which