dynamic_menu 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +0 -1
- data/README.rdoc +20 -60
- data/Rakefile +4 -1
- data/dynamic_menu.gemspec +3 -3
- data/lib/dynamic_menu.rb +31 -37
- data/lib/engine.rb +9 -0
- metadata +4 -3
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -1,70 +1,30 @@
|
|
1
|
-
=
|
2
|
-
==Introduction
|
3
|
-
Dynamic Menu is a gem to make it easy to add a custom menu to your application via a controller.
|
4
|
-
== Install
|
5
|
-
You need to add:
|
1
|
+
=DYNAMIC MENU
|
6
2
|
|
7
|
-
|
3
|
+
Dynamic Menu is a Gem that provides a way to make it easy to create a menu that changes according
|
4
|
+
to the controller action. The controller passes in information into an array which is accessed by
|
5
|
+
the view.
|
8
6
|
|
9
|
-
|
7
|
+
==Installation
|
8
|
+
While pre-1.0 releases exits we recommend not using them as the code in them is not the best
|
9
|
+
and will not auto-load into your controller, they will not be commented on here.
|
10
10
|
|
11
|
-
|
12
|
-
this line to your gemfile:
|
11
|
+
In your Gemfile make sure you have
|
13
12
|
|
14
|
-
gem
|
13
|
+
gem 'dynamic_menu','~>1.0.0'
|
15
14
|
|
16
|
-
|
15
|
+
then run bundle install
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
==How to use
|
18
|
+
To use DynamicMenu you need to create an array such as @MenuItems and store items in it.
|
19
|
+
So in your controller in each method you can do something like:
|
20
20
|
|
21
|
-
@
|
21
|
+
@MenuItems = Array.new
|
22
22
|
|
23
|
-
|
23
|
+
@MenuItems << newmenuitem("name","link")
|
24
24
|
|
25
|
-
|
25
|
+
newmenuitem() is the method you need to use to add a menu-item.
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
menu.link_tag #this generates the entire link
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
if you need a delete and confirmation method then you can declare it like so:
|
36
|
-
|
37
|
-
option1 = DynamicMenu::ActionMenuItem.new("Link Name", link_to_path, :delete, "Are you sure?")
|
38
|
-
|
39
|
-
the first is what the link will look like on the view, second is the view, third is the method (only works
|
40
|
-
for delete) and the fourth is the confirmation method (which also only works on delete)
|
41
|
-
|
42
|
-
===Option2
|
43
|
-
Like Option1 except in your controller you can declare include DynamicForm right underneath the class
|
44
|
-
|
45
|
-
like so:
|
46
|
-
|
47
|
-
class SomeController < ApplicationController
|
48
|
-
|
49
|
-
include DynamicMenu
|
50
|
-
|
51
|
-
then instead of using DynamicMenu::ActionMenuItem.new you can use ActionMenuItem.new
|
52
|
-
|
53
|
-
|
54
|
-
==Tips
|
55
|
-
To prevent long code you can no arrays like so:
|
56
|
-
|
57
|
-
@actionMenuItems = Array.new
|
58
|
-
|
59
|
-
@actionMenuItems << ActionMenuItem.new("Link",link_path)
|
60
|
-
|
61
|
-
==Updates
|
62
|
-
As of 0.2.0 you can now make a custom submit link via the Dynamic Menu. It is buggy in 0.2.0 so we recommend that you use 0.2.1 if you would like to do this. This option requires you to be using JQuery or somehow reference it, as the code to detect the enter key runs with its syntax.
|
63
|
-
|
64
|
-
To make a link that acts like a submit button simply use :submit as a link.
|
65
|
-
|
66
|
-
As of 0.2.2 you can use :back as link because it will load a javascript to get you back
|
67
|
-
|
68
|
-
For example:
|
69
|
-
|
70
|
-
@actionMenuItems << ActionMenuItem.new("Submit Form",:submit)
|
27
|
+
newmenuitem has the arguments of name, link, method, and confirm. Method and confirm only
|
28
|
+
need to be specified if you are using anything other than get. Link may use :submit which
|
29
|
+
will submit a form when clicked and add a JavaScript method to listen for the enter key to
|
30
|
+
submit the form. Name and Link are the only required fields and are both Strings...
|
data/Rakefile
CHANGED
@@ -2,13 +2,16 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('dynamic_menu', '0.
|
5
|
+
Echoe.new('dynamic_menu', '1.0.0') do |p|
|
6
6
|
p.description = "Allow the creation of Menus"
|
7
7
|
p.url = "http://pessetto.com"
|
8
8
|
p.author = "Travis Pessettto"
|
9
9
|
p.email = "travis@pessetto.com"
|
10
10
|
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
11
|
p.development_dependencies = []
|
12
|
+
|
12
13
|
end
|
13
14
|
|
15
|
+
|
16
|
+
|
14
17
|
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/dynamic_menu.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{dynamic_menu}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "1.0.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = [%q{Travis Pessettto}]
|
9
|
-
s.date = %q{2011-08-
|
9
|
+
s.date = %q{2011-08-12}
|
10
10
|
s.description = %q{Allow the creation of Menus}
|
11
11
|
s.email = %q{travis@pessetto.com}
|
12
12
|
s.extra_rdoc_files = [%q{README.rdoc}, %q{lib/dynamic_menu.rb}]
|
13
|
-
s.files = [%q{README.rdoc}, %q{Rakefile}, %q{dynamic_menu.
|
13
|
+
s.files = [%q{README.rdoc}, %q{Rakefile}, %q{lib/dynamic_menu.rb},%q{lib/engine.rb}, %q{Manifest}, %q{dynamic_menu.gemspec}]
|
14
14
|
s.homepage = %q{http://pessetto.com}
|
15
15
|
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Dynamic_menu}, %q{--main}, %q{README.rdoc}]
|
16
16
|
s.require_paths = [%q{lib}]
|
data/lib/dynamic_menu.rb
CHANGED
@@ -1,49 +1,43 @@
|
|
1
1
|
module DynamicMenu
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :name, :link, :method, :link_tag
|
8
|
-
|
9
|
-
def initialize(name, link , method = :get, confirm="Are You Sure?")
|
10
|
-
@name = name
|
11
|
-
@link = link
|
12
|
-
@method = method
|
13
|
-
@link_tag = ""
|
2
|
+
require 'engine' if defined?(Rails)
|
3
|
+
|
4
|
+
module MenuItems
|
5
|
+
def newmenuitem(name,link,method=:get,confirm="Are you sure?")
|
6
|
+
genlink = ""
|
14
7
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#make it easy to include a submit button via link...for enter support...requires
|
21
|
-
#JQUERY!!!
|
22
|
-
@link_tag = link_to_function name, "$('form').submit()"
|
8
|
+
if method==:delete
|
9
|
+
genlink += "<a href=\"#{link}\" data-confirm=\"#{confirm}\" data-method=\"delete\" rel=\"nofollow\">
|
10
|
+
#{name}</a>".html_safe
|
11
|
+
elsif link==:submit
|
12
|
+
genlink += "<a href=\"#\" onclick=\"$('form').submit(); return false;\">#{name}</a>".html_safe
|
23
13
|
@link_tag += "<script type=\"text/javascript\">
|
24
14
|
$(document).ready(function(){
|
25
15
|
$('html').keypress(function(e){
|
26
|
-
|
16
|
+
if(e.which == 13){
|
27
17
|
$('form').submit();
|
28
|
-
|
29
|
-
|
18
|
+
return false;
|
19
|
+
}
|
30
20
|
});
|
31
21
|
});</script>".html_safe
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
elsif link == :back
|
23
|
+
genlink = "<a href=\"#\" id=\"jcheats-back\">#{name}</a>".html_safe
|
24
|
+
genlink += "<script type=\"text/javascript\">
|
25
|
+
$(\"#jcheats-back\").live(\"click\",
|
36
26
|
function(){
|
37
|
-
|
38
|
-
|
27
|
+
var ref = document.referrer;
|
28
|
+
document.location=ref;
|
39
29
|
});
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
</script>".html_safe
|
31
|
+
else
|
32
|
+
genlink = "<a href=\"#{link}\">#{name}<a>".html_safe
|
33
|
+
end
|
34
|
+
return genlink
|
35
|
+
end
|
36
|
+
|
46
37
|
|
47
|
-
|
38
|
+
def foo
|
39
|
+
"bar"
|
40
|
+
end
|
48
41
|
|
49
|
-
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/engine.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_menu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-12 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Allow the creation of Menus
|
15
15
|
email: travis@pessetto.com
|
@@ -21,9 +21,10 @@ extra_rdoc_files:
|
|
21
21
|
files:
|
22
22
|
- README.rdoc
|
23
23
|
- Rakefile
|
24
|
-
- dynamic_menu.gemspec
|
25
24
|
- lib/dynamic_menu.rb
|
25
|
+
- lib/engine.rb
|
26
26
|
- Manifest
|
27
|
+
- dynamic_menu.gemspec
|
27
28
|
homepage: http://pessetto.com
|
28
29
|
licenses: []
|
29
30
|
post_install_message:
|