mtoros-mega_menus 0.6.6 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -25,6 +25,11 @@ The current version creates:
|
|
25
25
|
* Rails 2.2
|
26
26
|
|
27
27
|
== NOTES:
|
28
|
+
* You can have multiple partials rendering different parts of the menu. Include in your partial the following line:
|
29
|
+
- <% mega_menus(name_of_the_menu_model, 'name_of_the_menu_controller', par, arr, parent_id) %>
|
30
|
+
- where par is the either TRUE(editor mode) or FALSE(normal mode), arr is an array containing the interval of depths to be shown(2..3 means display menus with depths 2 and 3), parent_id determines to which parent are this children related to( 5 would mean show only children whoose ancestor has id parent_id)
|
31
|
+
* If you have multiple partials you should edit the rjs files in order to assure proper updating of each partial. By default only the generated partial is updated.
|
32
|
+
|
28
33
|
* The menu is located in <ul id="ul_menu_#{m.depth}" class="ul_menu_depth_#{m.depth}">
|
29
34
|
* The selected menu is located in <li class="li_menu_class_selected">
|
30
35
|
* This two id and class values can be easly changed by editing the mega_menu partial and its helper.
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rake'
|
|
4
4
|
begin
|
5
5
|
require 'echoe'
|
6
6
|
|
7
|
-
Echoe.new('mega_menus', '0.6.
|
7
|
+
Echoe.new('mega_menus', '0.6.8') do |p|
|
8
8
|
p.summary = "Treeview menu Gem for Rails"
|
9
9
|
p.description = "Adds a model, controller to perform the tasks in order to have a treeview menu. To use this gem simply install it and write script/generate menu name_of_the_menu"
|
10
10
|
p.author = ['Marko Toros']
|
data/lib/mega_menus/editor.rb
CHANGED
@@ -5,6 +5,22 @@ module MegaMenus
|
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
7
|
|
8
|
+
def isChildOf( parent_id)
|
9
|
+
menu_id=self.id
|
10
|
+
while(menu_id != 1)
|
11
|
+
menu_id= self.class.parent_menu(menu_id).id
|
12
|
+
if(menu_id===parent_id)
|
13
|
+
return TRUE
|
14
|
+
end
|
15
|
+
end
|
16
|
+
return FALSE
|
17
|
+
end
|
18
|
+
|
19
|
+
def children
|
20
|
+
self.class.children(self.id)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
8
24
|
module ClassMethods
|
9
25
|
def acts_as_menu
|
10
26
|
self.send :extend, MenuClassMethods
|
@@ -63,10 +79,6 @@ module MegaMenus
|
|
63
79
|
self.find(:all, :order=> "position" ,:conditions => { :parent_id=>menu_id})
|
64
80
|
end
|
65
81
|
|
66
|
-
def all_children(menu_id)
|
67
|
-
#to be written
|
68
|
-
end
|
69
|
-
|
70
82
|
def parent_menu(menu_id)
|
71
83
|
m=self.find(menu_id)
|
72
84
|
self.find(:first,:conditions => { :id=>m.parent_id})
|
data/mega_menus.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{mega_menus}
|
3
|
-
s.version = "0.6.
|
3
|
+
s.version = "0.6.8"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Marko Toros"]
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = ["Manifest", "README.rdoc", "init.rb", "Rakefile", "lib/mega_menus.rb", "lib/mega_menus/editor.rb", "lib/mega_menus/view_helpers.rb", "test/test_editor.rb", "rails_generators/menu/USAGE", "rails_generators/menu/menu_generator.rb", "rails_generators/menu/templates/controllers/menu_controller.rb", "rails_generators/menu/templates/views/add_menu_form.rjs", "rails_generators/menu/templates/views/add_menu.rjs", "rails_generators/menu/templates/views/delete_menu.rjs", "rails_generators/menu/templates/views/edit_menu_form.rjs", "rails_generators/menu/templates/views/edit_menu.rjs", "rails_generators/menu/templates/views/up_menu.rjs", "rails_generators/menu/templates/views/down_menu.rjs", "rails_generators/menu/templates/views/_menu.html.erb", "rails_generators/menu/templates/helpers/menu_helper.rb", "rails_generators/menu/templates/models/create_menus.rb", "rails_generators/menu/templates/models/menu.rb", "mega_menus.gemspec"]
|
12
12
|
s.has_rdoc = true
|
13
13
|
s.homepage = %q{}
|
14
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mega_menus", "--main", "README.rdoc"]
|
14
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mega_menus", "--main", "README.rdoc~"]
|
15
15
|
s.require_paths = ["lib"]
|
16
16
|
s.rubyforge_project = %q{mega_menus}
|
17
17
|
s.rubygems_version = %q{1.2.0}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module <%= "#{file_name.capitalize}Helper" %>
|
2
|
-
def mega_menus(menu_model, menu_controller, admin_condition, admin_depth)
|
2
|
+
def mega_menus(menu_model, menu_controller, admin_condition, admin_depth, admin_parent)
|
3
3
|
#Checks
|
4
4
|
if(!menu_checks(menu_model))
|
5
5
|
return nil
|
6
6
|
end
|
7
7
|
#HTML generation
|
8
|
-
html_generation(menu_model, menu_controller,admin_condition, admin_depth)
|
8
|
+
html_generation(menu_model, menu_controller,admin_condition, admin_depth, admin_parent)
|
9
9
|
end
|
10
10
|
|
11
11
|
def menu_checks(menu_model)
|
@@ -20,7 +20,7 @@ module <%= "#{file_name.capitalize}Helper" %>
|
|
20
20
|
return TRUE
|
21
21
|
end
|
22
22
|
|
23
|
-
def html_generation(menu_model, menu_controller,admin_condition, admin_depth)
|
23
|
+
def html_generation(menu_model, menu_controller,admin_condition, admin_depth, admin_parent)
|
24
24
|
allmenus=menu_model.find(:all, :order => "absolute_position")
|
25
25
|
#mdp...previous menu depth
|
26
26
|
pmd=1
|
@@ -30,32 +30,27 @@ module <%= "#{file_name.capitalize}Helper" %>
|
|
30
30
|
elsif(!session[:menu_id].nil?)
|
31
31
|
menu_id=session[:menu_id]
|
32
32
|
end
|
33
|
-
|
34
|
-
|
33
|
+
|
35
34
|
firstm=TRUE
|
36
35
|
allmenus.each do |m|
|
37
|
-
#
|
38
|
-
if(
|
39
|
-
if
|
40
|
-
|
41
|
-
if(
|
42
|
-
|
43
|
-
|
44
|
-
concat
|
45
|
-
add_menu_form
|
36
|
+
#write the actual menu line for each record
|
37
|
+
if(m.id!=1 and m.isChildOf(admin_parent))
|
38
|
+
#check if your depth is correct
|
39
|
+
if(admin_depth.include?(m.depth))
|
40
|
+
if(m.depth > pmd or firstm)
|
41
|
+
concat( "<ul id=\"ul_menu_#{m.depth}\" class=\"ul_menu_depth_#{m.depth} ul_menu\">")
|
42
|
+
if(admin_condition)
|
43
|
+
concat( "<li id=\"root_add_#{m.parent_id}\" class=\"root_add\">")
|
44
|
+
concat( link_to_remote( "<span>Add</span>", {:url => {:controller => menu_controller, :action => 'add_menu_form', :menu_id => m.parent_id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links_add", :title=> "Add",:id => "add_menu_link_#{m.id}"}))
|
45
|
+
add_menu_form(menu_model, menu_controller, m.parent_id)
|
46
46
|
concat( "</li>")
|
47
47
|
end
|
48
|
+
firstm=FALSE
|
49
|
+
elsif(m.depth < pmd)
|
50
|
+
pmd.downto(m.depth+1) {concat( "</ul>")}
|
48
51
|
end
|
49
|
-
|
50
|
-
elsif(m.depth > pmd)
|
51
|
-
concat( "<ul id=\"ul_menu_#{m.depth}\" class=\"ul_menu_depth_#{m.depth} ul_menu\">")
|
52
|
-
elsif(m.depth < pmd)
|
53
|
-
pmd.downto(m.depth+1) {concat( "</ul>")}
|
54
|
-
end
|
55
|
-
pmd=m.depth
|
52
|
+
pmd=m.depth
|
56
53
|
|
57
|
-
#write the actual menu line for each record
|
58
|
-
if(m.id!=1)
|
59
54
|
#make the selected view appear nicer
|
60
55
|
if(m.id==menu_id.to_i)
|
61
56
|
concat( "<li id=\"li_menu_#{m.id}\" class=\"li_menu_class_selected\">")
|
@@ -66,15 +61,23 @@ module <%= "#{file_name.capitalize}Helper" %>
|
|
66
61
|
concat( "<a class=\"menu_link\", id =\"menu_link_#{m.id}\" href=\"#{m.link}?menu_id=#{m.id}\"> #{m.title} </a>")
|
67
62
|
end
|
68
63
|
if(admin_condition)
|
69
|
-
|
64
|
+
#remove the comment on the following line depending on the view you want to have
|
65
|
+
#concat( link_to_remote( "<span>Add</span>", {:url => {:controller => menu_controller, :action => 'add_menu_form', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links_add", :title=> "Add",:id => "add_menu_link_#{m.id}"}))
|
70
66
|
concat( link_to_remote( "<span>Delete</span>", {:url => {:controller => menu_controller, :action => 'delete_menu', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links_delete", :title=> "Delete",:id => "delete_menu_link_#{m.id}"}))
|
71
67
|
concat( link_to_remote( "<span>Edit</span>", {:url => {:controller => menu_controller, :action => 'edit_menu_form', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links_edit",:title=> "Edit", :id => "edit_menu_link_#{m.id}"}))
|
72
68
|
concat( link_to_remote( "<span>Up</span>", {:url => {:controller => menu_controller, :action => 'up_menu', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links_up", :title=> "Up",:id => "up_menu_link_#{m.id}"}))
|
73
69
|
concat( link_to_remote( "<span>Down</span>", {:url => {:controller => menu_controller, :action => 'down_menu', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links_down", :title=> "Down", :id => "down_menu_link_#{m.id}"}))
|
74
|
-
add_menu_form(menu_model, menu_controller,m.id)
|
75
70
|
edit_menu_form(menu_model, menu_controller,m)
|
76
71
|
end
|
77
72
|
concat( "</li>")
|
73
|
+
if(admin_condition and m.children.empty? and admin_depth.include?(m.depth+1))
|
74
|
+
concat( "<ul id=\"ul_menu_#{m.depth+1}\" class=\"ul_menu_depth_#{m.depth+1} ul_menu\">")
|
75
|
+
concat( "<li id=\"root_add_#{m.id}\" class=\"root_add\">")
|
76
|
+
concat( link_to_remote( "<span>Add</span>", {:url => {:controller => menu_controller, :action => 'add_menu_form', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links_add", :title=> "Add",:id => "add_menu_link_#{m.id}"}))
|
77
|
+
add_menu_form(menu_model, menu_controller, m.id)
|
78
|
+
concat( "</li>")
|
79
|
+
concat( "</ul>")
|
80
|
+
end
|
78
81
|
end
|
79
82
|
end
|
80
83
|
end
|
@@ -85,9 +88,9 @@ module <%= "#{file_name.capitalize}Helper" %>
|
|
85
88
|
def add_menu_form(menu_model, menu_controller, menu_id)
|
86
89
|
form_remote_tag( :url => {:controller=>menu_controller, :action=> 'add_menu'}, :html => {:id => "add_menu_form_#{menu_id}", :class => "add_menu_form", :style=>"display: none"}) do
|
87
90
|
concat( "Title:" )
|
88
|
-
concat( text_field_tag( "title"
|
91
|
+
concat( text_field_tag( "title"))
|
89
92
|
concat( "Link:")
|
90
|
-
concat( text_field_tag("link"
|
93
|
+
concat( text_field_tag("link"))
|
91
94
|
concat( hidden_field_tag(:menu_id, menu_id))
|
92
95
|
#content_tag :button, "Submit", {:type=>"submit", :class=>"button-submit"}
|
93
96
|
concat( submit_tag( "Add", :class => "add_button"))
|
@@ -1,4 +1,4 @@
|
|
1
1
|
<%#"The 3. parameter determines normal mode(FALSE) or edit mode(TRUE)...remove this annoying line" %>
|
2
2
|
<%# "The 4. parameter determines the depth of the menus to be shown...remove this annoying line" %>
|
3
|
-
<%% mega_menus(<%= file_name.capitalize %>, <%= "'#{file_name+ "editor"}'"%>, TRUE, 1..10) %>
|
3
|
+
<%% mega_menus(<%= file_name.capitalize %>, <%= "'#{file_name+ "editor"}'"%>, TRUE, 1..10,1) %>
|
4
4
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mtoros-mega_menus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marko Toros
|
@@ -65,7 +65,7 @@ rdoc_options:
|
|
65
65
|
- --title
|
66
66
|
- Mega_menus
|
67
67
|
- --main
|
68
|
-
- README.rdoc
|
68
|
+
- README.rdoc~
|
69
69
|
require_paths:
|
70
70
|
- lib
|
71
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|