Skip to content

Commit

Permalink
Merge 5784863 into 503f074
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Apr 17, 2019
2 parents 503f074 + 5784863 commit d5e00a4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
14 changes: 13 additions & 1 deletion memegen/routes/custom.py
@@ -1,14 +1,26 @@
from flask import Blueprint, render_template, current_app, make_response
from webargs import fields, flaskparser

from . image import PLACEHOLDER


OPTIONS = {
'font': fields.Str(missing='titilliumweb-black'),
'image': fields.URL(missing=PLACEHOLDER),
}


blueprint = Blueprint('custom-page', __name__)


@blueprint.route("/custom")
def get():
@flaskparser.use_kwargs(OPTIONS)
def get(font, image):
html = render_template(
'custom.html',
fonts=sorted(current_app.font_service.all()),
font=font,
image=image,
config=current_app.config,
)
response = make_response(html)
Expand Down
5 changes: 2 additions & 3 deletions memegen/templates/custom.html
Expand Up @@ -99,14 +99,13 @@
// Generate with defaults
$('#meme-line-1').val("your text");
$('#meme-line-2').val("goes here");
$('#meme-font').val("titilliumweb-black");
$('#meme-background').val("http://www.gstatic.com/webp/gallery/1.jpg");
$('#meme-font').val('{{ font }}');
$('#meme-background').val('{{ image }}');
$('#btn-generate').click();

// Clear defaults
$('#meme-line-1').val("");
$('#meme-line-2').val("");
$('#meme-background').val("");

</script>
{% endblock %}
2 changes: 1 addition & 1 deletion memegen/templates/layout.html
Expand Up @@ -2,7 +2,7 @@
('index', '/', 'Home'),
('examples', '/examples', 'Examples'),
('latest', '/latest', 'Latest'),
('custom', '/custom', 'Custom'),
('custom', '/custom?image=http://www.gstatic.com/webp/gallery/1.jpg', 'Custom'),
] -%}

<!DOCTYPE html>
Expand Down
28 changes: 28 additions & 0 deletions tests/test_custom.py
@@ -0,0 +1,28 @@
# pylint: disable=unused-variable,expression-not-assigned,line-too-long

from expecter import expect


def describe_custom():

def it_selects_image_from_query_param(client):
response = client.get("/custom?image=http://www.gstatic.com/webp/gallery/2.jpg")

expect(response.status_code) == 200
expect(response.mimetype) == 'text/html'

html = response.get_data(as_text=True)

expect(html).contains("$('#meme-font').val('titilliumweb-black');")
expect(html).contains("$('#meme-background').val('http://www.gstatic.com/webp/gallery/2.jpg');")

def it_selects_font_from_query_param(client):
response = client.get("/custom?font=impact")

expect(response.status_code) == 200
expect(response.mimetype) == 'text/html'

html = response.get_data(as_text=True)

expect(html).contains("$('#meme-font').val('impact');")
expect(html).contains("$('#meme-background').val('https://raw.githubusercontent.com/jacebrowning/memegen/master/memegen/static/images/missing.png');")

0 comments on commit d5e00a4

Please sign in to comment.