Joel  Rivera  avatar Joel Rivera committed a1cb181

Improve makotemplate.Template skeleton integration.
Improve README and example.

Comments (0)

Files changed (6)

 this packages *requires Java*  ``>_<'``, but fear not my python comrade it is
 almost transparent to the python application.
+In general the internal workflow is::
+    template ->  mako -> apply css ->  xsl-fo ->  fop -> *Document*
+1. Install pypfop::
+    pip install pypfop
+2. Install `Apache FOP`_.:
+   #. Download the binary package of fop1.1 either the  zip_. or tar_. package.
+   #. Decompress in wherever place you like and set environment variable ``FOP_CMD``
+      to the ``bin/fop`` of the decompressed folder. [1]_.
+About XSL-FO syntax
+As you should notice already it is required to now how to format xsl-fo documents
+which in most part are very similar to the HTML counterparts, the best reference
+that I could find online is in the `XML Bible`_.
 I was looking to have some kind of *template* to the very rigid format of
 the average invoice and billing order, so pypfop came to relieve that pain.
+.. [1] Actually you can set the command at another level, check the examples. 
 .. _`Apache FOP`:
 .. _XSL-FO:
+.. _zip:
+.. _tar:
+.. _`XML Bible`:


-<%inherit file="" />
-<block>Hello world!</block>


-import pypfop
-from pypfop import makotemplates
-import pypfop.makotemplates
-tfactory = makotemplates.TemplateFactory(('.', '../pypfop/skeletons/mako/'))
-doc = pypfop.Document(tfactory(''),
-                      fop_cmd='/usr/bin/fop', debug=True)


+<%inherit file="" />
+<block>Hello ${name}!</block>


+from pypfop import Document
+from pypfop.makotemplates import TemplateFactory
+tfactory = TemplateFactory()
+doc = Document(tfactory(''))
+fpath = doc.generate({"name": "Stranger"})
+print("The document has been generated at %s" % fpath)


 class TemplateFactory(object):
-    def __init__(self, lookup_dirs=pypfop.skeldir_for('mako')):
+    __skel_dir__ = pypfop.skeldir_for('mako')
+    def __init__(self, lookup_dirs=None, use_skels=True):
+        lookup_dirs = self._get_lookup_dirs(lookup_dirs, use_skels)
         self.lookup = get_lookup(lookup_dirs)
     def __call__(self, template):
         return Template(template, self.lookup)
+    def _get_lookup_dirs(self, lookup_dirs, use_skels):
+        if lookup_dirs is None:
+            lookup_dirs = ['.',]
+        else:
+            lookup_dirs =  list(lookup_dirs)
+        if use_skels:
+            lookup_dirs.append(self.__skel_dir__)
+        return lookup_dirs
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.