-
Notifications
You must be signed in to change notification settings - Fork 28
/
templates.ex
67 lines (55 loc) · 1.57 KB
/
templates.ex
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
60
61
62
63
64
65
66
67
defmodule FunWithFlags.UI.Templates do
@moduledoc false
require EEx
alias FunWithFlags.UI.Utils
alias FunWithFlags.Flag
@templates [
_head: "_head",
index: "index",
details: "details",
new: "new",
not_found: "not_found",
_boolean_row: "rows/_boolean",
_actor_row: "rows/_actor",
_group_row: "rows/_group",
_percentage_row: "rows/_percentage",
_new_actor_row: "rows/_new_actor",
_new_group_row: "rows/_new_group",
_percentage_form_row: "rows/_percentage_form",
]
for {fn_name, file_name} <- @templates do
EEx.function_from_file :def, fn_name, Path.expand("./templates/#{file_name}.html.eex", __DIR__), [:assigns]
end
def html_smart_status_for(flag) do
case Utils.get_flag_status(flag) do
:fully_open ->
~s(<span class="text-success">Enabled</span>)
:half_open ->
~s(<span class="text-warning">Enabled</span>)
:closed ->
~s(<span class="text-danger">Disabled</span>)
end
end
def html_status_for({:ok, bool}) do
html_status_for(bool)
end
def html_status_for(:missing) do
~s{<span class="badge badge-default">Disabled (missing)</span>}
end
def html_status_for(bool) when is_boolean(bool) do
if bool do
~s(<span class="badge badge-success">Enabled</span>)
else
~s(<span class="badge badge-danger">Disabled</span>)
end
end
def html_gate_list(%Flag{gates: gates}) do
gates
|> Enum.map(&(&1.type))
|> Enum.uniq()
|> Enum.join(", ")
end
def path(conn, path) do
Path.join(conn.assigns[:namespace], path)
end
end