feat: added liquid templates

This commit is contained in:
2026-04-23 21:37:45 +02:00
parent b48bed8823
commit 4e46e1b393
42 changed files with 2470 additions and 53 deletions

View File

@@ -59,4 +59,105 @@ defmodule BDS.PreviewTest do
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "draft preview renders through the published post template", %{project: project} do
assert {:ok, template} =
BDS.Templates.create_template(%{
project_id: project.id,
title: "Preview Post",
kind: :post,
content: "<article class=\"preview-template\"><h1>{{ post.title }}</h1><div>{{ post.content }}</div></article>"
})
assert {:ok, published_template} = BDS.Templates.publish_template(template.id)
assert {:ok, post} =
Posts.create_post(%{
project_id: project.id,
title: "Draft Post",
content: "Draft preview body",
language: "en",
template_slug: published_template.slug
})
assert {:ok, _server} = BDS.Preview.start_preview(project.id)
assert {:ok, %{body: draft_html, content_type: "text/html"}} =
BDS.Preview.preview_draft(project.id, "/draft/draft-post", post.id)
assert draft_html =~ "preview-template"
assert draft_html =~ "Draft Post"
assert draft_html =~ "Draft preview body"
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "draft preview renders through copied starter templates with markdown and i18n", %{project: project} do
assert {:ok, _menu} =
BDS.Menu.update_menu(project.id, [
%{kind: :page, label: "Notes", slug: "notes"}
])
assert {:ok, _metadata} =
Metadata.update_project_metadata(project.id, %{
public_url: "https://example.com/blog",
main_language: "en",
blog_languages: ["en", "de"]
})
assert {:ok, post} =
Posts.create_post(%{
project_id: project.id,
title: "Draft Post",
content: "**Draft** preview body",
language: "en"
})
assert {:ok, _server} = BDS.Preview.start_preview(project.id)
assert {:ok, %{body: draft_html, content_type: "text/html"}} =
BDS.Preview.preview_draft(project.id, "/draft/draft-post", post.id)
assert draft_html =~ ~s(data-template="single-post")
assert draft_html =~ ~s(<strong>Draft</strong> preview body)
assert draft_html =~ "Language"
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "start_preview serves generated and draft routes over real HTTP on localhost", %{project: project} do
:inets.start()
assert {:ok, _metadata} =
Metadata.update_project_metadata(project.id, %{
public_url: "https://example.com/blog",
main_language: "en",
blog_languages: ["en"]
})
assert {:ok, _} = Generation.write_generated_file(project.id, "index.html", "<html>http home</html>")
assert {:ok, post} =
Posts.create_post(%{
project_id: project.id,
title: "HTTP Draft",
content: "Draft over HTTP",
language: "en"
})
assert {:ok, server} = BDS.Preview.start_preview(project.id)
assert {:ok, {{_version, 200, _reason}, headers, body}} =
:httpc.request(:get, {to_charlist("http://#{server.host}:#{server.port}/"), []}, [], body_format: :binary)
assert body == "<html>http home</html>"
assert Enum.any?(headers, fn {name, value} -> String.downcase(to_string(name)) == "content-type" and to_string(value) =~ "text/html" end)
assert {:ok, {{_version, 200, _reason}, _headers, draft_body}} =
:httpc.request(:get, {to_charlist("http://#{server.host}:#{server.port}/draft/http-draft?post_id=#{post.id}"), []}, [], body_format: :binary)
assert draft_body =~ "Draft over HTTP"
assert :ok = BDS.Preview.stop_preview(project.id)
end
end