Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gutschilla/elixir-navigation-tree
A navigation tree representation with helpers to generate HTML out of it - depending of userroles
https://github.com/gutschilla/elixir-navigation-tree
Last synced: 4 days ago
JSON representation
A navigation tree representation with helpers to generate HTML out of it - depending of userroles
- Host: GitHub
- URL: https://github.com/gutschilla/elixir-navigation-tree
- Owner: gutschilla
- License: mit
- Created: 2015-07-16T11:03:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T16:24:55.000Z (about 9 years ago)
- Last Synced: 2024-10-02T23:47:53.599Z (about 1 month ago)
- Language: Elixir
- Size: 582 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - A navigation tree representation with helpers to generate HTML out of it. (Algorithms and Data structures)
- fucking-awesome-elixir - navigation_tree - A navigation tree representation with helpers to generate HTML out of it. (Algorithms and Data structures)
- awesome-elixir - navigation_tree - A navigation tree representation with helpers to generate HTML out of it. (Algorithms and Data structures)
README
# 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.
## Terminology
__node__: A configuration struct looking like this:
```
%NavigationTree.Node{
name: string, # the node's name, like "About Us"
url: nil or string, # will be set on startup, but may be overridden
controller: nil or string, # would be set to about-us, but may be overridden
children:, nil or list of child nodes
roles: nil or list of strings # role names a user must have to see this navigation item
}
```__path__: A list of node names, e.g. ["Home", "Admin"]
__url__: Every node gets a url on start_link setup constructed out of its ancestors' url
concatenated with "/" whereas is either a safe_string version of
the node's name or the specified controller namde in this node's config# Basic usage
- create a config module or just use NavigationTree.Example
- Startup Agent possibly in your application setup
- create you HTML generator or use the shipped NavigationTree.Bootstrap module
- enjoy!```
# startup
NavigationTree.Agent.start_link NavigationTree.Example.config# getters
NavigationTree.Agent.get.tree
NavigationTree.Agent.get.paths
NavigationTree.Agent.get.root_node (initoal config)# methods
NavigationTree.Agent.node_of ["Home","Admin"]
# same as
NavigationTree.Agent.node_of "/admin"
# the inverse of node_of is path_of
NavigationTree.Agent.path_of "/admin" # returns ["Home","Admin"]# parent node
NavigationTree.Agent.parent of ["Home","Admin", "Users"]# returns next/previous node after "Users" in "Amind"
NavigationTree.Agent.next_sibling ["Home","Admin", "Users"]
NavigationTree.Agent.previous_sibling ["Home","Admin", "Users"]
# HTML
NavigationTree.Agent.as_html [], :bootstrap
# returns HTML for unauthenticated userNavigationTree.Agent.as_html ["admin", "customer"], :bootstrap
# returns HTML for user with admin and customer role# or your tree_to_html implementation:
MyApp.NavigationTree.Sidenav.tree_to_html NavigationTree.Agent.get.tree```
# Documentation
[Can be found here.](http://hexdocs.pm/navigation_tree/0.4.0/NavigationTree.Agent.html)# Basics
Add this project both to your dependecies and to your app list (including configuration). [..]
# LICENSE
M.I.T.