Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 145 lines (108 sloc) 3.892 kB
cd4298e @danielvlopes Initial commit to menu_builder.
authored
1 = menu_builder
2
7cac374 @danielvlopes refactoring
authored
3 With this gem/plugin you get a helper to define menus and also can control the current item of menu
4 in controller. Easy like always should be!
5
6 == Instalation
7
5d7e5bb @danielvlopes Rails 3 compatible
authored
8 Rail2
7cac374 @danielvlopes refactoring
authored
9
5d7e5bb @danielvlopes Rails 3 compatible
authored
10 gem.config "menu_builder", :version => '0.2.1'
11
12 Rails3
7cac374 @danielvlopes refactoring
authored
13
76fbc4b @danielvlopes improve rakefile and fix tests after bundler migration
authored
14 gem "menu_builder", '>=0.4.1'
7cac374 @danielvlopes refactoring
authored
15
812fcaf @danielvlopes changes in README
authored
16 == Usage
7cac374 @danielvlopes refactoring
authored
17
18 Just install the plugin and see the example below:
19
812fcaf @danielvlopes changes in README
authored
20 == Example
7cac374 @danielvlopes refactoring
authored
21
22 === Controller
23
24 class DashboardController < ApplicationController
3ba8afd @danielvlopes fix readme
authored
25 menu_item :mydashboard
7cac374 @danielvlopes refactoring
authored
26 ...
27 end
28
e3f328f @danielvlopes Changes in readme
authored
29 You can also change to menu item in action level instead of class level:
30
31 class DashboardController < ApplicationController
32 menu_item :mydashboard
33
34 def prices
35 menu_item :prices
36 ...
37 end
38 end
39
7cac374 @danielvlopes refactoring
authored
40 === View
41
42 ==== ERB code
43
5d7e5bb @danielvlopes Rails 3 compatible
authored
44 <%= menu(:id=>"mainMenu", :class=>"menu") do |m| %>
3a4b422 @danielvlopes add a tests and rename everything to menu instead of tab
authored
45 <%= m.account 'Account', account_path, :style => 'float: right' %>
46 <%= m.users 'Users', users_path, :style => 'float: right' %>
47 <%= m.mydashboard 'Dashboard', '/' %>
48 <%= m.projects 'Projects', projects_path %>
7cac374 @danielvlopes refactoring
authored
49 <% end %>
50
51 ==== HTML Result
52
53 <ul id="mainMenu" class="menu">
54 <li><a href="/accounts">Account</a></li>
55 <li><a href="/users">Users</a></li>
56 <li><a href="/" class="current">Dashboard</a></li>
57 <li><a href="/projects">Projects</a></li>
58 </ul>
59
60 ==== Blocks for content
61
62 Also is possible to pass blocks instead of simple strings for content.
3ba8afd @danielvlopes fix readme
authored
63 In this way you can create menu item with icons. Like below:
7cac374 @danielvlopes refactoring
authored
64
5d7e5bb @danielvlopes Rails 3 compatible
authored
65 <%= menu do |m| %>
3a4b422 @danielvlopes add a tests and rename everything to menu instead of tab
authored
66 <% m.account account_path do %>
67 <%= image_tag "icon.jpg" /> Accounts
7cac374 @danielvlopes refactoring
authored
68 <% end %>
3a4b422 @danielvlopes add a tests and rename everything to menu instead of tab
authored
69 <%= m.users "Users", users_path %>
70 <%= m.posts "Posts", posts_path %>
7cac374 @danielvlopes refactoring
authored
71 <% end %>
72
73 == CSS and HTML
74
3ba8afd @danielvlopes fix readme
authored
75 This plugin don't came with any kind of asset like image or css.
76 The layout of menu depends of your css. You can use any kind of CSS technique you want,
77 like below:
7cac374 @danielvlopes refactoring
authored
78
79 <html>
80 <head>
81 <style type="text/css" charset="utf-8">
82 #header ul { font-family:Tahoma; position: absolute; margin:0; list-style:none; }
83 #header li { display:inline; margin:0; padding:0; }
84
85 #header a {
86 float:left;
87 background: url(corner_left.jpg) no-repeat left top;
88 margin:0;
89 padding:0 0 0 4px;
90 text-decoration:none;
91 }
92 #header a span {
93 float:left;
94 display:block;
95 background: url(corner_right.jpg) no-repeat right top;
96 padding:4px 14px 4px 6px;
97 color:#FFF;
98 }
99
100 #header a:hover span { color:#FFF; }
101 #header a:hover { background-position:0% -43px; }
102 #header a:hover span { background-position:100% -43px; }
103 #header #current a { background-position:0% -43px; }
104 #header #current a span { background-position:100% -43px; }
105 </style>
106 </head>
107
108 <body>
109 <div id="header">
110 <ul>
111 <li><a href="#"><span>Home</span></a></li>
112 <li><a href="#"><span>Quem Somos</span></a></li>
113 <li><a href="#"><span>Portif&oacute;lio</span></a></li>
114 <li><a href="#"><span>Contato</span></a></li>
115 </ul>
116 </div>
117 </body>
118 </html>
119
3ba8afd @danielvlopes fix readme
authored
120 You can read a full tutorial and see a working demo of above in this
121 {link}[http://www.google.com/translate?langpair=pt|en&u=http://blog.areacriacoes.com.br//2009/1/23/bordas-arredondas-para-menus-em-abas]
7cac374 @danielvlopes refactoring
authored
122
812fcaf @danielvlopes changes in README
authored
123 == Author
7cac374 @danielvlopes refactoring
authored
124
125 Authors:: Daniel Lopes
126 Blog:: {http://blog.areacriacoes.com.br}[http://blog.areacriacoes.com.br]
127 Github:: {http://github.com/danielvlopes}[http://github.com/danielvlopes]
128 Twitter:: {danielvlopes}[http://blog.areacriacoes.com.br]
cd4298e @danielvlopes Initial commit to menu_builder.
authored
129
130 == Note on Patches/Pull Requests
131
132 * Fork the project.
133 * Make your feature addition or bug fix.
134 * Add tests for it. This is important so I don't break it in a
135 future version unintentionally.
136 * Commit, do not mess with rakefile, version, or history.
3ba8afd @danielvlopes fix readme
authored
137 * Send me a pull request :)
138
139 == License
140
141 MenuBuilder is released under the MIT License.
cd4298e @danielvlopes Initial commit to menu_builder.
authored
142
143 == Copyright
144
7cac374 @danielvlopes refactoring
authored
145 Copyright (c) 2010 Daniel Lopes. See LICENSE for details.
Something went wrong with that request. Please try again.