Skip to content

Commit

Permalink
Refactor sample image data generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Oct 25, 2015
1 parent dabf7e5 commit 3e50d16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
13 changes: 13 additions & 0 deletions memegen/routes/_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from urllib.parse import unquote

from flask import current_app as app
from flask import url_for as _url_for


Expand All @@ -10,3 +11,15 @@
def url_for(*args, **kwargs):
"""Unquoted version of Flask's `url_for`."""
return unquote(_url_for(*args, **kwargs))


def samples():
"""Generate dictionaries of sample image data for template rendering."""
for template in sorted(app.template_service.all()):
path = template.sample_path
url = url_for("image.get", key=template.key, path=path, _external=True)
link = url_for("links.get", key=template.key, path=path)
yield {
'url': url,
'link': link
}
17 changes: 3 additions & 14 deletions memegen/routes/overview.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
from flask import Blueprint, current_app as app, render_template
from flask import Blueprint, render_template
from flask_api.decorators import set_renderers
from flask_api.renderers import HTMLRenderer

from ._common import url_for
from ._common import samples


blueprint = Blueprint('overview', __name__, url_prefix="/overview")


def _gen():
for template in sorted(app.template_service.all()):
path = template.sample_path
url = url_for("image.get", key=template.key, path=path, _external=True)
link = url_for("links.get", key=template.key, path=path)
yield {
'url': url,
'link': link
}


@blueprint.route("")
@set_renderers(HTMLRenderer)
def get():
return render_template('overview.html', imgs=_gen())
return render_template('overview.html', imgs=samples())

0 comments on commit 3e50d16

Please sign in to comment.