Example #1
0
def _jinja24doc(name):
    ctx = Context((get_pathfor('templates'), EXAMPLES))
    data = ctx.generate('%s' % name)
    if not isinstance(data, str):
        data = data.encode('utf-8')
    with open('%s/out/%s' % (EXAMPLES, name), 'w') as f:
        f.write(data)
Example #2
0
def _jinja24doc(name):
    ctx = Context((get_pathfor('templates'), EXAMPLES))
    data = ctx.generate('%s' % name)
    if not isinstance(data, str):
        data = data.encode('utf-8')
    with open('%s/out/%s' % (EXAMPLES, name), 'w') as f:
        f.write(data)
Example #3
0
 def _jinja24doc(tname, oname):
     ctx = Context(('templates/jinja24doc', 'doc'))
     log.info('jinja24doc processing %s ...' % oname)
     data = ctx.generate(tname)
     if not isinstance(data, str):
         data = data.encode('utf-8')
     with open(oname, 'w') as f:
         f.write(data.replace('http://poorhttp.zeropage.cz/', ''))
Example #4
0
def jinja_cmdline(description=''):
    """Function called by jinja24doc command tool."""
    parser = build_parser(description)
    args = parser.parse_args()
    try:
        ctx = Context(args.path, args.encoding)
        python_path.insert(0, getcwd())

        source = args.source
        # TODO: styles
        verbose(args, parser)

        kwargs = {
            'link': args.link,
            'top': args.top,
            'system_message': args.system_message,
            'encoding': args.encoding
        }
        if args.var:    # could be None
            for kwarg in args.var:
                key, val = kwarg.split('=', 1)
                kwargs[key] = val

        output = ctx.generate(source, **kwargs)

        if args.output:
            with open(args.output, 'w+', encoding=args.encoding) as o:
                o.write(output)
        else:
            if not isinstance(output, str):
                output = output.encode('utf-8')
            print(output)
    except SystemExit as e:
        if args.traceback:
            stderr.write("%s\n" % args)
            stderr.write(format_exc())
        parser.error(e)
    except BaseException as e:
        if args.traceback:
            stderr.write("%s\n" % args)
            stderr.write(format_exc())
        parser.error('Error while proccessing %s' % e)
Example #5
0
def jinja_cmdline(description=''):
    """Function called by jinja24doc command tool."""
    parser = build_parser(description)
    args = parser.parse_args()
    try:
        ctx = Context(args.path, args.encoding)
        python_path.insert(0, os.getcwd())

        source = args.source
        # TODO: styles
        verbose(args, parser)

        kwargs = {
            'link': args.link,
            'top': args.top,
            'system_message': args.system_message,
            'encoding': args.encoding
        }

        output = ctx.generate(source, **kwargs)

        if args.output:
            with open(args.output, 'w+', encoding=args.encoding) as o:
                o.write(output)
        else:
            if not isinstance(output, str):
                output = output.encode('utf-8')
            print(output)
    except SystemExit as e:
        if args.traceback:
            stderr.write("%s\n" % args)
            stderr.write(format_exc())
        parser.error(e.message)
    except BaseException as e:
        if args.traceback:
            stderr.write("%s\n" % args)
            stderr.write(format_exc())
        parser.error('Error while proccessing %s' % e)
Example #6
0
def auto_cmdline(description='', formater='rst', file_types=['.txt']):
    """Function called by rst24doc and wiki24doc command tools."""
    parser = build_parser(description)
    args = parser.parse_args()
    try:
        ctx = Context(args.path, args.encoding)

        source = args.source
        verbose(args, parser)

        kwargs = {
            'link': args.link,
            'top': args.top,
            'system_message': args.system_message,
            'encoding': args.encoding,
            'formater': getattr(ctx, formater)
        }
        if args.var:    # could be None
            for kwarg in args.var:
                key, val = kwarg.split('=', 1)
                kwargs[key] = val

        if args.embed_stylesheet:
            kwargs['embed_stylesheet'] = embed_stylesheet(args)
        else:
            kwargs['stylesheets'] = args.stylesheet

        output = process(ctx, source, file_types, **kwargs)

        if args.output:
            with open(args.output, 'w+', encoding=args.encoding) as o:
                o.write(output)
        else:
            if not isinstance(output, str):
                output = output.encode('utf-8')
            print(output)
    except SystemExit as e:
        if args.traceback:
            stderr.write("%s\n" % args)
            stderr.write(format_exc())
        parser.error(e)
    except BaseException as e:
        if args.traceback:
            stderr.write("%s\n" % args)
            stderr.write(format_exc())
        parser.error('Error while proccessing %s' % e)