init, homepage and puzzle page
commit
f0e3510341
@ -0,0 +1,15 @@
|
||||
venv/
|
||||
|
||||
*.pyc
|
||||
__pycache__/
|
||||
.ipynb_checkpoints
|
||||
|
||||
instance/
|
||||
|
||||
.pytest_cache/
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
dist/
|
||||
build/
|
||||
*.egg-info/
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.formatting.provider": "black"
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
include chaospuzzles/schema.sql
|
||||
graft chaospuzzles/static
|
||||
graft chaospuzzles/templates
|
||||
global-exclude *.pyc
|
@ -0,0 +1,48 @@
|
||||
import os
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class PrefixMiddleware(object):
|
||||
def __init__(self, app, prefix=""):
|
||||
self.app = app
|
||||
self.prefix = prefix
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
|
||||
if environ["PATH_INFO"].startswith(self.prefix):
|
||||
environ["PATH_INFO"] = environ["PATH_INFO"][len(self.prefix) :]
|
||||
environ["SCRIPT_NAME"] = self.prefix
|
||||
return self.app(environ, start_response)
|
||||
else:
|
||||
start_response("404", [("Content-Type", "text/plain")])
|
||||
return ["This url does not belong to the app.".encode()]
|
||||
|
||||
|
||||
def create_app(test_config=None):
|
||||
# create and configure the app
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
app.config.from_mapping(
|
||||
SECRET_KEY="dev",
|
||||
# DATABASE=os.path.join(app.instance_path, 'puzzles'),
|
||||
)
|
||||
|
||||
if test_config is None:
|
||||
# load the instance config, if it exists, when not testing
|
||||
app.config.from_pyfile("config.py", silent=True)
|
||||
else:
|
||||
# load the test config if passed in
|
||||
app.config.from_mapping(test_config)
|
||||
|
||||
# ensure the instance folder exists
|
||||
try:
|
||||
os.makedirs(app.instance_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
from . import puzzle
|
||||
|
||||
app.register_blueprint(puzzle.bp)
|
||||
|
||||
app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix="/soupboat/chaospuzzles")
|
||||
|
||||
return app
|
@ -0,0 +1,29 @@
|
||||
import os
|
||||
import json
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
bp = Blueprint("puzzle", __name__, url_prefix="/")
|
||||
|
||||
|
||||
def list_folders(path):
|
||||
"""Return all the folders in a folder"""
|
||||
names = []
|
||||
for entry in os.scandir(path):
|
||||
# add to the list only proper files
|
||||
if not entry.name.startswith(".") and entry.is_dir():
|
||||
# remove the extension from the filename
|
||||
names.append(entry.name)
|
||||
return names
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def home():
|
||||
puzzles = list_folders("chaospuzzles/puzzles")
|
||||
return render_template("home.html", puzzles=puzzles)
|
||||
|
||||
|
||||
@bp.route("/<puzzle>")
|
||||
def puzzle(puzzle=None):
|
||||
with open(f"chaospuzzles/puzzles/{puzzle}/info.json") as data:
|
||||
info = json.load(data)
|
||||
return render_template("puzzle.html", puzzle=puzzle, **info)
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "katamari",
|
||||
"rows": 10,
|
||||
"columns": 15,
|
||||
"image": "katamari.jpg",
|
||||
"clusters": []
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Chaos Puzzles Prototype</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Chaos Puzzles</h1>
|
||||
<ul>
|
||||
{%for puzzle in puzzles%}
|
||||
<li>
|
||||
<a href="{{puzzle}}">{{puzzle}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{puzzle}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{puzzle}}</h1>
|
||||
{{rows}}, {{columns}}, {{clusters}}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue