def html_generate(env, options, input_js, input_html):
    """
    Generate html based on the templates and build mode.
    """

    # - dev, canvas_dev:
    #     render top-level js files into a temporary file
    #     collect the .js files that need to be included
    #     setup includes, startup code and the js render result into variables
    #     render html template
    #
    # - release, canvas:
    #     need to know name of output js file
    #     setup startup code to point to .tzjs or .js file
    #     render html template

    # Load templates (using default html template if not specified)

    Profiler.start('load_templates')

    template_html = load_html_template(env, input_html)
    if template_html is None:
        LOG.error("failed to load file %s from template dirs", input_html[0])
        exit(1)

    # Get context

    if len(input_js) > 0:
        title = input_js[0]
    elif options.codefile:
        title = options.codefile
    elif len(input_html) > 0:
        title = input_html[0]
    else:
        title = "Unknown"
    title = splitext(basename(title))[0]

    context = context_from_options(options, title)

    Profiler.stop('load_templates')
    Profiler.start('code_gen')

    # In development modes, render the JS code that needs embedding

    rendered_js = ""
    inc_js = []

    if options.mode in [ 'plugin-debug', 'canvas-debug' ]:
        inject_js = inject_js_from_options(options)

        Profiler.start('load_js_templates')
        templates_js = env_load_templates(env, input_js)
        Profiler.stop('load_js_templates')

        (rendered_js, inc_js) = render_js(context, options, templates_js,
                                          inject_js)

    # Add the HTML and JS code into the tz_* variables

    default_add_code(options, context, rendered_js, inc_js)

    Profiler.stop('code_gen')
    Profiler.start('html_render')

    # Render the template and write it out

    try:
        res = template_html.render(context)
    except Exception, e:
        raise ToolsException("Error in '%s': %s %s" \
                                 % (input_html, e.__class__.__name__, str(e)))

    try:
        with open(options.output, "wb") as f:
            f.write(res.encode('utf-8'))
    except __HOLE__:
        raise ToolsException("failed to create file: %s" % options.output)

    Profiler.stop('html_render')

    return 0

############################################################
dataset/ETHPy150Open turbulenz/turbulenz_tools/turbulenz_tools/tools/makehtml.py/html_generate