-
Notifications
You must be signed in to change notification settings - Fork 30
/
layout_view.ex
39 lines (35 loc) · 1017 Bytes
/
layout_view.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
defmodule VerkWeb.LayoutView do
use VerkWeb.Web, :view
def menu_item(conn, path, item) do
class = if path == conn.request_path, do: "active", else: ""
content_tag(:li, link(item, to: path), class: class)
end
# From: https://blog.diacode.com/page-specific-javascript-in-phoenix-framework-pt-1
@doc """
Generates name for the JavaScript view we want to use
in this combination of view/template.
"""
def js_view_name(conn) do
[view_name(conn), template_name(conn)]
|> Enum.reverse()
|> Enum.map(&String.capitalize/1)
|> Enum.reverse()
|> Enum.join("")
end
# Takes the resource name of the view module and removes the
# the ending *_view* string.
defp view_name(conn) do
conn
|> view_module
|> Phoenix.Naming.resource_name()
|> String.replace("_view", "")
end
# Removes the extion from the template and reutrns
# just the name.
defp template_name(conn) do
conn
|> view_template
|> String.split(".")
|> Enum.at(0)
end
end