Skip to content

Commit

Permalink
Preserve style in cloned templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Oct 21, 2022
1 parent 3ec915b commit b72980e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/main.py
Expand Up @@ -46,5 +46,5 @@ async def robots(request):
auto_reload=True,
access_log=False,
motd=False,
fast=True,
fast=not settings.DEBUG,
)
6 changes: 4 additions & 2 deletions app/models/template.py
Expand Up @@ -373,7 +373,9 @@ async def _embed(

return await foreground.exists()

async def clone(self, layout: str, lines: int, *, animated: bool) -> "Template":
async def clone(
self, layout: str, lines: int = 1, style: str = "default", *, animated: bool
) -> "Template":
if layout != "top":
return self

Expand All @@ -394,7 +396,7 @@ async def clone(self, layout: str, lines: int, *, animated: bool) -> "Template":
)
template.text.append(text)

source = self.get_image(animated=animated)
source = self.get_image(style=style, animated=animated)
suffix = source.suffix
if suffix == settings.PLACEHOLDER_SUFFIX:
suffix = settings.DEFAULT_SUFFIX
Expand Down
2 changes: 1 addition & 1 deletion app/tests/test_utils_images.py
Expand Up @@ -353,7 +353,7 @@ def test_preview_images(images, template):

@pytest.mark.asyncio
async def test_preview_images_top_layout(images, template: models.Template):
template = await template.clone("top", 2, animated=False)
template = await template.clone(layout="top", lines=2, animated=False)
path = images / "preview-top.jpg"
data, _extension = utils.images.preview(template, ["Nominal image", "while typing"])
path.write_bytes(data)
4 changes: 2 additions & 2 deletions app/views/helpers.py
Expand Up @@ -114,7 +114,7 @@ async def preview_image(id: str, style: str, lines: list[str], layout: str):
if not any(line.strip() for line in lines):
lines = template.example

template = await template.clone(layout, len(lines), animated=False)
template = await template.clone(layout, len(lines), style, animated=False)

if not utils.urls.schema(style):
style = style.strip().lower()
Expand Down Expand Up @@ -201,7 +201,7 @@ async def render_image(
status = 422

layout = utils.urls.arg(request.args, "default", "layout")
template = await template.clone(layout, len(lines), animated=animated)
template = await template.clone(layout, len(lines), style, animated=animated)

template.animate(
utils.urls.arg(request.args, "", "start"),
Expand Down

0 comments on commit b72980e

Please sign in to comment.