mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
untangle compile time dependencies in views
This commit is contained in:
parent
3ae6994de7
commit
eeacf9ee14
12 changed files with 60 additions and 19 deletions
|
@ -11,6 +11,9 @@ defmodule Philomena.Textile.Renderer do
|
||||||
image_transform: &Camo.Image.image_url/1
|
image_transform: &Camo.Image.image_url/1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Kill bogus compile time dependency on ImageView
|
||||||
|
@image_view Module.concat(["PhilomenaWeb.ImageView"])
|
||||||
|
|
||||||
def render_one(post, conn) do
|
def render_one(post, conn) do
|
||||||
hd(render_collection([post], conn))
|
hd(render_collection([post], conn))
|
||||||
end
|
end
|
||||||
|
@ -79,15 +82,15 @@ defmodule Philomena.Textile.Renderer do
|
||||||
match
|
match
|
||||||
|
|
||||||
[image, "p"] ->
|
[image, "p"] ->
|
||||||
Phoenix.View.render(PhilomenaWeb.ImageView, "_image_target.html", image: image, size: :medium, conn: conn)
|
Phoenix.View.render(@image_view, "_image_target.html", image: image, size: :medium, conn: conn)
|
||||||
|> safe_to_string()
|
|> safe_to_string()
|
||||||
|
|
||||||
[image, "t"] ->
|
[image, "t"] ->
|
||||||
Phoenix.View.render(PhilomenaWeb.ImageView, "_image_target.html", image: image, size: :small, conn: conn)
|
Phoenix.View.render(@image_view, "_image_target.html", image: image, size: :small, conn: conn)
|
||||||
|> safe_to_string()
|
|> safe_to_string()
|
||||||
|
|
||||||
[image, "s"] ->
|
[image, "s"] ->
|
||||||
Phoenix.View.render(PhilomenaWeb.ImageView, "_image_target.html", image: image, size: :thumb_small, conn: conn)
|
Phoenix.View.render(@image_view, "_image_target.html", image: image, size: :thumb_small, conn: conn)
|
||||||
|> safe_to_string()
|
|> safe_to_string()
|
||||||
|
|
||||||
[image] ->
|
[image] ->
|
||||||
|
|
|
@ -34,4 +34,4 @@ defmodule PhilomenaWeb.EnsureUserEnabledPlug do
|
||||||
|> Controller.redirect(to: Routes.pow_session_path(conn, :new))
|
|> Controller.redirect(to: Routes.pow_session_path(conn, :new))
|
||||||
end
|
end
|
||||||
defp maybe_halt(_any, conn), do: conn
|
defp maybe_halt(_any, conn), do: conn
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
defmodule PhilomenaWeb.Admin.AdvertView do
|
defmodule PhilomenaWeb.Admin.AdvertView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import PhilomenaWeb.AdvertView, only: [advert_image_url: 1]
|
alias PhilomenaWeb.AdvertView
|
||||||
|
|
||||||
|
defp advert_image_url(advert),
|
||||||
|
do: AdvertView.advert_image_url(advert)
|
||||||
|
|
||||||
def time_column_class(other_time) do
|
def time_column_class(other_time) do
|
||||||
now = DateTime.utc_now()
|
now = DateTime.utc_now()
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
defmodule PhilomenaWeb.Admin.BadgeView do
|
defmodule PhilomenaWeb.Admin.BadgeView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import PhilomenaWeb.ProfileView, only: [badge_image: 2]
|
alias PhilomenaWeb.ProfileView
|
||||||
|
|
||||||
|
defp badge_image(badge, options),
|
||||||
|
do: ProfileView.badge_image(badge, options)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
defmodule PhilomenaWeb.Admin.DnpEntryView do
|
defmodule PhilomenaWeb.Admin.DnpEntryView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import PhilomenaWeb.DnpEntryView, only: [pretty_state: 1]
|
alias PhilomenaWeb.DnpEntryView
|
||||||
|
|
||||||
|
defp pretty_state(dnp_entry),
|
||||||
|
do: DnpEntryView.pretty_state(dnp_entry)
|
||||||
|
|
||||||
def dnp_entry_row_class(%{aasm_state: state}) when state in ["closed", "listed"], do: "success"
|
def dnp_entry_row_class(%{aasm_state: state}) when state in ["closed", "listed"], do: "success"
|
||||||
def dnp_entry_row_class(%{aasm_state: state}) when state in ["claimed", "acknowledged"], do: "warning"
|
def dnp_entry_row_class(%{aasm_state: state}) when state in ["claimed", "acknowledged"], do: "warning"
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
defmodule PhilomenaWeb.Admin.FingerprintBanView do
|
defmodule PhilomenaWeb.Admin.FingerprintBanView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import PhilomenaWeb.ProfileView, only: [user_abbrv: 2]
|
alias PhilomenaWeb.ProfileView
|
||||||
|
|
||||||
|
defp user_abbrv(conn, user),
|
||||||
|
do: ProfileView.user_abbrv(conn, user)
|
||||||
|
|
||||||
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
|
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
|
||||||
now = DateTime.utc_now()
|
now = DateTime.utc_now()
|
||||||
|
|
|
@ -4,8 +4,23 @@ defmodule PhilomenaWeb.Admin.ReportView do
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
alias Philomena.Comments.Comment
|
alias Philomena.Comments.Comment
|
||||||
|
|
||||||
import PhilomenaWeb.ReportView, only: [link_to_reported_thing: 2, report_row_class: 1, pretty_state: 1]
|
alias PhilomenaWeb.ReportView
|
||||||
import PhilomenaWeb.ProfileView, only: [user_abbrv: 2, current?: 2]
|
alias PhilomenaWeb.ProfileView
|
||||||
|
|
||||||
|
defp link_to_reported_thing(conn, reportable),
|
||||||
|
do: ReportView.link_to_reported_thing(conn, reportable)
|
||||||
|
|
||||||
|
defp report_row_class(report),
|
||||||
|
do: ReportView.report_row_class(report)
|
||||||
|
|
||||||
|
defp pretty_state(report),
|
||||||
|
do: ReportView.pretty_state(report)
|
||||||
|
|
||||||
|
defp user_abbrv(conn, user),
|
||||||
|
do: ProfileView.user_abbrv(conn, user)
|
||||||
|
|
||||||
|
defp current?(current_user, user),
|
||||||
|
do: ProfileView.current?(current_user, user)
|
||||||
|
|
||||||
def truncate(<<string::binary-size(50), _rest::binary>>), do: string <> "..."
|
def truncate(<<string::binary-size(50), _rest::binary>>), do: string <> "..."
|
||||||
def truncate(string), do: string
|
def truncate(string), do: string
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
defmodule PhilomenaWeb.Admin.SubnetBanView do
|
defmodule PhilomenaWeb.Admin.SubnetBanView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import PhilomenaWeb.ProfileView, only: [user_abbrv: 2]
|
alias PhilomenaWeb.ProfileView
|
||||||
|
|
||||||
|
defp user_abbrv(conn, user),
|
||||||
|
do: ProfileView.user_abbrv(conn, user)
|
||||||
|
|
||||||
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
|
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
|
||||||
now = DateTime.utc_now()
|
now = DateTime.utc_now()
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
defmodule PhilomenaWeb.Admin.UserBanView do
|
defmodule PhilomenaWeb.Admin.UserBanView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import PhilomenaWeb.ProfileView, only: [user_abbrv: 2]
|
alias PhilomenaWeb.ProfileView
|
||||||
|
|
||||||
|
defp user_abbrv(conn, user),
|
||||||
|
do: ProfileView.user_abbrv(conn, user)
|
||||||
|
|
||||||
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
|
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
|
||||||
now = DateTime.utc_now()
|
now = DateTime.utc_now()
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
defmodule PhilomenaWeb.Admin.UserLinkView do
|
defmodule PhilomenaWeb.Admin.UserLinkView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import Philomena.Tags.Tag, only: [display_order: 1]
|
alias Philomena.Tags.Tag
|
||||||
|
|
||||||
|
defp display_order(tags),
|
||||||
|
do: Tag.display_order(tags)
|
||||||
|
|
||||||
def link_state_class(%{aasm_state: state}) when state in ["verified", "link_verified"], do: "success"
|
def link_state_class(%{aasm_state: state}) when state in ["verified", "link_verified"], do: "success"
|
||||||
def link_state_class(%{aasm_state: state}) when state in ["unverified", "rejected"], do: "danger"
|
def link_state_class(%{aasm_state: state}) when state in ["unverified", "rejected"], do: "danger"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
defmodule PhilomenaWeb.AppView do
|
defmodule PhilomenaWeb.AppView do
|
||||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
|
||||||
use Phoenix.HTML
|
use Phoenix.HTML
|
||||||
|
|
||||||
@time_strings %{
|
@time_strings %{
|
||||||
|
@ -127,8 +126,8 @@ defmodule PhilomenaWeb.AppView do
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_ip(_conn, nil), do: content_tag(:code, "null")
|
def link_to_ip(_conn, nil), do: content_tag(:code, "null")
|
||||||
def link_to_ip(conn, ip) do
|
def link_to_ip(_conn, ip) do
|
||||||
link(to: Routes.ip_profile_path(conn, :show, to_string(ip))) do
|
link(to: "/ip_profiles/#{ip}") do
|
||||||
[
|
[
|
||||||
content_tag(:i, "", class: "fas fa-network-wired"),
|
content_tag(:i, "", class: "fas fa-network-wired"),
|
||||||
" ",
|
" ",
|
||||||
|
@ -138,8 +137,8 @@ defmodule PhilomenaWeb.AppView do
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_to_fingerprint(_conn, nil), do: content_tag(:code, "null")
|
def link_to_fingerprint(_conn, nil), do: content_tag(:code, "null")
|
||||||
def link_to_fingerprint(conn, fp) do
|
def link_to_fingerprint(_conn, fp) do
|
||||||
link(to: Routes.fingerprint_profile_path(conn, :show, fp)) do
|
link(to: "/fingerprint_profiles/#{fp}") do
|
||||||
[
|
[
|
||||||
content_tag(:i, "", class: "fas fa-desktop"),
|
content_tag(:i, "", class: "fas fa-desktop"),
|
||||||
" ",
|
" ",
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
defmodule PhilomenaWeb.Tag.ImageView do
|
defmodule PhilomenaWeb.Tag.ImageView do
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
import PhilomenaWeb.TagView, only: [tag_image: 1]
|
alias PhilomenaWeb.TagView
|
||||||
|
|
||||||
|
defp tag_image(tag),
|
||||||
|
do: TagView.tag_image(tag)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue