From 8e9d6285e4faab32e562909e8dfb797c7ebc7b5f Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Thu, 7 May 2020 22:19:08 -0400 Subject: [PATCH] move textile renderer to web namespace --- .../controllers/admin/dnp_entry_controller.ex | 4 ++-- .../controllers/admin/mod_note_controller.ex | 4 ++-- .../controllers/admin/report_controller.ex | 6 +++--- lib/philomena_web/controllers/comment_controller.ex | 5 +++-- .../controllers/conversation_controller.ex | 4 ++-- .../controllers/dnp_entry_controller.ex | 8 ++++---- .../controllers/image/comment_controller.ex | 7 ++++--- .../controllers/image/description_controller.ex | 4 ++-- lib/philomena_web/controllers/image_controller.ex | 8 ++++---- .../controllers/post/preview_controller.ex | 4 ++-- lib/philomena_web/controllers/post_controller.ex | 5 +++-- .../controllers/profile/commission_controller.ex | 8 ++++---- .../controllers/profile/detail_controller.ex | 4 ++-- lib/philomena_web/controllers/profile_controller.ex | 12 ++++++------ lib/philomena_web/controllers/tag_controller.ex | 6 +++--- lib/philomena_web/controllers/topic_controller.ex | 4 ++-- lib/philomena_web/image_loader.ex | 6 +++--- .../textile_renderer.ex} | 3 +-- 18 files changed, 52 insertions(+), 50 deletions(-) rename lib/{philomena/textile/renderer.ex => philomena_web/textile_renderer.ex} (97%) diff --git a/lib/philomena_web/controllers/admin/dnp_entry_controller.ex b/lib/philomena_web/controllers/admin/dnp_entry_controller.ex index 21a796c7..3e53d7ab 100644 --- a/lib/philomena_web/controllers/admin/dnp_entry_controller.ex +++ b/lib/philomena_web/controllers/admin/dnp_entry_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Admin.DnpEntryController do use PhilomenaWeb, :controller - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.DnpEntries.DnpEntry alias Philomena.Repo import Ecto.Query @@ -45,7 +45,7 @@ defmodule PhilomenaWeb.Admin.DnpEntryController do bodies = dnp_entries |> Enum.map(&%{body: &1.conditions}) - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) dnp_entries = %{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)} diff --git a/lib/philomena_web/controllers/admin/mod_note_controller.ex b/lib/philomena_web/controllers/admin/mod_note_controller.ex index 6cd9e62d..53d91eb1 100644 --- a/lib/philomena_web/controllers/admin/mod_note_controller.ex +++ b/lib/philomena_web/controllers/admin/mod_note_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do use PhilomenaWeb, :controller - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.ModNotes.ModNote alias Philomena.Polymorphic alias Philomena.ModNotes @@ -29,7 +29,7 @@ defmodule PhilomenaWeb.Admin.ModNoteController do |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) - bodies = Renderer.render_collection(mod_notes, conn) + bodies = TextileRenderer.render_collection(mod_notes, conn) preloaded = Polymorphic.load_polymorphic(mod_notes, notable: [notable_id: :notable_type]) mod_notes = %{mod_notes | entries: Enum.zip(bodies, preloaded)} diff --git a/lib/philomena_web/controllers/admin/report_controller.ex b/lib/philomena_web/controllers/admin/report_controller.ex index ede6fac8..3df8274a 100644 --- a/lib/philomena_web/controllers/admin/report_controller.ex +++ b/lib/philomena_web/controllers/admin/report_controller.ex @@ -2,7 +2,7 @@ defmodule PhilomenaWeb.Admin.ReportController do use PhilomenaWeb, :controller alias Philomena.Elasticsearch - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Reports.Report alias Philomena.Reports.Query alias Philomena.Polymorphic @@ -73,7 +73,7 @@ defmodule PhilomenaWeb.Admin.ReportController do reportable: [reportable_id: :reportable_type] ) - body = Renderer.render_one(%{body: report.reason}, conn) + body = TextileRenderer.render_one(%{body: report.reason}, conn) render(conn, "show.html", title: "Showing Report", report: report, body: body) end @@ -125,7 +125,7 @@ defmodule PhilomenaWeb.Admin.ReportController do mod_notes = mod_notes - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) |> Enum.zip(mod_notes) assign(conn, :mod_notes, mod_notes) diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index 4e3d7fac..82f48a41 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -1,8 +1,9 @@ defmodule PhilomenaWeb.CommentController do use PhilomenaWeb, :controller + alias PhilomenaWeb.TextileRenderer alias Philomena.Elasticsearch - alias Philomena.{Comments.Query, Comments.Comment, Textile.Renderer} + alias Philomena.{Comments.Query, Comments.Comment} import Ecto.Query def index(conn, params) do @@ -36,7 +37,7 @@ defmodule PhilomenaWeb.CommentController do Comment |> preload([:deleted_by, image: [:tags], user: [awards: :badge]]) ) - rendered = Renderer.render_collection(comments.entries, conn) + rendered = TextileRenderer.render_collection(comments.entries, conn) comments = %{comments | entries: Enum.zip(rendered, comments.entries)} diff --git a/lib/philomena_web/controllers/conversation_controller.ex b/lib/philomena_web/controllers/conversation_controller.ex index 817c4275..07fcfe00 100644 --- a/lib/philomena_web/controllers/conversation_controller.ex +++ b/lib/philomena_web/controllers/conversation_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.ConversationController do alias PhilomenaWeb.NotificationCountPlug alias Philomena.{Conversations, Conversations.Conversation, Conversations.Message} - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Repo import Ecto.Query @@ -67,7 +67,7 @@ defmodule PhilomenaWeb.ConversationController do rendered = messages.entries - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) messages = %{messages | entries: Enum.zip(messages.entries, rendered)} diff --git a/lib/philomena_web/controllers/dnp_entry_controller.ex b/lib/philomena_web/controllers/dnp_entry_controller.ex index 8455e68d..c4428fed 100644 --- a/lib/philomena_web/controllers/dnp_entry_controller.ex +++ b/lib/philomena_web/controllers/dnp_entry_controller.ex @@ -2,7 +2,7 @@ defmodule PhilomenaWeb.DnpEntryController do use PhilomenaWeb, :controller alias Philomena.DnpEntries.DnpEntry - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.DnpEntries alias Philomena.Tags.Tag alias Philomena.ModNotes.ModNote @@ -43,7 +43,7 @@ defmodule PhilomenaWeb.DnpEntryController do bodies = dnp_entries |> Enum.map(&%{body: &1.conditions || "-"}) - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) dnp_entries = %{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)} @@ -60,7 +60,7 @@ defmodule PhilomenaWeb.DnpEntryController do dnp_entry = conn.assigns.dnp_entry [conditions, reason, instructions] = - Renderer.render_collection( + TextileRenderer.render_collection( [ %{body: dnp_entry.conditions || "-"}, %{body: dnp_entry.reason || "-"}, @@ -165,7 +165,7 @@ defmodule PhilomenaWeb.DnpEntryController do mod_notes = mod_notes - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) |> Enum.zip(mod_notes) assign(conn, :mod_notes, mod_notes) diff --git a/lib/philomena_web/controllers/image/comment_controller.ex b/lib/philomena_web/controllers/image/comment_controller.ex index 4fc55e4f..c35e56ea 100644 --- a/lib/philomena_web/controllers/image/comment_controller.ex +++ b/lib/philomena_web/controllers/image/comment_controller.ex @@ -2,7 +2,8 @@ defmodule PhilomenaWeb.Image.CommentController do use PhilomenaWeb, :controller alias PhilomenaWeb.CommentLoader - alias Philomena.{Images.Image, Comments.Comment, Textile.Renderer} + alias PhilomenaWeb.TextileRenderer + alias Philomena.{Images.Image, Comments.Comment} alias Philomena.UserStatistics alias Philomena.Comments alias Philomena.Images @@ -37,7 +38,7 @@ defmodule PhilomenaWeb.Image.CommentController do def index(conn, _params) do comments = CommentLoader.load_comments(conn, conn.assigns.image) - rendered = Renderer.render_collection(comments.entries, conn) + rendered = TextileRenderer.render_collection(comments.entries, conn) comments = %{comments | entries: Enum.zip(comments.entries, rendered)} @@ -45,7 +46,7 @@ defmodule PhilomenaWeb.Image.CommentController do end def show(conn, _params) do - rendered = Renderer.render_one(conn.assigns.comment, conn) + rendered = TextileRenderer.render_one(conn.assigns.comment, conn) render(conn, "show.html", layout: false, diff --git a/lib/philomena_web/controllers/image/description_controller.ex b/lib/philomena_web/controllers/image/description_controller.ex index da52c1de..e5dd6e90 100644 --- a/lib/philomena_web/controllers/image/description_controller.ex +++ b/lib/philomena_web/controllers/image/description_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do use PhilomenaWeb, :controller - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Images.Image alias Philomena.Images @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do {:ok, image} -> Images.reindex_image(image) - body = Renderer.render_one(%{body: image.description}, conn) + body = TextileRenderer.render_one(%{body: image.description}, conn) conn |> put_view(PhilomenaWeb.ImageView) diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index a710bdce..8df0c085 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -4,13 +4,13 @@ defmodule PhilomenaWeb.ImageController do alias PhilomenaWeb.ImageLoader alias PhilomenaWeb.CommentLoader alias PhilomenaWeb.NotificationCountPlug + alias PhilomenaWeb.TextileRenderer alias Philomena.{ Images, Images.Image, Comments.Comment, - Galleries.Gallery, - Textile.Renderer + Galleries.Gallery } # alias Philomena.Servers.ImageProcessor @@ -56,13 +56,13 @@ defmodule PhilomenaWeb.ImageController do comments = CommentLoader.load_comments(conn, image) - rendered = Renderer.render_collection(comments.entries, conn) + rendered = TextileRenderer.render_collection(comments.entries, conn) comments = %{comments | entries: Enum.zip(comments.entries, rendered)} description = %{body: image.description} - |> Renderer.render_one(conn) + |> TextileRenderer.render_one(conn) interactions = Interactions.user_interactions([image], conn.assigns.current_user) diff --git a/lib/philomena_web/controllers/post/preview_controller.ex b/lib/philomena_web/controllers/post/preview_controller.ex index 98d68968..00416436 100644 --- a/lib/philomena_web/controllers/post/preview_controller.ex +++ b/lib/philomena_web/controllers/post/preview_controller.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.Post.PreviewController do use PhilomenaWeb, :controller - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Posts.Post alias Philomena.Repo @@ -11,7 +11,7 @@ defmodule PhilomenaWeb.Post.PreviewController do anonymous = params["anonymous"] == true post = %Post{user: user, body: body, anonymous: anonymous} - rendered = Renderer.render_one(post, conn) + rendered = TextileRenderer.render_one(post, conn) render(conn, "create.html", layout: false, post: post, body: rendered) end diff --git a/lib/philomena_web/controllers/post_controller.ex b/lib/philomena_web/controllers/post_controller.ex index b613317d..79d8ee39 100644 --- a/lib/philomena_web/controllers/post_controller.ex +++ b/lib/philomena_web/controllers/post_controller.ex @@ -1,8 +1,9 @@ defmodule PhilomenaWeb.PostController do use PhilomenaWeb, :controller + alias PhilomenaWeb.TextileRenderer alias Philomena.Elasticsearch - alias Philomena.{Posts.Query, Posts.Post, Textile.Renderer} + alias Philomena.{Posts.Query, Posts.Post} import Ecto.Query def index(conn, params) do @@ -33,7 +34,7 @@ defmodule PhilomenaWeb.PostController do Post |> preload([:deleted_by, topic: :forum, user: [awards: :badge]]) ) - rendered = Renderer.render_collection(posts.entries, conn) + rendered = TextileRenderer.render_collection(posts.entries, conn) posts = %{posts | entries: Enum.zip(rendered, posts.entries)} diff --git a/lib/philomena_web/controllers/profile/commission_controller.ex b/lib/philomena_web/controllers/profile/commission_controller.ex index bdf7fe52..adac762d 100644 --- a/lib/philomena_web/controllers/profile/commission_controller.ex +++ b/lib/philomena_web/controllers/profile/commission_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.Profile.CommissionController do alias Philomena.Commissions.Commission alias Philomena.Commissions - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Users.User plug PhilomenaWeb.FilterBannedUsersPlug when action in [:new, :create, :edit, :update, :delete] @@ -33,15 +33,15 @@ defmodule PhilomenaWeb.Profile.CommissionController do item_descriptions = items |> Enum.map(&%{body: &1.description}) - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) item_add_ons = items |> Enum.map(&%{body: &1.add_ons}) - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) [information, contact, will_create, will_not_create] = - Renderer.render_collection( + TextileRenderer.render_collection( [ %{body: commission.information || ""}, %{body: commission.contact || ""}, diff --git a/lib/philomena_web/controllers/profile/detail_controller.ex b/lib/philomena_web/controllers/profile/detail_controller.ex index 40989f9f..ced52900 100644 --- a/lib/philomena_web/controllers/profile/detail_controller.ex +++ b/lib/philomena_web/controllers/profile/detail_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.Profile.DetailController do alias Philomena.UserNameChanges.UserNameChange alias Philomena.ModNotes.ModNote - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Polymorphic alias Philomena.Users.User alias Philomena.Repo @@ -30,7 +30,7 @@ defmodule PhilomenaWeb.Profile.DetailController do mod_notes = mod_notes - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) |> Enum.zip(mod_notes) name_changes = diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index 63c586d7..32f7bb66 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -3,7 +3,7 @@ defmodule PhilomenaWeb.ProfileController do alias PhilomenaWeb.ImageLoader alias Philomena.Elasticsearch - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.UserStatistics.UserStatistic alias Philomena.Users.User alias Philomena.Bans @@ -98,7 +98,7 @@ defmodule PhilomenaWeb.ProfileController do recent_comments = recent_comments - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) |> Enum.zip(recent_comments) recent_posts = @@ -122,9 +122,9 @@ defmodule PhilomenaWeb.ProfileController do ) |> Enum.filter(&Canada.Can.can?(current_user, :show, &1.topic)) - about_me = Renderer.render_one(%{body: user.description || ""}, conn) + about_me = TextileRenderer.render_one(%{body: user.description || ""}, conn) - scratchpad = Renderer.render_one(%{body: user.scratchpad || ""}, conn) + scratchpad = TextileRenderer.render_one(%{body: user.scratchpad || ""}, conn) commission_information = commission_info(user.commission, conn) @@ -199,7 +199,7 @@ defmodule PhilomenaWeb.ProfileController do defp map_fetch(map, field_name), do: Map.get(map, field_name) defp commission_info(%{information: info}, conn) when info not in [nil, ""], - do: Renderer.render_one(%{body: info}, conn) + do: TextileRenderer.render_one(%{body: info}, conn) defp commission_info(_commission, _conn), do: "" @@ -264,7 +264,7 @@ defmodule PhilomenaWeb.ProfileController do mod_notes = mod_notes - |> Renderer.render_collection(conn) + |> TextileRenderer.render_collection(conn) |> Enum.zip(mod_notes) assign(conn, :mod_notes, mod_notes) diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index 3de9c04e..11d6d34a 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -4,7 +4,7 @@ defmodule PhilomenaWeb.TagController do alias PhilomenaWeb.ImageLoader alias Philomena.Elasticsearch alias Philomena.{Tags, Tags.Tag} - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Interactions plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show] @@ -57,10 +57,10 @@ defmodule PhilomenaWeb.TagController do interactions = Interactions.user_interactions(images, user) - body = Renderer.render_one(%{body: tag.description || ""}, conn) + body = TextileRenderer.render_one(%{body: tag.description || ""}, conn) dnp_bodies = - Renderer.render_collection(Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), conn) + TextileRenderer.render_collection(Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), conn) dnp_entries = Enum.zip(dnp_bodies, tag.dnp_entries) diff --git a/lib/philomena_web/controllers/topic_controller.ex b/lib/philomena_web/controllers/topic_controller.ex index 1f86c474..8ba63c47 100644 --- a/lib/philomena_web/controllers/topic_controller.ex +++ b/lib/philomena_web/controllers/topic_controller.ex @@ -5,7 +5,7 @@ defmodule PhilomenaWeb.TopicController do alias Philomena.{Forums.Forum, Topics.Topic, Posts.Post, Polls.Poll, PollOptions.PollOption} alias Philomena.{Forums, Topics, Posts} alias Philomena.PollVotes - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Repo import Ecto.Query @@ -56,7 +56,7 @@ defmodule PhilomenaWeb.TopicController do |> preload([:deleted_by, :topic, topic: :forum, user: [awards: :badge]]) |> Repo.all() - rendered = Renderer.render_collection(posts, conn) + rendered = TextileRenderer.render_collection(posts, conn) posts = Enum.zip(posts, rendered) diff --git a/lib/philomena_web/image_loader.ex b/lib/philomena_web/image_loader.ex index c0bb26b8..78a3f04e 100644 --- a/lib/philomena_web/image_loader.ex +++ b/lib/philomena_web/image_loader.ex @@ -1,7 +1,7 @@ defmodule PhilomenaWeb.ImageLoader do alias Philomena.Elasticsearch alias Philomena.Images.{Image, Query} - alias Philomena.Textile.Renderer + alias PhilomenaWeb.TextileRenderer alias Philomena.Tags.Tag alias Philomena.Repo import Ecto.Query @@ -135,11 +135,11 @@ defmodule PhilomenaWeb.ImageLoader do defp render_bodies([tag], conn) do dnp_bodies = - Renderer.render_collection(Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), conn) + TextileRenderer.render_collection(Enum.map(tag.dnp_entries, &%{body: &1.conditions || ""}), conn) dnp_entries = Enum.zip(dnp_bodies, tag.dnp_entries) - description = Renderer.render_one(%{body: tag.description || ""}, conn) + description = TextileRenderer.render_one(%{body: tag.description || ""}, conn) [{tag, description, dnp_entries}] end diff --git a/lib/philomena/textile/renderer.ex b/lib/philomena_web/textile_renderer.ex similarity index 97% rename from lib/philomena/textile/renderer.ex rename to lib/philomena_web/textile_renderer.ex index c6fc1686..9b445f2b 100644 --- a/lib/philomena/textile/renderer.ex +++ b/lib/philomena_web/textile_renderer.ex @@ -1,5 +1,4 @@ -defmodule Philomena.Textile.Renderer do - # todo: belongs in PhilomenaWeb +defmodule PhilomenaWeb.TextileRenderer do alias Textile.Parser alias Philomena.Images.Image alias Philomena.Repo