Skip to content

Commit

Permalink
Merge f22079d into 2c0a376
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Apr 2, 2016
2 parents 2c0a376 + f22079d commit f8ef18c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
6 changes: 2 additions & 4 deletions memegen/routes/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ def route(*args, **kwargs):
return unquote(_url_for(*args, **kwargs))


def samples():
def samples(blank=False):
"""Generate dictionaries of sample image data for template rendering."""
for template in sorted(current_app.template_service.all()):
path = template.sample_path
url = route('image.get', key=template.key, path=path)
link = route('links.get', key=template.key, path=path)
url = route('image.get', key=template.key, path="_" if blank else path)
yield {
'key': template.key,
'name': template.name,
'url': url,
'link': link
}


Expand Down
8 changes: 5 additions & 3 deletions memegen/routes/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@

@blueprint.route("")
def get_index():
imgs = list(samples())
template_images = list(samples(blank=True))
sample_images = list(samples())
return Response(render_template(
"index.html",
imgs=imgs,
default=random.choice(imgs)['key'],
template_images=template_images,
default_template=random.choice(template_images)['key'],
sample_images=sample_images,
github_slug=GITHUB_SLUG,
ga_tid=get_tid(),
))
Expand Down
16 changes: 10 additions & 6 deletions memegen/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ <h2>The open source meme generator.</h2>
<label for="top" class="col-sm-2 control-label">Meme</label>
<div class="col-sm-10">
<select class="js-meme-selector" name="meme">
{% for img in imgs %}
<option value="{{ img.key }}" data-url="{{ img.url }}" data-link="{{ img.link }}" data-top="{{ img.top }}">
{% for img in template_images %}
<option value="{{ img.key }}" data-url="{{ img.url }}" data-top="{{ img.top }}" data-bottom="{{ img.bottom }}">
{{ img.name }}
</option>
{% endfor %}
Expand All @@ -75,14 +75,14 @@ <h2>The open source meme generator.</h2>
<div class="form-group">
<label for="top" class="col-sm-2 control-label">Top Text</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="meme-text-top" name="top" value="I don't know what this meme is for"/>
<input type="text" class="form-control" id="meme-text-top" name="top"/>
</div>
</div>

<div class="form-group">
<label for="bottom" class="col-sm-2 control-label">Bottom Text</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="meme-text-bottom" name="bottom" value="and at this point I'm too afraid to ask"/>
<input type="text" class="form-control" id="meme-text-bottom" name="bottom"/>
</div>
</div>

Expand All @@ -107,7 +107,7 @@ <h2>The open source meme generator.</h2>

<div class="meme-templates">
<div class="row">
{% for img in imgs %}
{% for img in sample_images %}


<div class="col-sm-4">
Expand Down Expand Up @@ -207,7 +207,11 @@ <h2>The open source meme generator.</h2>
generateMeme();
});

$( ".js-meme-selector" ).val("{{ default }}").trigger("change");
if ($('#meme-text-top').val() || $('#meme-text-bottom').val()) {
$(".js-meme-selector").trigger("change");
} else {
$(".js-meme-selector").val("{{ default_template }}").trigger("change");;
}
</script>

<script>
Expand Down

0 comments on commit f8ef18c

Please sign in to comment.