import jinja2


def render_template(authors, configuration):
    """
    Renders a template in `adoc`, `html`, `md`,
    `rst`, or `txt` format.

    Parameters
    ----------
    authors : list
        The authors to include in the rendered
        template.

    configuration : dict
        Configuration settings relevant to the
        rendered template (`heading`, `opening`,
        and `closing`).

    Returns
    -------
    str
        The rendered template.
    """

    loader = jinja2.PackageLoader("authors", "templates")

    environment = jinja2.Environment(
        loader=loader,
        lstrip_blocks=True,
        trim_blocks=True
    )

    source_file = "template.{}".format(configuration["kind"])
    template = environment.get_template(source_file)
    return template.render(authors=authors, **configuration)