Skip to content

Commit

Permalink
Merge pull request #697 from jacebrowning/disable-animation-update
Browse files Browse the repository at this point in the history
Preserve template config when start/stop is passed
  • Loading branch information
jacebrowning committed Feb 23, 2022
2 parents 5038eb0 + 5df2c4b commit 6a8527b
Show file tree
Hide file tree
Showing 139 changed files with 285 additions and 301 deletions.
33 changes: 10 additions & 23 deletions app/models/template.py
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path

import aiopath
from datafiles import datafile, field
from datafiles import datafile, field, hooks
from furl import furl
from sanic import Request
from sanic.log import logger
Expand All @@ -15,19 +15,8 @@
from .overlay import Overlay
from .text import Text

DEFAULT_TEXT = [
Text(start=0.0, stop=1.0),
Text(start=0.0, stop=1.0, anchor_x=0.0, anchor_y=0.8),
]
ANIMATED_TEXT = [
Text(start=0.2, stop=1.0),
Text(start=0.6, stop=1.0, anchor_x=0.0, anchor_y=0.8),
]

DEFAULT_EXAMPLE = [
"Top Line",
"Bottom Line",
]
DEFAULT_TEXT = [Text(), Text(anchor_x=0.0, anchor_y=0.8)]
DEFAULT_EXAMPLE = ["Top Line", "Bottom Line"]


@datafile("../../templates/{self.id}/config.yml", defaults=True)
Expand Down Expand Up @@ -316,8 +305,6 @@ async def _embed(

@property
def animated(self):
if self.text == DEFAULT_TEXT or self.text == ANIMATED_TEXT:
return False
return any(text.animated for text in self.text)

def animate(self, start: str = "0.2,0.6", stop: str = "1.0,1.0"):
Expand All @@ -328,13 +315,13 @@ def animate(self, start: str = "0.2,0.6", stop: str = "1.0,1.0"):
logger.error(f"Invalid text animation: {start=} {stop=}")
return

with suppress(IndexError):
for index, value in enumerate(starts):
self.text[index].start = value

with suppress(IndexError):
for index, value in enumerate(stops):
self.text[index].stop = value
with hooks.disabled():
with suppress(IndexError):
for index, value in enumerate(starts):
self.text[index].start = value
with suppress(IndexError):
for index, value in enumerate(stops):
self.text[index].stop = value

if starts or stops:
logger.info(f"Updated {self} with: {starts=} {stops=}")
Expand Down
5 changes: 1 addition & 4 deletions app/tests/test_models_template.py
Expand Up @@ -34,10 +34,7 @@ def it_only_includes_default_style_with_custom_overlay(

def describe_text():
def it_defaults_to_two_lines(expect, template):
expect(template.text) == [
Text(start=0.2),
Text(start=0.6, anchor_x=0.0, anchor_y=0.8),
]
expect(template.text) == [Text(), Text(anchor_x=0.0, anchor_y=0.8)]

def describe_image():
def it_has_generic_extension_when_absent(expect, template):
Expand Down
4 changes: 2 additions & 2 deletions templates/_error/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 0.8
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 0.8
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- Top Line
Expand Down
4 changes: 2 additions & 2 deletions templates/_test/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- Top Line
Expand Down
4 changes: 2 additions & 2 deletions templates/aag/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- ''
Expand Down
4 changes: 2 additions & 2 deletions templates/ackbar/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- ''
Expand Down
4 changes: 2 additions & 2 deletions templates/afraid/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- i don't know what this meme is for
Expand Down
4 changes: 2 additions & 2 deletions templates/agnes/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- ''
Expand Down
4 changes: 2 additions & 2 deletions templates/aint-got-time/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- memes?
Expand Down
4 changes: 2 additions & 2 deletions templates/ams/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- when you're watching a movie
Expand Down
4 changes: 2 additions & 2 deletions templates/ants/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- do you want ants?
Expand Down
4 changes: 2 additions & 2 deletions templates/apcr/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- I supported my sister's abortion
Expand Down
4 changes: 2 additions & 2 deletions templates/atis/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- and then i said
Expand Down
4 changes: 2 additions & 2 deletions templates/away/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- life...
Expand Down
4 changes: 2 additions & 2 deletions templates/awesome-awkward/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- first day at new job
Expand Down
4 changes: 2 additions & 2 deletions templates/awesome/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- say a word wrong
Expand Down
4 changes: 2 additions & 2 deletions templates/awkward-awesome/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- trip guy on the street
Expand Down
4 changes: 2 additions & 2 deletions templates/awkward/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- start telling joke
Expand Down
4 changes: 2 additions & 2 deletions templates/bad/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- your meme is bad
Expand Down
4 changes: 2 additions & 2 deletions templates/badchoice/config.yml
Expand Up @@ -9,7 +9,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.2
start: 0.0
stop: 1.0
- style: upper
color: white
Expand All @@ -19,7 +19,7 @@ text:
angle: 0.0
scale_x: 1.0
scale_y: 0.2
start: 0.6
start: 0.0
stop: 1.0
example:
- milk
Expand Down

0 comments on commit 6a8527b

Please sign in to comment.