cssmenu 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +44 -3
- data/VERSION +1 -1
- data/cssmenu.gemspec +56 -0
- data/lib/cssmenu.rb +253 -0
- data/lib/cssmenu/engine.rb +7 -0
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -1,9 +1,50 @@
|
|
1
|
-
=
|
1
|
+
= Css Menu System
|
2
2
|
|
3
|
-
|
3
|
+
This set of functions makes adding a CSS configured menu as simple as
|
4
|
+
possible. Because it uses CSS for all formatting, it will work even if
|
5
|
+
javascript is turned off. If there is no styling, it will degrade
|
6
|
+
gracefully to a simple unordered list. That means it will work even with
|
7
|
+
a text based browser.
|
8
|
+
|
9
|
+
=== A note about images in the menus
|
10
|
+
|
11
|
+
This will search the /public/images and /public/images/icons directories for
|
12
|
+
image files of type .png, .gif, and .jpg, so any image that is of one of those
|
13
|
+
types and located in those directories will be found automatically. You do not
|
14
|
+
need to supply any more than the file base name. If you want to use a file that
|
15
|
+
does not meet those assumptions, you may still supply the full file
|
16
|
+
specification.
|
17
|
+
|
18
|
+
=== Typical Example:
|
19
|
+
|
20
|
+
<%= menubar do -%>
|
21
|
+
<%= menu_item('Back to Home', 'house', root_path()) %>
|
22
|
+
<%= menu_item('New Registration', 'user_add', new_registration_path) %>
|
23
|
+
<%- end -%>
|
24
|
+
|
25
|
+
=== Extended Example:
|
26
|
+
|
27
|
+
<%= menubar do -%>
|
28
|
+
<%= menu_item('Back to Home', 'house', root_path()) %>
|
29
|
+
<%= sub_menu('Tagged Actions', 'tag') do -%>
|
30
|
+
<%= menu_item('Send Mail', 'email', nil, nil, :onclick => js_submit('email')) %>
|
31
|
+
<%= menu_item('Delete', 'delete', nil, nil, {:onclick => js_submit('delete', :confirm => "Are you sure you want to delete the tagged registrations?"}) ) %>
|
32
|
+
<%- end -%>
|
33
|
+
<%= sub_menu('Tools', 'cog') do -%>
|
34
|
+
<%= menu_item('Export as CSV', 'report_disk', url_for(:controller=>:registrations, :action=>:index, :format=>:csv)) %>
|
35
|
+
<%= menu_item('Manage Statuses', 'application_view_list', statuses_path) %>
|
36
|
+
<%= menu_item('Manage Documents', 'page_copy', documents_path) %>
|
37
|
+
<%= sub_menu('Sub Item 2', 'add') do -%>
|
38
|
+
<%= menu_item('Sub Sub Item 1', 'add', '#') %>
|
39
|
+
<%= menu_item('Sub Sub Item 2', 'add', '#') %>
|
40
|
+
<%- end -%>
|
41
|
+
<%= menu_item('Sub Item 4', 'add') %>
|
42
|
+
<%- end -%>
|
43
|
+
<%= menu_item('New Registration', 'user_add', new_registration_path) %>
|
44
|
+
<%- end -%>
|
4
45
|
|
5
46
|
== Note on Patches/Pull Requests
|
6
|
-
|
47
|
+
|
7
48
|
* Fork the project.
|
8
49
|
* Make your feature addition or bug fix.
|
9
50
|
* Add tests for it. This is important so I don't break it in a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.0
|
data/cssmenu.gemspec
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{cssmenu}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["wmerrell"]
|
12
|
+
s.date = %q{2010-11-12}
|
13
|
+
s.description = %q{This is a set of functions to simplify management of a CSS based menu system.}
|
14
|
+
s.email = %q{will@morelandsolutions.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"cssmenu-0.1.0.gem",
|
27
|
+
"cssmenu.gemspec",
|
28
|
+
"lib/cssmenu.rb",
|
29
|
+
"lib/cssmenu/engine.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_cssmenu.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/wmerrell/cssmenu}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{A CSS based menu system for Rails pages.}
|
38
|
+
s.test_files = [
|
39
|
+
"test/test_cssmenu.rb",
|
40
|
+
"test/helper.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
data/lib/cssmenu.rb
CHANGED
@@ -0,0 +1,253 @@
|
|
1
|
+
require 'cssmenu/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
2
|
+
|
3
|
+
# == Css Menu System
|
4
|
+
#
|
5
|
+
# This set of functions makes adding a CSS configured menu as simple as
|
6
|
+
# possible. Because it uses CSS for all formatting, it will work even if
|
7
|
+
# javascript is turned off. If there is no styling, it will degrade
|
8
|
+
# gracefully to a simple unordered list.
|
9
|
+
#
|
10
|
+
# === Typical Example:
|
11
|
+
#
|
12
|
+
# <%= menubar do -%>
|
13
|
+
# <%= menu_item('Back to Home', 'house', root_path()) %>
|
14
|
+
# <%= menu_item('New Registration', 'user_add', new_registration_path) %>
|
15
|
+
# <%- end -%>
|
16
|
+
#
|
17
|
+
# === Extended Example:
|
18
|
+
#
|
19
|
+
# <%= menubar do -%>
|
20
|
+
# <%= menu_item('Back to Home', 'house', root_path()) %>
|
21
|
+
# <%= sub_menu('Tagged Actions', 'tag') do -%>
|
22
|
+
# <%= menu_item('Send Mail', 'email', nil, nil, :onclick => js_submit('email')) %>
|
23
|
+
# <%= menu_item('Delete', 'delete', nil, nil, {:onclick => js_submit('delete', :confirm => "Are you sure you want to delete the tagged registrations?"}) ) %>
|
24
|
+
# <%- end -%>
|
25
|
+
# <%= sub_menu('Tools', 'cog') do -%>
|
26
|
+
# <%= menu_item('Export as CSV', 'report_disk', url_for(:controller=>:registrations, :action=>:index, :format=>:csv)) %>
|
27
|
+
# <%= menu_item('Manage Statuses', 'application_view_list', statuses_path) %>
|
28
|
+
# <%= menu_item('Manage Documents', 'page_copy', documents_path) %>
|
29
|
+
# <%= sub_menu('Sub Item 2', 'add') do -%>
|
30
|
+
# <%= menu_item('Sub Sub Item 1', 'add', '#') %>
|
31
|
+
# <%= menu_item('Sub Sub Item 2', 'add', '#') %>
|
32
|
+
# <%- end -%>
|
33
|
+
# <%= menu_item('Sub Item 4', 'add') %>
|
34
|
+
# <%- end -%>
|
35
|
+
# <%= menu_item('New Registration', 'user_add', new_registration_path) %>
|
36
|
+
# <%- end -%>
|
37
|
+
#
|
38
|
+
module CssMenu
|
39
|
+
|
40
|
+
# Creates a menu bar
|
41
|
+
#
|
42
|
+
# This function creates a menu bar by creating an unordered list with a
|
43
|
+
# class of "cssMenu". The menu items will be li items within the list.
|
44
|
+
# It is expected that the "cssMenu" class will be styled to resemble a
|
45
|
+
# horizontal bar that will contain the item buttons.
|
46
|
+
#
|
47
|
+
# *Parameters*
|
48
|
+
#
|
49
|
+
# *permission* If the permission argument is supplied, it is expected to
|
50
|
+
# evaluate to true or false. If permissions is true or nil the menu is
|
51
|
+
# displayed. If it is false, the menu is not displayed.
|
52
|
+
#
|
53
|
+
# *block* This function expects a block consisting of the menu items to
|
54
|
+
# display. If no block is supplied, then no output is returned.
|
55
|
+
#
|
56
|
+
# === Usage:
|
57
|
+
# <%= menubar(permission) do -%>
|
58
|
+
# <%- end -%>
|
59
|
+
#
|
60
|
+
def menubar(permission=nil, &block)
|
61
|
+
if block_given?
|
62
|
+
content = capture(&block)
|
63
|
+
if permission.nil? || permission
|
64
|
+
raw("\n <!-- cssMenu -->\n <ul class=\"cssMenu\">\n" + content + " </ul>\n")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Creates a menu item
|
70
|
+
#
|
71
|
+
# This function creates a menu item by creating an +li+ element, with a
|
72
|
+
# link element inside it. It is assumed that this will be used inside
|
73
|
+
# an unordered list with a class of "cssMenu" created by menubar. It is
|
74
|
+
# expected that the +li+ element, and the link within it, will be
|
75
|
+
# formatted with css to resemble a button.
|
76
|
+
#
|
77
|
+
# *Parameters*
|
78
|
+
#
|
79
|
+
# *text* is the text that will be used in the link. It may be blank.
|
80
|
+
#
|
81
|
+
# *image* is the image that will be used in the link. It may be blank.
|
82
|
+
# If an image name is supplied, it will create the link with an embedded
|
83
|
+
# image along with text.
|
84
|
+
#
|
85
|
+
# *url* is the url that will be used in the link. It takes the same
|
86
|
+
# arguments as url_for.
|
87
|
+
#
|
88
|
+
# *permission* If the permission argument is supplied, it is expected to
|
89
|
+
# evaluate to true or false. If permissions is true or nil the item is
|
90
|
+
# displayed. If it is false, the item is not displayed.
|
91
|
+
#
|
92
|
+
# *html_options* are any options that will be used in the link. It may be
|
93
|
+
# blank and takes the same arguments as +html_options+ in the
|
94
|
+
# +link_to+ command.
|
95
|
+
#
|
96
|
+
# === Usage:
|
97
|
+
# <%= menubar do -%>
|
98
|
+
# <%= menu_item('Back to Home', 'house', root_path()) %>
|
99
|
+
# <%- end -%>
|
100
|
+
#
|
101
|
+
def menu_item(text='', image='', url='', permission=nil, html_options = {})
|
102
|
+
text = text.blank? ? "" : text
|
103
|
+
image = image.blank? ? "" : image_tag(cssmenu_clean_imagefile_name(image), :alt=>'')
|
104
|
+
url = url.blank? ? "#" : url
|
105
|
+
html_options = html_options.stringify_keys
|
106
|
+
if permission.nil? || permission
|
107
|
+
raw("<li>" + link_to( image + text, url, html_options ) + "</li>")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Creates a submenu
|
112
|
+
#
|
113
|
+
# This function creates a submenu item by creating an unordered list
|
114
|
+
# inside a li element. It is expected that an unordered list within a
|
115
|
+
# +cssMenu+ will be formatted with css to resemble a drop down box.
|
116
|
+
#
|
117
|
+
# *Parameters*
|
118
|
+
#
|
119
|
+
# *text* is the text that will be used in the link. It may be blank.
|
120
|
+
#
|
121
|
+
# *image* is the image that will be used in the link. It may be blank.
|
122
|
+
# If an image name is supplied, it will create the link with an embedded
|
123
|
+
# image along with text.
|
124
|
+
#
|
125
|
+
# *url* is the url that will be used in the link. It takes the same
|
126
|
+
# arguments as url_for. This will usually be blank.
|
127
|
+
#
|
128
|
+
# *permission* If the permission argument is supplied, it is expected to
|
129
|
+
# evaluate to true or false. If permissions is true or nil the item and
|
130
|
+
# the submenu will be displayed. If it is false, then neither the item nor
|
131
|
+
# the submenu is displayed.
|
132
|
+
#
|
133
|
+
# *html_options* are any options that will be used in the link. It may be
|
134
|
+
# blank and takes the same arguments as +html_options+ in the
|
135
|
+
# +link_to+ command. This will usually be blank.
|
136
|
+
#
|
137
|
+
# *block* This function expects a block consisting of the menu items to
|
138
|
+
# display. If no block is supplied, then no output is returned.
|
139
|
+
#
|
140
|
+
# === Usage:
|
141
|
+
# <%= menubar do -%>
|
142
|
+
# <%= sub_menu('Sub Item 2', 'add') do -%>
|
143
|
+
# <%= menu_item('Sub Sub Item 1', 'add', item1_path) %>
|
144
|
+
# <%= menu_item('Sub Sub Item 2', 'add', item2_path) %>
|
145
|
+
# <%- end -%>
|
146
|
+
# <%- end -%>
|
147
|
+
#
|
148
|
+
def sub_menu(text='', image='', url='', permission=nil, html_options = {}, &block)
|
149
|
+
if block_given?
|
150
|
+
content = capture(&block)
|
151
|
+
text = text.blank? ? "" : text
|
152
|
+
image = image.blank? ? "" : image_tag(cssmenu_clean_imagefile_name(image), :alt=>'')
|
153
|
+
url = url.blank? ? "#" : url
|
154
|
+
html_options = html_options.stringify_keys
|
155
|
+
if permission.nil? || permission
|
156
|
+
raw(" <li>" + link_to( "<span>" + image + text + "</span>", url, html_options ) + "\n <ul>\n" + content + " </ul></li>\n")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Makes a menu item into a submit button.
|
162
|
+
#
|
163
|
+
# This function is a convienience function to aid in using menu items
|
164
|
+
# inside a form. It adds javascript to the menu item to turn it into a
|
165
|
+
# submit button.
|
166
|
+
#
|
167
|
+
# The intent is to use menu items to manipulate data sets within a form.
|
168
|
+
# Typically you would display a dataset with checkboxes and use the menu
|
169
|
+
# items to issue commands against the checked data items.
|
170
|
+
#
|
171
|
+
# *Parameters*
|
172
|
+
#
|
173
|
+
# *command* is the command that will be submitted.
|
174
|
+
#
|
175
|
+
# *options* is hash of options. The following options are supported.
|
176
|
+
#
|
177
|
+
# _form_name_ The +name+ of the form. Defaults to +taglist+.
|
178
|
+
#
|
179
|
+
# _tag_name_ The name of the form's submit tag. Defauts to +commit+.
|
180
|
+
#
|
181
|
+
# _confirm_ If present, a confirm dialog will be generated using this text.
|
182
|
+
#
|
183
|
+
# === Usage:
|
184
|
+
# <%= form_tag('/posts')do -%>
|
185
|
+
# <%= menubar do -%>
|
186
|
+
# <%= sub_menu('Tagged Actions', 'tag') do -%>
|
187
|
+
# <%= menu_item('Touch', 'finger', nil, nil, :onclick => js_submit('touch')) %>
|
188
|
+
# <%= menu_item('Delete', 'delete', nil, nil, {:onclick => js_submit('delete', :confirm => "Are you sure you want to delete the tagged registrations?"}) ) %>
|
189
|
+
# <%- end -%>
|
190
|
+
# <%- end -%>
|
191
|
+
# <div><%= check_box_tag 'post_1' -%>Post 1</div>
|
192
|
+
# <div><%= check_box_tag 'post_2' -%>Post 2</div>
|
193
|
+
# <div><%= check_box_tag 'post_3' -%>Post 3</div>
|
194
|
+
# <div><%= submit_tag 'Save' -%></div>
|
195
|
+
# <%- end -%>
|
196
|
+
#
|
197
|
+
def js_submit(command='', options={})
|
198
|
+
options.to_options!
|
199
|
+
form_name = options.delete(:form_name) || 'taglist'
|
200
|
+
tag_name = options.delete(:tag_name) || 'commit'
|
201
|
+
submit_str = "document.#{form_name}['#{tag_name}'].value='#{command}'; document.#{form_name}.submit(); return false;"
|
202
|
+
if confirm_str = options.delete(:confirm)
|
203
|
+
output = "if (confirm('#{confirm_str}')) { #{submit_str} } else { return false; }"
|
204
|
+
else
|
205
|
+
output = submit_str
|
206
|
+
end
|
207
|
+
output.html_safe
|
208
|
+
end
|
209
|
+
|
210
|
+
private
|
211
|
+
|
212
|
+
# Normalizes image file names
|
213
|
+
#
|
214
|
+
# This function tries to find the file based on the name supplied. In
|
215
|
+
# normal use you will only need to supply the image file name without
|
216
|
+
# any extention. It will check for the supplied name as is, and with
|
217
|
+
# .png, .gif, or .jpg extentions added to the supplied name, in the
|
218
|
+
# public, public/images, and public/images/icons directories. If the
|
219
|
+
# file is found, it's normalized path name is returned. Note: It will
|
220
|
+
# also match any file that is explictly specified.
|
221
|
+
#
|
222
|
+
# This version is used internally, and should not be used by users.
|
223
|
+
#
|
224
|
+
def cssmenu_clean_imagefile_name(name='')
|
225
|
+
root = Rails.public_path
|
226
|
+
filename = ""
|
227
|
+
# Shortcut to handle the most common cases.
|
228
|
+
if FileTest.exist?( File.join( root, "/images/#{name}.png" ) )
|
229
|
+
filename = "/images/#{name}.png"
|
230
|
+
elsif FileTest.exist?( File.join( root, "/images/icons/#{name}.png" ) )
|
231
|
+
filename = "/images/icons/#{name}.png"
|
232
|
+
else
|
233
|
+
# If not, check all
|
234
|
+
["", ".png", ".gif", ".jpg"].each do |ext|
|
235
|
+
# Check if full path has been specified
|
236
|
+
if FileTest.exist?( File.join( root, name + ext ) )
|
237
|
+
filename = name + ext
|
238
|
+
elsif FileTest.exist?( File.join( root, "/images/", name + ext ) )
|
239
|
+
filename = File.join( "/images/", name + ext )
|
240
|
+
elsif FileTest.exist?( File.join( root, "/images/icons/", name + ext ) )
|
241
|
+
filename = File.join( "/images/icons/", name + ext )
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
if filename.blank?
|
246
|
+
filename = "/images/broken.png"
|
247
|
+
end
|
248
|
+
filename
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
ActionView::Base.send :include, CssMenu
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cssmenu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- wmerrell
|
@@ -48,7 +48,10 @@ files:
|
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
|
+
- cssmenu-0.1.0.gem
|
52
|
+
- cssmenu.gemspec
|
51
53
|
- lib/cssmenu.rb
|
54
|
+
- lib/cssmenu/engine.rb
|
52
55
|
- test/helper.rb
|
53
56
|
- test/test_cssmenu.rb
|
54
57
|
has_rdoc: true
|