Skip to content

Commit

Permalink
Use "your-text/goes-here" as sample path
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Oct 4, 2015
1 parent ed9ad1b commit 4c37284
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 19 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ Icon*
env

# Temporary server files
.env
*.pid

# Generated documentation
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Expand Up @@ -90,7 +90,7 @@ $(ALL_FLAG): $(SOURCES)
ci: check test tests validate

.PHONY: run
run: depends-dev
run: depends-dev .env
$(HONCHO) start

.PHONY: launch
Expand All @@ -107,6 +107,9 @@ watch: depends-dev .clean-test
@ rm -rf $(FAILED_FLAG)
$(SNIFFER)

.env:
echo "CONFIG = dev" >> .env

# Development Installation #####################################################

.PHONY: env
Expand Down
2 changes: 1 addition & 1 deletion memegen/domain/image.py
Expand Up @@ -84,7 +84,7 @@ def make_meme(top, bottom, background, path, match_font_size=False):
_draw_outlined_text(draw, bottom_text_position,
bottom, bottom_font, bottom_font_size)

log.info("generated: %s", path)
log.info("generating: %s", path)
return img.save(path)


Expand Down
24 changes: 19 additions & 5 deletions memegen/domain/template.py
Expand Up @@ -14,8 +14,11 @@
class Template:
"""Blank image to generate a meme."""

DEFAULTS = ("default.png", "default.jpg")
DEFAULT_IMAGES = ("default.png", "default.jpg")
DEFAULT_LINES = ["YOUR TEXT", "GOES HERE"]

VALID_LINK_FLAG = '.valid_link.tmp'

MIN_HEIGHT = 240
MIN_WIDTH = 240

Expand All @@ -42,16 +45,27 @@ def __lt__(self, other):

@property
def path(self):
for default in self.DEFAULTS:
for default in self.DEFAULT_IMAGES:
path = os.path.join(self.root, self.key, default)
if os.path.isfile(path):
return path
return None

@property
def default(self):
text = Text('/'.join(self.lines))
return text.path
def default_text(self):
return Text('/'.join(self.lines))

@property
def default_path(self):
return self.default_text.path

@property
def sample_text(self):
return self.default_text or Text('/'.join(self.DEFAULT_LINES))

@property
def sample_path(self):
return self.sample_text.path

@property
def aliases_lowercase(self):
Expand Down
3 changes: 3 additions & 0 deletions memegen/domain/text.py
Expand Up @@ -6,6 +6,9 @@ def __init__(self, path=None):
def __str__(self):
return ' / '.join(self.lines)

def __bool__(self):
return bool(self.path.strip("_/"))

def __getitem__(self, key):
try:
part = self._parts[key]
Expand Down
2 changes: 1 addition & 1 deletion memegen/routes/image.py
Expand Up @@ -22,7 +22,7 @@ def get_latest():
@blueprint.route("<key>.jpg")
def get_without_text(key):
template = app.template_service.find(key)
text = domain.Text(template.default or '_')
text = domain.Text(template.default_path or '_')
return redirect(url_for(".get", key=key, path=text.path))


Expand Down
2 changes: 1 addition & 1 deletion memegen/routes/overview.py
Expand Up @@ -10,7 +10,7 @@

def _gen():
for template in sorted(app.template_service.all()):
path = template.default or "your-text/goes-here"
path = template.default_path
url = url_for("image.get", key=template.key, path=path, _external=True)
link = url_for("links.get", key=template.key, path=path)
yield {
Expand Down
2 changes: 1 addition & 1 deletion memegen/routes/templates.py
Expand Up @@ -36,7 +36,7 @@ def create_meme(key):
data['name'] = template.name
data['description'] = template.link
data['aliases'] = sorted(template.aliases + [template.key])
path = template.default or "hello/world"
path = template.sample_path
url = url_for("links.get", key=key, path=path, _external=True)
data['example'] = url
return data
Expand Down
16 changes: 12 additions & 4 deletions memegen/test/test_domain_template.py
Expand Up @@ -34,13 +34,21 @@ def test_path_is_none_with_no_file(self, template):

assert None is path

def test_default(self, template):
assert "foo/bar" == template.default
def test_default_path(self, template):
assert "foo/bar" == template.default_path

def test_default_with_no_lines(self, template):
def test_default_path_with_no_lines(self, template):
template.lines = []

assert "" == template.default
assert "" == template.default_path

def test_sample_path(self, template):
assert "foo/bar" == template.sample_path

def test_sample_path_with_no_lines(self, template):
template.lines = []

assert "your-text/goes-here" == template.sample_path

def test_validate_meta_with_no_name(self, template):
template.name = None
Expand Down
18 changes: 15 additions & 3 deletions memegen/test/test_domain_text.py
Expand Up @@ -3,7 +3,7 @@
from memegen.domain import Text


class TestTextInit:
class TestInit:

def test_none(self):
text = Text()
Expand Down Expand Up @@ -33,7 +33,19 @@ def test_2_slashes(self):
assert "" == text.get_line(3)


class TestTextLines:
class TestBool:

def test_content_is_truthy(self):
assert True is bool(Text("Hello, world!"))

def test_empty_is_falsey(self):
assert False is bool(Text())

def test_only_spaces_is_falsey(self):
assert False is bool(Text("_/_/_"))


class TestLines:

def test_split_underscore_as_spaces(self):
text = Text("hello_world")
Expand Down Expand Up @@ -116,7 +128,7 @@ def test_percents_are_escaped(self):
assert ["99% VS. 1%"] == text.lines


class TestTextPath:
class TestPath:

def test_case_ignored(self):
text = Text("hello/World")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_routes_templates.py
Expand Up @@ -13,7 +13,7 @@ def test_get(self, client):
name="Insanity Wolf",
description="http://knowyourmeme.com/memes/insanity-wolf",
aliases=['insanity', 'insanity-wolf', 'iw'],
example="http://localhost/iw/hello/world",
example="http://localhost/iw/your-text/goes-here",
) == load(response)

def test_get_with_default(self, client):
Expand Down

0 comments on commit 4c37284

Please sign in to comment.