Add basic gallery functionality
parent
8f3c6af6db
commit
ff3678ab99
|
@ -1,2 +1,4 @@
|
||||||
graft static
|
graft static
|
||||||
prune static/screenshots
|
prune static/screenshots
|
||||||
|
|
||||||
|
recursive-include src *.j2
|
||||||
|
|
|
@ -4,10 +4,15 @@ import os
|
||||||
import milla.util
|
import milla.util
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CONFIG = {
|
||||||
|
'gallery.screenshot_dir': 'screenshots',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Application(milla.Application):
|
class Application(milla.Application):
|
||||||
|
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
self.config = {}
|
self.config = DEFAULT_CONFIG.copy()
|
||||||
if config and os.access(config, os.R_OK):
|
if config and os.access(config, os.R_OK):
|
||||||
self.config.update(milla.util.read_config(config))
|
self.config.update(milla.util.read_config(config))
|
||||||
self.config['milla.favicon'] = False
|
self.config['milla.favicon'] = False
|
||||||
|
|
|
@ -1,8 +1,48 @@
|
||||||
|
import jinja2
|
||||||
import milla.controllers
|
import milla.controllers
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_EXTENSIONS = [
|
||||||
|
'.jpg',
|
||||||
|
'.jpeg',
|
||||||
|
'.png',
|
||||||
|
'.bmp',
|
||||||
|
'.gif',
|
||||||
|
'.tiff',
|
||||||
|
'.tif',
|
||||||
|
]
|
||||||
|
|
||||||
|
TMPL_LOADER = jinja2.PackageLoader(__name__.rsplit('.', 1)[0])
|
||||||
|
|
||||||
|
|
||||||
|
def render(request, template, context=None):
|
||||||
|
if context is None:
|
||||||
|
context = {}
|
||||||
|
env = jinja2.Environment(loader=TMPL_LOADER)
|
||||||
|
env.globals.update(
|
||||||
|
url=request.create_href,
|
||||||
|
static=request.static_resource,
|
||||||
|
)
|
||||||
|
return env.get_template(template).render(**context)
|
||||||
|
|
||||||
|
|
||||||
|
def get_images(path, extensions=None):
|
||||||
|
if extensions is None:
|
||||||
|
extensions = DEFAULT_EXTENSIONS
|
||||||
|
try:
|
||||||
|
for f in os.listdir(path):
|
||||||
|
if os.path.splitext(f)[1] in extensions:
|
||||||
|
yield f
|
||||||
|
except OSError:
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
|
|
||||||
class GalleryController(milla.controllers.HTTPVerbController):
|
class GalleryController(milla.controllers.HTTPVerbController):
|
||||||
|
|
||||||
def GET(self, request):
|
def GET(self, request):
|
||||||
response = request.ResponseClass()
|
response = request.ResponseClass()
|
||||||
|
response.text = render(request, 'gallery.html.j2', {
|
||||||
|
'images': get_images(request.config['gallery.screenshot_dir']),
|
||||||
|
})
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Dark Chest of Wonders</title>
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="//cdnjs.cloudflare.com/ajax/libs/foundation/6.2.1/foundation.min.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns">
|
||||||
|
<h1>Dark Chest of Wonders</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row small-up-1 medium-up-2 large-up-4">
|
||||||
|
{% for image in images %}
|
||||||
|
<div class="column">
|
||||||
|
<a href="{{ static('screenshots/' + image) }}">
|
||||||
|
<img src="{{ static('screenshots/' + image) }}"
|
||||||
|
alt="{{ image.rsplit('.', 1)[0] }}" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in New Issue