예제 #1
0
def writer_action(io, name, Strategy, options, args):
    """
    Called by `commandline()` as a result of sub-command
    dispatching. At this point the name of the writer is in `name` and
    the strategy that should be send to the `rendering` module is in
    the parameter `Strategy`.

    The return value of this function will be the command line's
    return value.
    """
    dest = None
    if options.outfile:
        dest = shellopen(options.outfile, 'w')
        if len(args) == 1:
            io.source = shellopen(args[0], 'r')
    else:
        if len(args) == 1:
            # Only infile
            io.source = shellopen(args[0], 'r')
        elif len(args) > 1:
            io.source = shellopen(args[0], 'r')
            dest = BufferedFile(os.path.expanduser(args[1]))

    if dest:
        io.destination = dest

    sys.path.append(os.getcwd())
    if options.config:
        confmod = _import(options.config)
    else:
        confmod = _import('flexiconf', False)

    tpath = getattr(options, 'template', False)
    if tpath:
        template = shellopen(tpath, 'r').read()
    else:
        template = defaults.templates[name]

    strategy = strategies.from_name(name)

    if options.dump_parts:
        rendering.dump_parts(strategy,
                             io,
                             confmod,
                             options,
                             template)
    else:
        rendering.render(strategy,
                         io,
                         confmod,
                         options,
                         template)

    # XXX Way to simple way to treat return codes
    return 0
예제 #2
0
def test_dump_parts():
    io = support.CapturingIo()
    rendering.dump_parts(
        strategies.HtmlStrategy(),
        io,
        imp.new_module("flexiconf"),
        util.Duck(lang="en", dump_parts=True),
        defaults.templates["html"],
    )
    assert io.msglines[0].startswith("Parts created by the docutils writer 'html4css1'")
    assert io.msglines[9].startswith("body")
예제 #3
0
def test_dump_parts_utf8():
    out = LineCapture()
    io = support.CapturingIo()
    rendering.dump_parts(
        strategies.LatexStrategy(),
        io,
        imp.new_module("flexiconf"),
        util.Duck(lang="sv", dump_parts=True, resources=False),
        defaults.templates["latex"],
    )
    assert io.msglines[0].startswith("Parts created by the docutils writer 'latex2e'")
    assert io.msglines[9].startswith("abstract")