• Stars
    star
    2
  • Language
    Elixir
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A navigation tree representation with helpers to generate HTML out of it - depending of userroles

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 user

NavigationTree.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.

Basics

Add this project both to your dependecies and to your app list (including configuration). [..]

LICENSE

M.I.T.

More Repositories

1

elixir-pdf-generator

Create PDFs with wkhtmltopdf or puppeteer/chromium from Elixir.
Elixir
314
star
2

phoenix-skeleton

Skeleton WebApp based on Elixir/Phoenix that comes with sessions, authentications, userroles and a role-based navigation tree.
Elixir
36
star
3

plug-session-memcached

Store your plug sessions in memcached
Elixir
15
star
4

elixir-helper-random

Create random strings and numbers of arbitrary length in Elixir.
Elixir
11
star
5

elixir-pdf-server

A simple pdf-generating web service
Elixir
6
star
6

elixir-airtable-client

Client and caching proxy for airtable.com
Elixir
6
star
7

elixir-couchdb-client

A CouchDB client
Elixir
5
star
8

elixir-map-deeply

Traverse and map values of deeply nested data structures: Provides a `map_deeply/2` function for Maps and Lists and Keyword Lists.
Elixir
5
star
9

phoenix-liveview-todo-app

The famous TODO app example made with Phoenix LiveView
Elixir
3
star
10

komodo-elixir-udl

basic UDL file for the Elixir language. Includes built XPI extension for Komodo-Edit and Komodo-IDE
Python
2
star
11

elixir-genserver-demo

A demo of some basic Elixir GenServer implementation. Used to demo :observer for process inspection and tracing
Elixir
1
star
12

elixir-vista-client

A client for Vista Entertainment's VistaConnnect API
Elixir
1
star
13

elixir-vista-api-cache

aka. VistaStorage - keeping track of sessiosn, cinemas and films. Will take care of loading, expiring and via adjusted polling frequencies.
Elixir
1
star
14

elixir-qr-code-svg

Creates SVGs out of bytes generated by https://github.com/remiq/qr_code
Elixir
1
star
15

plug_authorization_roles

A plug and config framework that checks for user roles
Elixir
1
star