mirror of https://github.com/dirtbags/moth.git
Make category-wide puzzles work
This commit is contained in:
parent
17fe6cc779
commit
5c5cb36530
|
@ -29,15 +29,16 @@ def page(title, body):
|
|||
return """<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{}</title>
|
||||
<title>{title}</title>
|
||||
<link rel="stylesheet" href="/files/src/www/res/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>{title}</h1>
|
||||
<div id="preview" class="terminal">
|
||||
{}
|
||||
{body}
|
||||
</div>
|
||||
</body>
|
||||
</html>""".format(title, body)
|
||||
</html>""".format(title=title, body=body)
|
||||
|
||||
|
||||
def mdpage(body):
|
||||
|
@ -132,7 +133,7 @@ you are a fool.
|
|||
if not cat:
|
||||
title = "Puzzle Categories"
|
||||
body.write("<ul>")
|
||||
for i in glob.glob(os.path.join("puzzles", "*", "")):
|
||||
for i in sorted(glob.glob(os.path.join("puzzles", "*", ""))):
|
||||
body.write('<li><a href="{}">{}</a></li>'.format(i, i))
|
||||
body.write("</ul>")
|
||||
elif not puzzle:
|
||||
|
@ -155,6 +156,7 @@ you are a fool.
|
|||
body.write("</ul>")
|
||||
body.write("<h2>Answers</h2>")
|
||||
body.write("<ul>")
|
||||
assert puzzle.answers, 'No answers defined'
|
||||
for a in puzzle.answers:
|
||||
body.write("<li><code>{}</code></li>".format(html.escape(a)))
|
||||
body.write("</ul>")
|
||||
|
|
|
@ -177,20 +177,12 @@ class Category:
|
|||
self.pointvals = []
|
||||
self.catmod = None
|
||||
|
||||
try:
|
||||
catmod = SourceFileLoader(
|
||||
if os.path.exists(os.path.join(path, 'category.py')):
|
||||
self.catmod = importlib.machinery.SourceFileLoader(
|
||||
'catmod',
|
||||
os.path.join(path, 'category.py')).load_module()
|
||||
assert all([
|
||||
hasattr(catmod, 'make'),
|
||||
hasattr(catmod, 'points'),
|
||||
type(catmod.points) is list,
|
||||
])
|
||||
self.catmod = catmod
|
||||
self.pointvals.extend(catmod.points)
|
||||
except:
|
||||
pass
|
||||
|
||||
self.pointvals = self.catmod.points[:]
|
||||
else:
|
||||
for fpath in glob.glob(os.path.join(path, "[0-9]*")):
|
||||
pn = os.path.basename(fpath)
|
||||
points = int(pn)
|
||||
|
@ -202,7 +194,8 @@ class Category:
|
|||
puzzle = Puzzle(self.seed, points)
|
||||
path = os.path.join(self.path, str(points))
|
||||
if self.catmod:
|
||||
self.catmod.make(p, points)
|
||||
self.catmod.make(points, puzzle)
|
||||
else:
|
||||
puzzle.read_directory(path)
|
||||
return puzzle
|
||||
|
||||
|
|
Loading…
Reference in New Issue