# 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 "/<controller>" whereas <controller> 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.](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.
没有合适的资源?快使用搜索试试~ 我知道了~
elixir-navigation-tree:带有帮助程序的导航树表示形式,用于从中生成HTML-取决于用户角色-源码
共15个文件
ex:6个
exs:4个
exs~:1个
需积分: 5 0 下载量 67 浏览量
2021-05-11
00:07:50
上传
评论
收藏 12KB ZIP 举报
温馨提示
NavigationTree.Agent 代理代表导航树。 代理保持转换后的配置状态。 提供方便的包装,以便通过NavigationTree.Helper和NavigationTree.Bootstrap在此状态之外生成Twitter /引导友好的用户角色HTML。 导航树节点将配置为NavigationTree.Node结构。 术语 node :如下所示的配置结构: %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
资源推荐
资源详情
资源评论
收起资源包目录
elixir-navigation-tree-master.zip (15个子文件)
elixir-navigation-tree-master
.gitignore 53B
README.md 2KB
test
test_helper.exs 15B
navigation_tree_test.exs 2KB
LICENSE 1KB
config
config.exs 1KB
mix.exs~ 682B
mix.lock 79B
lib
navigation_tree.ex 32B
navigation_tree
agent.ex 5KB
example.ex 522B
node.ex 141B
bootstrap.ex 3KB
helper.ex 5KB
mix.exs 1KB
共 15 条
- 1
资源评论
温暖如故
- 粉丝: 22
- 资源: 4642
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功