NavigationTree.Agent
An agent represing a navigation tree. The agent holds transformed configuration state.
Provides convenience wrappers to generate Twitter/bootstrap-freindly userrole-aware HTML out of this state through NavigationTree.Helper and NavigationTree.Bootstrap.
Navigation tree nodes are to be configured as NavigationTree.Node structs.
Examples
Configure and start agent
iex> alias NavigationTree.Node, as: Node
nil
iex> NavigationTree.Agent.start_link %Node{
name: "Home",
url: "/",
children: [
%Node{ name: "Login", url: "/auth" },
%Node{
name: "Admin",
roles: ["admin"],
children: [
%Node{ name: "Users", roles: ["user_admin"] },
%Node{ name: "Roles" }
]
}
]
}
{:ok, #PID<0.120.0>}
get tree node by path hopping through tree
iex> NavigationTree.Agent.node_of ["Home", "Admin", "Users"]
%{children: [], controller: nil, name: "Users", roles: ["admin", "user_admin"], url: "/admin/users"}
generate bootstrap-style HTML for a user that has userroles ["admin"]
iex> NavigationTree.Agent.as_html ["admin"], :bootstrap
"""
<ul class="nav navbar-nav">
<li><a href="/auth">Login</a></li>
<li class="dropdown">
<a href="#">Admin</a>
<ul class="dropdown-menu">
<li><a href="/admin/roles">Roles</a></li>
</ul>
</li>
</ul>
"""
Summary
as_html(roles, atom2) | Return an HTML string suitable to fit in a navbar in a Twitter/Bootstrap environment |
get() | |
init_opts(root_node) | |
node_of(path) | Returns node at given path. Path must be a either |
path_of(url) | Returns node path for given url |
start_link(root_node) | |
stop() |
Functions
Return an HTML string suitable to fit in a navbar in a Twitter/Bootstrap environment.
- roles must be a list of user roles (strings)
- atom2 must be either
- :bootstrap (currently the only supported framework)
- a module implementing tree_to_html( tree, roles )
Returns node at given path. Path must be a either
- A list of node names traversing the stree starting with root node’s name
- An URL string. URL must be absolute e.g. “/admin/users”
Returns node path for given url