1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
defmodule WaevWeb.ExportsView do
use WaevWeb, :view
def party_peek(assigns, party) do
~E"""
<div class="party-peek">
<figure>
<%= party_avatar(assigns, party, :big) %>
<figcaption><%= party.name %></figcaption>
</figure>
</div>
"""
end
def party_avatar(assigns, party, size) do
modifier =
case size do
:tiny -> "avatar--tiny"
:big -> "avatar--big"
end
~E"""
<img class="avatar <%= modifier %>" src="<%= Routes.exports_path(@conn, :get_avatar, @id, party.name) %>" />
"""
end
def highlight_urls(nil), do: ""
def highlight_urls(text) do
url_re =
~r/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/
url_re
|> Regex.scan(text)
|> Enum.reduce(text, fn [url | _], t ->
t
|> String.replace(url, "<a target=\"_blank\" href=#{url}>#{url}</a>", global: false)
|> raw()
end)
end
def nl_to_br(text) do
String.replace(text, "\n", "<br />")
|> raw()
end
def pagination_bar(assigns, page, size) do
prev = if page == 0, do: 0, else: page - 1
# TODO max
next = page + 1
~E"""
<div>
<a href="<%= Routes.exports_path(@conn, :show, @id, page: prev, size: size) %>">Left</a>
<a href="<%= Routes.exports_path(@conn, :show, @id, page: next, size: size) %>">Right</a>
</div>
"""
end
end
|