Deduplicate macro rendering paths
This commit is contained in:
1
AUDIT.md
1
AUDIT.md
@@ -14,6 +14,7 @@ after each item.
|
|||||||
|
|
||||||
- [x] `rendering/labels.ex`
|
- [x] `rendering/labels.ex`
|
||||||
- [x] `rendering/liquid_parser.ex` (verified Liquex does not expose a built-in filter/operator subset validator; keeping current implementation)
|
- [x] `rendering/liquid_parser.ex` (verified Liquex does not expose a built-in filter/operator subset validator; keeping current implementation)
|
||||||
|
- [x] `rendering/filters.ex`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -85,29 +85,10 @@ defmodule BDS.Rendering.Filters do
|
|||||||
|
|
||||||
case String.downcase(macro_name) do
|
case String.downcase(macro_name) do
|
||||||
"youtube" ->
|
"youtube" ->
|
||||||
render_macro_template(
|
render_video_macro("youtube", params, language, "YouTube video", context)
|
||||||
"macros/youtube",
|
|
||||||
%{
|
|
||||||
"id" => Map.get(params, "id", ""),
|
|
||||||
"title" =>
|
|
||||||
default_macro_title(
|
|
||||||
Map.get(params, "title"),
|
|
||||||
language,
|
|
||||||
"YouTube video"
|
|
||||||
)
|
|
||||||
},
|
|
||||||
context
|
|
||||||
)
|
|
||||||
|
|
||||||
"vimeo" ->
|
"vimeo" ->
|
||||||
render_macro_template(
|
render_video_macro("vimeo", params, language, "Vimeo video", context)
|
||||||
"macros/vimeo",
|
|
||||||
%{
|
|
||||||
"id" => Map.get(params, "id", ""),
|
|
||||||
"title" => default_macro_title(Map.get(params, "title"), language, "Vimeo video")
|
|
||||||
},
|
|
||||||
context
|
|
||||||
)
|
|
||||||
|
|
||||||
"gallery" ->
|
"gallery" ->
|
||||||
render_gallery_macro(context, params, post_id)
|
render_gallery_macro(context, params, post_id)
|
||||||
@@ -313,61 +294,15 @@ defmodule BDS.Rendering.Filters do
|
|||||||
|
|
||||||
# ── Built-in macro renderers ───────────────────────────────────────────────
|
# ── Built-in macro renderers ───────────────────────────────────────────────
|
||||||
|
|
||||||
defp render_gallery_macro(context, params, post_id) when is_binary(post_id) do
|
defp render_gallery_macro(context, params, post_id) do
|
||||||
columns = normalize_columns(Map.get(params, "columns", "3"), 3, 1, 6)
|
normalized_post_id = if is_binary(post_id), do: post_id, else: ""
|
||||||
caption = Map.get(params, "caption")
|
items = if is_binary(post_id), do: gallery_items(post_id), else: []
|
||||||
|
|
||||||
items =
|
render_gallery_template(context, params, normalized_post_id, items)
|
||||||
post_id
|
|
||||||
|> linked_media_images()
|
|
||||||
|> Enum.map(fn media ->
|
|
||||||
%{
|
|
||||||
"media_path" => "/#{media.file_path}",
|
|
||||||
"title" => media.title || media.original_name,
|
|
||||||
"alt" => media.alt || media.title || media.original_name,
|
|
||||||
"group_name" => post_id
|
|
||||||
}
|
|
||||||
end)
|
|
||||||
|
|
||||||
render_macro_template(
|
|
||||||
"macros/gallery",
|
|
||||||
%{
|
|
||||||
"columns" => columns,
|
|
||||||
"post_id" => post_id,
|
|
||||||
"items" => items,
|
|
||||||
"caption" => caption,
|
|
||||||
"empty_label" =>
|
|
||||||
BDS.Gettext.lgettext(
|
|
||||||
Access.get(context, "language") || "en",
|
|
||||||
"render",
|
|
||||||
"No images"
|
|
||||||
)
|
|
||||||
},
|
|
||||||
context
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp render_gallery_macro(context, params, _post_id) do
|
|
||||||
render_macro_template(
|
|
||||||
"macros/gallery",
|
|
||||||
%{
|
|
||||||
"columns" => normalize_columns(Map.get(params, "columns", "3"), 3, 1, 6),
|
|
||||||
"post_id" => "",
|
|
||||||
"items" => [],
|
|
||||||
"caption" => Map.get(params, "caption"),
|
|
||||||
"empty_label" =>
|
|
||||||
BDS.Gettext.lgettext(
|
|
||||||
Access.get(context, "language") || "en",
|
|
||||||
"render",
|
|
||||||
"No images"
|
|
||||||
)
|
|
||||||
},
|
|
||||||
context
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp render_photo_archive_macro(context, params) do
|
defp render_photo_archive_macro(context, params) do
|
||||||
language = Access.get(context, "language") || "en"
|
language = macro_language(context)
|
||||||
project_id = project_id_from_context(context)
|
project_id = project_id_from_context(context)
|
||||||
|
|
||||||
months =
|
months =
|
||||||
@@ -390,7 +325,7 @@ defmodule BDS.Rendering.Filters do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp render_tag_cloud_macro(context, params) do
|
defp render_tag_cloud_macro(context, params) do
|
||||||
language = Access.get(context, "language") || "en"
|
language = macro_language(context)
|
||||||
project_id = project_id_from_context(context)
|
project_id = project_id_from_context(context)
|
||||||
|
|
||||||
{words_json, width, height} =
|
{words_json, width, height} =
|
||||||
@@ -414,6 +349,44 @@ defmodule BDS.Rendering.Filters do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp render_video_macro(kind, params, language, translation, context) do
|
||||||
|
render_macro_template(
|
||||||
|
"macros/#{kind}",
|
||||||
|
%{
|
||||||
|
"id" => Map.get(params, "id", ""),
|
||||||
|
"title" => default_macro_title(Map.get(params, "title"), language, translation)
|
||||||
|
},
|
||||||
|
context
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp render_gallery_template(context, params, post_id, items) do
|
||||||
|
render_macro_template(
|
||||||
|
"macros/gallery",
|
||||||
|
%{
|
||||||
|
"columns" => normalize_columns(Map.get(params, "columns", "3"), 3, 1, 6),
|
||||||
|
"post_id" => post_id,
|
||||||
|
"items" => items,
|
||||||
|
"caption" => Map.get(params, "caption"),
|
||||||
|
"empty_label" => BDS.Gettext.lgettext(macro_language(context), "render", "No images")
|
||||||
|
},
|
||||||
|
context
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp gallery_items(post_id) do
|
||||||
|
post_id
|
||||||
|
|> linked_media_images()
|
||||||
|
|> Enum.map(fn media ->
|
||||||
|
%{
|
||||||
|
"media_path" => "/#{media.file_path}",
|
||||||
|
"title" => media.title || media.original_name,
|
||||||
|
"alt" => media.alt || media.title || media.original_name,
|
||||||
|
"group_name" => post_id
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
# ── Data queries for macros ────────────────────────────────────────────────
|
# ── Data queries for macros ────────────────────────────────────────────────
|
||||||
|
|
||||||
defp linked_media_images(post_id) do
|
defp linked_media_images(post_id) do
|
||||||
@@ -556,6 +529,8 @@ defmodule BDS.Rendering.Filters do
|
|||||||
|
|
||||||
# ── Helpers ────────────────────────────────────────────────────────────────
|
# ── Helpers ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
defp macro_language(context), do: Access.get(context, "language") || "en"
|
||||||
|
|
||||||
defp project_id_from_context(context) do
|
defp project_id_from_context(context) do
|
||||||
post = Access.get(context, "post") || %{}
|
post = Access.get(context, "post") || %{}
|
||||||
post["project_id"] || Access.get(post, :project_id) || project_id_from_post(context)
|
post["project_id"] || Access.get(post, :project_id) || project_id_from_post(context)
|
||||||
|
|||||||
Reference in New Issue
Block a user