def compile_template(self, out_path, data): compiled_html = SimpleTemplate(TEMPLATE_TEXT).render( html=data['html'], title=data['title'], credit=data['credit'], soln=data['soln'], exampleId=data['exampleId']) self.make_path(out_path) compiled_html = compiled_html.encode('utf8') open(out_path, 'wb').write(compiled_html)
def make_home_page(self, paths): example_list = '' for path in paths: example_list += '<li><a href="{}">{}</a></li>\n'.format( path + '/index.html', path) template_text = open('home_template.html').read() compiled_html = SimpleTemplate(template_text).render( exampleList=example_list) compiled_html = compiled_html.encode('utf8') open(os.path.join('en', 'index.html'), 'wb').write(compiled_html)
def compileTemplate(self, relativePath): print(relativePath) pathToRoot = self.getPathToRoot(relativePath) filePath = os.path.join(TEMPLATE_DIR, relativePath) templateText = open(filePath).read() compiledHtml = SimpleTemplate(templateText).render(pathToRoot = pathToRoot) self.makePath(relativePath) fileName, fileExtension = os.path.splitext(relativePath) compiledHtml = compiledHtml.encode('utf8') open(relativePath, 'wb').write(compiledHtml)
def compileTemplate(relativePath, sectionData): pathToRoot = getPathToRootFrom(relativePath) filePath = os.path.join(TEMPLATE_DIR, relativePath) templateText = open(filePath).read() compiledHtml = SimpleTemplate(templateText).render(pathToRoot=pathToRoot, sections=sectionData) compiledHtml = compiledHtml.encode('utf8') relativePath = os.path.join(OUTPUT_DIR, relativePath) makePath(relativePath) open(relativePath, 'wb').write(compiledHtml) return relativePath
def compileTemplate(self, page, fromPath, toPath, progLang, lang): # print(toPath) # note: all pages are in language/page pathToRoot = '../../' templateText = open(fromPath).read() data = { 'pathToRoot': pathToRoot, 'lang': lang, 'progLang': progLang, 'langName': self.getLangName(lang), 'page': page } try: compiledHtml = SimpleTemplate(templateText).render(data) self.makePath(toPath) fileName, fileExtension = os.path.splitext(fromPath) compiledHtml = compiledHtml.encode('utf8') open(toPath, 'wb').write(compiledHtml) except Exception as err: print('failed to compile: ', fromPath) print('error: {}'.format(err))