Permalink
Browse files

[FIX] Installer was ignoring the templates. Fixes #20

[IMP] Now templates are using static file path
      which is way more generic in order to not depend only of the
      pre-installed templated (even if this feature is not ready this is
      the correct implementation).
  • Loading branch information...
nhomar committed Jul 15, 2016
1 parent 1dcbdbe commit 7fa5f76d03723535ffc10690d51ccc1c47d68ae8
Showing with 11 additions and 6 deletions.
  1. +1 −0 MANIFEST.in
  2. +10 −6 cfdilib/cfdilib.py
View
@@ -3,6 +3,7 @@ include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE
include README.rst
include cfdilib/templates/*
recursive-include tests *
recursive-exclude * __pycache__
View
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
import os
from os.path import dirname
from cStringIO import StringIO
from abc import ABCMeta, abstractmethod
from tempfile import NamedTemporaryFile
from lxml import etree
from jinja2 import Environment, PackageLoader
from jinja2 import Environment, FileSystemLoader
from .tools import tools
@@ -80,6 +81,10 @@ def __init__(self, dict_document, debug_mode=False, cache=1000):
self.set_xml()
self.set_xslt_fname()
self.document_orginal = self.set_original()
self.template_fname = ''
self.schema_fname = self.template_fname.replace('.xml', '.xsd')
self.xslt_fname = self.template_fname.replace('.xml', '.xslt')
self.templates = os.path.join(dirname(__file__), 'templates')
__metaclass__ = ABCMeta
@@ -111,8 +116,7 @@ def guess_autoescape(self, template_name):
@abstractmethod
def set_schema(self, schema_fname):
testxml = os.path.join(os.path.dirname(__file__),
'templates', schema_fname)
testxml = os.path.join(self.templates, schema_fname)
with open(testxml, 'r') as element:
schema = element.read()
return schema
@@ -122,8 +126,7 @@ def set_xslt(self):
if self.xslt_fname and tools.is_url(self.xslt_fname):
xslt_path = tools.cache_it(self.xslt_fname)
elif self.xslt_fname:
xslt_path = os.path.join(os.path.dirname(__file__),
'templates', self.xslt_fname)
xslt_path = os.path.join(self.templates, self.xslt_fname)
with open(xslt_path, 'r') as element:
xslt = element.read()
self.xslt_document = xslt
@@ -133,7 +136,8 @@ def set_xslt(self):
@abstractmethod
def set_template(self, template_fname):
env = Environment(loader=PackageLoader('cfdilib', 'templates'),
self.templates = os.path.join(dirname(__file__), 'templates')
env = Environment(loader=FileSystemLoader(self.templates),
extensions=['jinja2.ext.autoescape'],
autoescape=self.guess_autoescape)
return env.get_template(template_fname)

0 comments on commit 7fa5f76

Please sign in to comment.