-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (63 loc) · 2.08 KB
/
app.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from flask import Flask, request, Response, jsonify, safe_join, send_file, render_template
from generator import fetch_config, fetch_raw_config, fetch_font_map, form_font_face, generate_font_map
app = Flask(__name__)
"""
ABOUT ROUTING
In Fontiles' current revision, all fonts have determined
paths for all resources.
Full Font family (all members):
$HOST/fonts/$FONT_SLUG/full.css
TTF static source:
$HOST/fonts/$FONT_SLUG/static/$MEMBER_SLUG.ttf
Font Family Config:
$HOST/fonts/$FONT_SLUG/font.json
In addition, all Fontiles instances have a /ping
route that returns a text response 'pong' and others:
App Config:
$HOST/config.json
"""
@app.route('/')
def hello():
cfg = fetch_config()
return render_template('index.html', cfg=cfg)
@app.route('/ping')
def ping():
return 'pong'
@app.route('/config.json')
def config():
return jsonify(fetch_config())
@app.route('/fonts/<font_slug>/font.json')
def font_config(font_slug):
return jsonify(fetch_font_map(font_slug))
@app.route('/fonts/<font_slug>/static/<member_slug>.ttf')
def font_static_ttf(font_slug, member_slug):
fcfg = generate_font_map(font_slug, include_raw=True)
if member_slug in fcfg['members']:
raw_ttf = fcfg['members'][member_slug]['raw_ttf']
return send_file(safe_join(fcfg['rawFontPath'], raw_ttf))
# Replace with proper 404
return jsonify("cannot find")
@app.route('/fonts/<font_slug>/LICENSE')
def font_license(font_slug):
return jsonify("not implemented.")
@app.route('/fonts/<font_slug>/full.css')
def font_full_css(font_slug):
cfg = fetch_config()
fcfg = fetch_font_map(font_slug)
member_css = []
if not fcfg:
return Response("""/**
* generated by Fontiles, served from {}
* font {} does not exist
**/
""".format(cfg["name"], font_slug), mimetype='text/css')
for member in fcfg["members"]:
member_css += [form_font_face(cfg["host"], fcfg, member)]
return Response("""/**
* generated by Fontiles, served from {}
* font: {}
* author: {}
**/
{}
""".format(cfg["name"], fcfg["name"], fcfg["author"],
"\n\n".join(member_css)), mimetype='text/css')