#!/usr/bin/env python # ***************************************************************************** # Copyright (C) 2023 Thomas Touhey # This file is part of the textoutpc project, which is MIT-licensed. # ***************************************************************************** """Demonstration website for textoutpc.""" from __future__ import annotations from pathlib import Path from flask import Flask, render_template, request from flask_assets import ( Bundle as AssetsBundle, Environment as AssetsEnvironment, ) from .utils import to_html __all__ = ["app"] STATIC_PATH = Path(__file__).parent DEFAULT_TEXT = open(STATIC_PATH / "content" / "default.bbcode").read().rstrip() DEFAULT_TRANSLATED_TEXT = to_html(DEFAULT_TEXT) app = Flask( __name__, template_folder=STATIC_PATH / "templates", static_folder=STATIC_PATH / "static", ) """WSGI application for the textoutpc demonstration.""" assets = AssetsEnvironment(app) assets.register( "js", AssetsBundle("js/elements.js"), filters="jsmin", output="index.js", ) assets.register( "css", AssetsBundle("css/elements.scss", "css/page.scss"), filters=("scss", "cssmin"), output="index.css", ) @app.route("/", methods=("GET", "POST")) def index() -> str: """Process input for demonstration purposes.""" if request.method == "POST" and "text" in request.form: text = request.form["text"].strip() result = to_html(text) else: text = DEFAULT_TEXT result = DEFAULT_TRANSLATED_TEXT return render_template("page.html", text=text, result=result)