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*
+
+Installation
+------------
+
+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]_.
+
+
+Usage
+-----
+
+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`_.
+
 
 Why!
 ----
 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`: https://xmlgraphics.apache.org/fop/
 .. _XSL-FO: https://en.wikipedia.org/wiki/XSL_Formatting_Objects
+.. _zip: http://apache.webxcreen.org/xmlgraphics/fop/binaries/fop-1.1-bin.zip
+.. _tar: http://apache.webxcreen.org/xmlgraphics/fop/binaries/fop-1.1-bin.tar.gz
+.. _`XML Bible`:  http://www.ibiblio.org/xml/books/bible3/chapters/ch16.html

examples/helloworld.fo.mako

-<%inherit file="single-page-base.fo.mako" />
-<block>Hello world!</block>

examples/helloworld.py

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

examples/helloworld/helloworld.fo.mako

+<%inherit file="single-page-base.fo.mako" />
+<block>Hello ${name}!</block>

examples/helloworld/helloworld.py

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

pypfop/makotemplates.py

 
 
 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 ProjectModifiedEvent.java.
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.