aboutsummaryrefslogtreecommitdiff
path: root/app/__init__.py
blob: 7beb17be749438ccec2e6b73b233372bcfbaa5f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
#******************************************************************************
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************
""" textoutpc demonstration application definition. """

import os.path as _path

from flask import Flask as _Flask
from flask_assets import (Environment as _AssetsEnvironment,
	Bundle as _AssetsBundle)
from textoutpc import tohtml as _translate

from ._main import main as _main

__all__ = ["app"]

# Make the app and register blueprints.

_gd = lambda *x: _path.relpath(_path.join(_path.dirname(__file__), *x))
app = _Flask('textout',
	template_folder = _gd('templates'),
	static_folder = _gd('static'), static_url_path = '/static')
app.config['URL'] = 'https://textout.touhey.org'

# Register the blueprints.

app.register_blueprint(_main)

# Load the default texts.

with app.open_resource(_path.join('app', 'content', 'default.bbcode'),
	'r') as f:
	text = f.read().rstrip()
	app.config['TEXT_DEFAULT'] = text
	app.config['TEXT_DEFAULT_TRANSLATED'] = _translate(text) if text else None

with app.open_resource(_path.join('app', 'content', 'guide.bbcode'), 'r') as f:
	app.config['TEXT_GUIDE'] = _translate(f.read())

# Add the assets.

_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'))

# End of file.