-
Notifications
You must be signed in to change notification settings - Fork 92
/
rapid_navigation.dryml
108 lines (80 loc) · 4.02 KB
/
rapid_navigation.dryml
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!-- Support for navigation links, account navigation (log in, out etc.) and pagination navigation. -->
<!-- General purpose navigation bar. Renders a `<ul class="navigation">`. This tag is intended to be used in conunction with `<nav-item>`. The main feature of this pair of tags (over, say, just using a plain `<ul>` list), is that it's easy to have a 'current' CSS class added to the appropriate nav item (so you can highlight the page/section the user is)
The main navigation in the default hobo app is implemented with `<navigation>` but this tag is also appropriate for any sub-navigation.
### Attributes
- `current` - the textual content of the nav item that should have the 'current' CSS class added (see example)
### Example
The normal usage is to define your own navigation tag that calls `<navigation>`.
<def tag="sub-nav">
<navigation merge>
<nav-item>Red</nav-item>
<nav-item>Green</nav-item>
<nav-item>Blue</nav-item>
</navigation>
</def>
Then in your pages you can call the tag like this
- On the 'red' page: `<sub-nav current="red"/>`
- On the 'green' page: `<sub-nav current="green"/>`
- and so on.
-->
<def tag="navigation" attrs="current">
<ul class="navigation" merge-attrs>
<set-scoped current-navigation="¤t">
<do param="default"/>
</set-scoped>
</ul>
</def>
<!-- Renders a single item in a [`<navigation>`](/api_tag_defs/navigation).
`<nav-item>` is basically an [`<a>`](/api_tag_defs/a) tag wrapped in an `<li>` tag. The attributes for [`<a>`](/api_tag_defs/a) may all be used on this tag, and work the same way.
Example 1: explicit links. Note that we're using explicit routes for clarity. Named routes are better.
<navigation current="home">
<nav-item href="/">Home</nav-item>
<nav-item href="/logout">Logout</nav-item>
</navigation>
Example 2: navigation based on a collection of items. Each item will be transformed into a link as described in [`<a>`](/api_tag_defs/a).
<navigation with="&links">
<repeat>
<nav-item/>
</repeat>
</navigation>
-->
<def tag="nav-item" attrs="name">
<% body = parameters.default
body = h(this.to_s) if body.blank?
name ||= body.gsub(/<.*?>/, '').strip
-%>
<li class="#{'current' if (c = scope.current_navigation) && c.downcase == name.downcase}"
merge-attrs="&attributes - (attrs_for(:a)+['target'])">
<a merge-attrs="&attributes & (attrs_for(:a)+['target'])"><%= body %></a>
</li>
</def>
<!-- Account Navigation (log in / out / signup)
When logged in, this renders:
- "Logged in as ..."
- Link to account page
- Log out link
When not logged in, renders:
- Log in link
- Sign up link
This is a simple tag - just look at the source if you need to know more detail.
-->
<def tag="account-nav">
<do with="¤t_user">
<ul class="navigation account-nav" param>
<li if="&Rails.env.development?" param="dev-user-changer"><dev-user-changer/></li>
<if test="&logged_in?">
<li class='nav-item' param="logged-in-as"><a to="¤t_user"><t key="hobo.actions.logged_in_as" name="&name">Logged in as <name/></t></a></li>
<li class='nav-item' param="account"><a action="account"><t key="hobo.actions.account">Account</t></a></li>
<li class='nav-item' param="log-out"><a href="&logout_url"><t key="hobo.actions.logout">Log out</t></a></li>
</if>
<else>
<li class='nav-item' param="log-in"><a href="&login_url"><t key="hobo.actions.login">Log in</t></a></li>
<li if="&signup_url" class="nav-item" param="sign-up"><a href="&signup_url"><t key="hobo.actions.signup">Sign up</t></a></li>
</else>
</ul>
</do>
</def>
<!--- A simple wrapper around the `will_paginate` helper. All options to `will_paginate` are available as attributes -->
<def tag="page-nav">
<%= will_paginate this, attributes.symbolize_keys.reverse_merge(:inner_window => 2, :previous_label => translate("hobo.actions.previous", :default=>"« Prev"), :next_label =>translate("hobo.actions.next", :default=>"Next »")) %>
</def>