예제 #1
0
파일: compile.py 프로젝트: guoguo12/templar
def main(args, configs):
    if args.source:
        if not file_exists(args.source):
            log.warn('File ' + args.source + ' does not exist.')
            exit(1)
        elif not os.path.isfile(args.source):
            log.warn(args.source + ' is not a valid file')
            exit(1)
        result = link.link(args.source)
        if args.markdown:
            markdown_obj = Markdown(result)
            for k, v in markdown_obj.variables.items():
                configs['VARIABLES'][k] = v
            result = markdown_obj.text
        result = link.substitutions(result,
                                    configs.get('SUBSTITUTIONS', []),
                                    args)
        result, cache = link.retrieve_blocks(result)
        if 'TOC_BUILDER' in configs:
            configs['VARIABLES']['table-of-contents'] = link.scrape_headers(result, configs['TOC_BUILDER'])
            for import_stmt in (
                    'from datetime import datetime',
                    ):
                exec(import_stmt, configs)
        for k, v in cache.items():
            configs['VARIABLES'][k] = v

    result = compile(args.template, configs)
    if not args.destination:
        log.log(result)
        return
    file_write(args.destination, result)
    log.info('Result can be found at ' + args.destination)
예제 #2
0
def main(args, configs):
    if args.source:
        if not file_exists(args.source):
            log.warn('File ' + args.source + ' does not exist.')
            exit(1)
        elif not os.path.isfile(args.source):
            log.warn(args.source + ' is not a valid file')
            exit(1)
        result = link.link(args.source)
        if args.markdown:
            markdown_obj = Markdown(result)
            for k, v in markdown_obj.variables.items():
                configs['VARIABLES'][k] = v
            result = markdown_obj.text
        result = link.substitutions(result, configs.get('SUBSTITUTIONS', []),
                                    args)
        result, cache = link.retrieve_blocks(result)
        if 'TOC_BUILDER' in configs:
            configs['VARIABLES']['table-of-contents'] = link.scrape_headers(
                result, configs['TOC_BUILDER'])
            for import_stmt in ('from datetime import datetime', ):
                exec(import_stmt, configs)
        for k, v in cache.items():
            configs['VARIABLES'][k] = v

    result = compile(args.template, configs)
    if not args.destination:
        log.log(result)
        return
    file_write(args.destination, result)
    log.info('Result can be found at ' + args.destination)
예제 #3
0
 def assertHeaders(self, text, regex, translate, build, expect):
     toc_builder = make_mock_toc_builder(regex, translate, build)
     expect = self.dedent(expect)
     self.assertEqual(expect,
                      link.scrape_headers(text, toc_builder))
예제 #4
0
 def assertHeaders(self, text, regex, translate, build, expect):
     toc_builder = make_mock_toc_builder(regex, translate, build)
     expect = self.dedent(expect)
     self.assertEqual(expect, link.scrape_headers(text, toc_builder))