mtoros-mega_menus 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest ADDED
@@ -0,0 +1,22 @@
1
+ Manifest
2
+ README
3
+ Rakefile
4
+ lib/mega_menus.rb
5
+ lib/mega_menus/editor.rb
6
+ lib/mega_menus/view_helpers.rb
7
+ test/test_editor.rb
8
+ rails_generators/menu/USAGE
9
+ rails_generators/menu/menu_generator.rb
10
+ rails_generators/menu/templates/controllers/menu_controller.rb
11
+ rails_generators/menu/templates/views/add_menu_form.rjs
12
+ rails_generators/menu/templates/views/add_menu.rjs
13
+ rails_generators/menu/templates/views/delete_menu.rjs
14
+ rails_generators/menu/templates/views/edit_menu_form.rjs
15
+ rails_generators/menu/templates/views/edit_menu.rjs
16
+ rails_generators/menu/templates/views/up_menu.rjs
17
+ rails_generators/menu/templates/views/down_menu.rjs
18
+ rails_generators/menu/templates/views/_menu.html.erb
19
+ rails_generators/menu/templates/helpers/menu_helper.rb
20
+ rails_generators/menu/templates/models/create_menus.rb
21
+ rails_generators/menu/templates/models/menu.rb
22
+ test/test_editor.rb
data/README ADDED
@@ -0,0 +1,30 @@
1
+ = MegaMenus
2
+
3
+ == DESCRIPTION:
4
+
5
+ This gem makes working with menu structures in Rails easier.
6
+
7
+ == FEATURES/PROBLEMS:
8
+ The current version creates
9
+ -a controller for editing the menu
10
+ -views associated to methods written in rjs
11
+ -a partial for rendering the menu
12
+ -a helper to configure its working in normal mode and edit mode
13
+ -a model for storing the menu with a field absolute_position to improve performance when the menu is in normal mode
14
+ -a generator for rails to ease the developers work for using this gem
15
+
16
+ == STATUS
17
+ Currently writing tests to ensure proper working for future versions.
18
+
19
+
20
+ == REQUIREMENTS:
21
+ Rails 2.2
22
+
23
+ == NOTES:
24
+ The menu is located in "<div id=\"mega_menus\">"
25
+ The selected menu is located in "<div id=\"selected_mega_menu\">"
26
+
27
+
28
+ == INSTALL:
29
+ script/generate menu menu_name
30
+
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ #require './lib/mega_menus.rb'
2
+ require 'rubygems'
3
+ require 'rake'
4
+
5
+ begin
6
+ require 'echoe'
7
+
8
+ Echoe.new('mega_menus', '0.4.9') do |p|
9
+ p.summary = "Treeview menu Gem for Rails"
10
+ 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"
11
+ p.author = ['Marko Toros', 'Rails Core']
12
+ p.email = "mtoros@gmail.com"
13
+ #p.url = ""
14
+ end
15
+ rescue LoadError => boom
16
+ puts "You are missing a dependency required for meta-operations on this gem."
17
+ puts "#{boom.to_s.capitalize}."
18
+ end
19
+
20
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,195 @@
1
+ module MegaMenus
2
+ module Editor
3
+ #here we want a class method!
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_menu
10
+ self.send :extend, MenuClassMethods
11
+ end
12
+ end
13
+ end
14
+ module MenuClassMethods
15
+ def check_menus
16
+ #title, id, parent_id, link
17
+ cn=self.column_names
18
+ if(!cn.include?("id"))
19
+ return FALSE
20
+ end
21
+ if(!cn.include?("title"))
22
+ return FALSE
23
+ end
24
+ if(!cn.include?("parent_id"))
25
+ return FALSE
26
+ end
27
+ if(!cn.include?("link"))
28
+ return FALSE
29
+ end
30
+ if(!cn.include?("position"))
31
+ return FALSE
32
+ end
33
+ if(!cn.include?("absolute_position"))
34
+ return FALSE
35
+ end
36
+ if(!cn.include?("depth"))
37
+ return FALSE
38
+ end
39
+ #model correct
40
+ return TRUE
41
+ end
42
+
43
+ def add_child(menu_id, title, link)
44
+ position=assign_position(menu_id)
45
+ child = self.new( "title" => title,
46
+ "link" => link,
47
+ "parent_id" => menu_id,
48
+ "position" => position)
49
+ child.save!
50
+ end
51
+
52
+ def assign_position(parent_id)
53
+ c=children(parent_id)
54
+ if(!c.empty?)
55
+ position= (c.max {|c1,c2| c1.position <=> c2.position}).position + 1
56
+ else
57
+ position=1
58
+ end
59
+ return position
60
+ end
61
+
62
+ def children(menu_id)
63
+ self.find(:all, :order=> "position" ,:conditions => { :parent_id=>menu_id})
64
+ end
65
+
66
+ def all_children(menu_id)
67
+ #to be written
68
+ end
69
+
70
+ def parent_menu(menu_id)
71
+ m=self.find(menu_id)
72
+ self.find(:first,:conditions => { :id=>m.parent_id})
73
+ end
74
+
75
+ def siblings(menu_id)
76
+ p=parent_menu(menu_id)
77
+ ac=children(p.id)
78
+ i=0
79
+ ac.each do |c|
80
+ if(c.id==menu_id)
81
+ ac.delete_at(i)
82
+ break
83
+ end
84
+ i=i+1
85
+ end
86
+ return ac
87
+ end
88
+
89
+ #sorry..for the spin word...:)
90
+ def get_menu(parent_id, position)
91
+ self.find(:first,:conditions => { :parent_id=>parent_id, :position => position})
92
+ end
93
+
94
+ def switch_menu_positions(parent_id, position1, position2)
95
+ menu1=get_menu(parent_id,position1)
96
+ menu2=get_menu(parent_id,position2)
97
+ menu1.position,menu2.position =menu2.position,menu1.position
98
+ menu1.save!
99
+ menu2.save!
100
+ end
101
+
102
+ def position_up(id)
103
+ menu=self.find(id)
104
+ if(menu.position>1)
105
+ switch_menu_positions(menu.parent_id, menu.position, menu.position-1)
106
+ end
107
+ end
108
+
109
+ def position_down(id)
110
+ menu=self.find(id)
111
+ if(menu.position< (siblings(id).max {|c1,c2| c1.position <=> c2.position}).position)
112
+ switch_menu_positions(menu.parent_id, menu.position, menu.position+1)
113
+ end
114
+ end
115
+
116
+ def edit(menu_id, new_parent_id, title, link)
117
+ menu=self.find(menu_id)
118
+ menu.update_attributes!(:title=> title,:link=> link)
119
+ if(menu.parent_id != new_parent_id)
120
+ position=assign_position(new_parent_id)
121
+ newmenu=self.new(:title=>title, :link=>link, :parent_id=>new_parent_id, :position=>position)
122
+ newmenu.save!
123
+ children(menu.id).each do |c|
124
+ c.parent_id=newmenu.id
125
+ end
126
+ siblings(menu).each do |s|
127
+ if(s.position>menu.position)
128
+ s.decrement(:position)
129
+ s.save!
130
+ end
131
+ end
132
+ self.delete(menu_id)
133
+ end
134
+ end
135
+
136
+ def delete_item(menu_id)
137
+ menu=self.find(menu_id)
138
+ if(children(menu_id).empty?)
139
+ siblings(menu_id).each do |s|
140
+ if(s.position>menu.position)
141
+ s.decrement(:position)
142
+ s.save!
143
+ end
144
+ end
145
+ else
146
+ siblings(menu.id).each do |s|
147
+ if(s.position>menu.position)
148
+ s.position+=children(menu.id).count - 1
149
+ s.save!
150
+ end
151
+ end
152
+ end
153
+ #actual move
154
+ children(menu.id).each do |c|
155
+ c.position+=menu.position-1
156
+ c.parent_id=menu.parent_id
157
+ c.save!
158
+ end
159
+ self.delete(menu_id)
160
+ end
161
+
162
+ def determine_abs_position_and_depth
163
+ roots=self.find(:all,:order=>"position",:conditions => {:parent_id=>1} )
164
+ ap=0
165
+ depth=1
166
+ roots.each do |r|
167
+ ap+=1
168
+ r.absolute_position=ap
169
+ r.depth=depth
170
+ r.save!
171
+ ap,depth=recursive_dapad(r,ap,depth)
172
+ end
173
+ end
174
+
175
+ def recursive_dapad(rp,ap,depth)
176
+ depth+=1
177
+ children(rp.id).each do |m|
178
+ ap+=1
179
+ m.absolute_position=ap
180
+ m.depth=depth
181
+ m.save!
182
+ ap,depth=recursive_dapad(m,ap,depth)
183
+ end
184
+ depth-=1
185
+ return ap,depth
186
+ end
187
+
188
+ def delete_children(menu_id)
189
+ #need to implement all_children first
190
+ #self.find(menu_id).all_children.each do |c|
191
+ # self.delete(c.id)
192
+ #end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,5 @@
1
+ #module MegaMenus
2
+ # module ViewHelpers
3
+ #
4
+ #end
5
+
data/lib/mega_menus.rb ADDED
@@ -0,0 +1,22 @@
1
+ module MegaMenus
2
+ class << self
3
+ def enable
4
+ enable_actionpack
5
+ enable_activerecord
6
+ end
7
+
8
+ def enable_actionpack
9
+ # require 'mega_menus/view_helpers'
10
+ # ActionView::Base.send :include, ViewHelpers
11
+ end
12
+
13
+ def enable_activerecord
14
+ require 'mega_menus/editor'
15
+ ActiveRecord::Base.send :include, Editor
16
+ end
17
+ end
18
+ end
19
+
20
+ if defined?(Rails) and defined?(ActiveRecord) and defined?(ActionController)
21
+ MegaMenus.enable
22
+ end
@@ -0,0 +1,33 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{mega_menus}
3
+ s.version = "0.4.9"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Marko Toros, Rails Core"]
7
+ s.date = %q{2008-11-10}
8
+ s.description = %q{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}
9
+ s.email = %q{mtoros@gmail.com}
10
+ s.extra_rdoc_files = ["README", "lib/mega_menus.rb", "lib/mega_menus/editor.rb", "lib/mega_menus/view_helpers.rb"]
11
+ s.files = ["Manifest", "README", "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
+ s.has_rdoc = true
13
+ s.homepage = %q{}
14
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mega_menus", "--main", "README"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{mega_menus}
17
+ s.rubygems_version = %q{1.2.0}
18
+ s.summary = %q{Treeview menu Gem for Rails}
19
+ s.test_files = ["test/test_editor.rb"]
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 2
24
+
25
+ if current_version >= 3 then
26
+ s.add_development_dependency(%q<echoe>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<echoe>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<echoe>, [">= 0"])
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ Write script/generate menu <name_of_menu> in the root folder of your rails application in order to use this generator.
@@ -0,0 +1,25 @@
1
+ class MenuGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ #create the menu controller
5
+ m.template "controllers/menu_controller.rb", "app/controllers/#{file_name}editor_controller.rb"
6
+ #create the views
7
+ m.directory File.join('app/views/', "#{file_name}editor")
8
+ m.template "views/add_menu_form.rjs", "app/views/#{file_name}editor/add_menu_form.rjs"
9
+ m.template "views/add_menu.rjs", "app/views/#{file_name}editor/add_menu.rjs"
10
+ m.template "views/delete_menu.rjs", "app/views/#{file_name}editor/delete_menu.rjs"
11
+ m.template "views/edit_menu_form.rjs", "app/views/#{file_name}editor/edit_menu_form.rjs"
12
+ m.template "views/edit_menu.rjs", "app/views/#{file_name}editor/edit_menu.rjs"
13
+ m.template "views/up_menu.rjs", "app/views/#{file_name}editor/up_menu.rjs"
14
+ m.template "views/down_menu.rjs", "app/views/#{file_name}editor/down_menu.rjs"
15
+ m.template "views/_menu.html.erb", "app/views/#{file_name}editor/_#{file_name}.html.erb"
16
+ #create the helper
17
+ m.template "helpers/menu_helper.rb", "app/helpers/#{file_name}_helper.rb"
18
+ #create the models
19
+ m.directory 'db/migrate/'
20
+ m.template "models/create_menus.rb", "db/migrate/#{Time.now.strftime("%Y%m%d%H%M%S")}_create_#{file_name}s.rb"
21
+ m.template "models/menu.rb", "app/models/#{file_name}.rb"
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,36 @@
1
+ class <%= "#{file_name.capitalize+ "editor" + "Controller"}" %> < ApplicationController
2
+
3
+ def add_menu_form
4
+ @menu_id=params[:menu_id]
5
+ end
6
+
7
+ def add_menu
8
+ <%= file_name.capitalize %>.add_child(params[:menu_id].to_i, params[:title], params[:link])
9
+ <%= file_name.capitalize %>.determine_abs_position_and_depth
10
+
11
+ end
12
+
13
+ def delete_menu
14
+ <%= file_name.capitalize %>.delete_item(params[:menu_id].to_i)
15
+ <%= file_name.capitalize %>.determine_abs_position_and_depth
16
+ end
17
+
18
+ def edit_menu_form
19
+ @menu_id=params[:menu_id]
20
+ end
21
+
22
+ def edit_menu
23
+ <%= file_name.capitalize %>.edit(params[:menu_id].to_i, params[:parent_id].to_i, params[:title], params[:link])
24
+ <%= file_name.capitalize %>.determine_abs_position_and_depth
25
+ end
26
+
27
+ def up_menu
28
+ <%= file_name.capitalize %>.position_up(params[:menu_id].to_i)
29
+ <%= file_name.capitalize %>.determine_abs_position_and_depth
30
+ end
31
+
32
+ def down_menu
33
+ <%= file_name.capitalize %>.position_down(params[:menu_id].to_i)
34
+ <%= file_name.capitalize %>.determine_abs_position_and_depth
35
+ end
36
+ end
@@ -0,0 +1,108 @@
1
+ module <%= "#{file_name.capitalize}Helper" %>
2
+ def mega_menus(menu_model, menu_controller, admin_condition)
3
+ #Checks
4
+ if(!menu_checks(menu_model))
5
+ return nil
6
+ end
7
+
8
+ #HTML generation
9
+ html_generation(menu_model, menu_controller,admin_condition)
10
+ end
11
+
12
+ def menu_checks(menu_model)
13
+ if(!defined?(menu_model.check_menus))
14
+ concat "Are you sure you have called acts_as_menu"
15
+ return FALSE
16
+ end
17
+ if(!menu_model.check_menus)
18
+ concat "You have not set correctly up the model."
19
+ return FALSE
20
+ end
21
+ return TRUE
22
+ end
23
+
24
+ def html_generation(menu_model, menu_controller,admin_condition)
25
+ concat "<div id=\"mega_menus\">"
26
+ if(admin_condition)
27
+ concat "Add Root:"
28
+ concat link_to_remote "Add", {:url => {:controller => menu_controller, :action => 'add_menu_form', :menu_id => 1,:menu_model=>menu_model, :menu_controller=>menu_controller } }, {:class => "menu_links", :id => "add_child_link_#{1}"}
29
+ add_menu_form(menu_model, menu_controller,1)
30
+ end
31
+ menu_list(menu_model, menu_controller,admin_condition)
32
+ concat "</div>"
33
+ end
34
+
35
+ def menu_list(menu_model, menu_controller,admin_condition)
36
+ allmenus=menu_model.find(:all, :order => "absolute_position")
37
+ concat "<ul>"
38
+ #mdp...previous menu depth
39
+ pmd=1
40
+ allmenus.each do |m|
41
+ if(m.id!=1)
42
+ if(m.depth > pmd)
43
+ pmd.upto(m.depth-1) {concat "<ul>"}
44
+ end
45
+ if(m.depth < pmd)
46
+ pmd.downto(m.depth+1) {concat "</ul>"}
47
+ end
48
+ pmd=m.depth
49
+ #write the actual menu line for each record
50
+ concat "<li>"
51
+ #make the selected view appear nicer
52
+ if(m.id==params[:menu_id].to_i or m.link==request.request_uri)
53
+ concat "<div id=\"selected_mega_menu\">"
54
+ end
55
+ concat link_to "#{m.title} #{m.id} ", m.link
56
+ if(m.id==params[:menu_id].to_i or m.link==request.request_uri)
57
+ concat "</div>"
58
+ end
59
+ if(admin_condition)
60
+ concat link_to_remote "Add", {:url => {:controller => menu_controller, :action => 'add_menu_form', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links", :id => "add_menu_link_#{m.id}"}
61
+ concat link_to_remote "Delete", {:url => {:controller => menu_controller, :action => 'delete_menu', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links", :id => "delete_menu_link_#{m.id}"}
62
+ concat link_to_remote "Edit", {:url => {:controller => menu_controller, :action => 'edit_menu_form', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links", :id => "edit_menu_link_#{m.id}"}
63
+ concat link_to_remote "Up", {:url => {:controller => menu_controller, :action => 'up_menu', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links",:id => "up_menu_link_#{m.id}"}
64
+ concat link_to_remote "Down", {:url => {:controller => menu_controller, :action => 'down_menu', :menu_id => m.id,:menu_model=>menu_model, :menu_controller=>menu_controller}}, {:class => "menu_links", :id => "down_menu_link_#{m.id}"}
65
+ add_menu_form(menu_model, menu_controller,m.id)
66
+ edit_menu_form(menu_model, menu_controller,m)
67
+ end
68
+ concat "</li>"
69
+ end
70
+ end
71
+ concat "<\ul>"
72
+
73
+ return nil
74
+ end
75
+
76
+ def add_menu_form(menu_model, menu_controller, menu_id)
77
+ form_remote_tag :url => {:controller=>menu_controller, :action=> 'add_menu'}, :html => {:id => "add_menu_form_#{menu_id}", :style=>"display: none"} do
78
+ concat "<div>"
79
+ concat "Title:"
80
+ concat text_field_tag "title", "title"
81
+ concat "Link:"
82
+ concat text_field_tag "link", "link"
83
+ concat hidden_field_tag :menu_id, menu_id
84
+ #content_tag :button, "Submit", {:type=>"submit", :class=>"button-submit"}
85
+ concat submit_tag "Add"
86
+ concat "</div>"
87
+ end
88
+ return nil
89
+ end
90
+
91
+
92
+ def edit_menu_form(menu_model, menu_controller,m)
93
+ form_remote_tag :url => {:controller=>menu_controller, :action=> 'edit_menu'}, :html => {:id => "edit_menu_form_#{m.id}", :style=>"display: none"} do
94
+ concat "<div>"
95
+ concat "Title:"
96
+ concat text_field_tag "title", m.title
97
+ concat "Link:"
98
+ concat text_field_tag "link", m.link
99
+ concat "Parent:"
100
+ concat text_field_tag "parent_id", m.parent_id
101
+ concat hidden_field_tag :menu_id, m.id
102
+ #concat content_tag :button, "Submit", {:type=>"submit", :class=>"button-submit"}
103
+ concat submit_tag "Edit"
104
+ concat "</div>"
105
+ end
106
+ return nil
107
+ end
108
+ end
@@ -0,0 +1,20 @@
1
+ class <%= "#{'Create' + file_name.capitalize + 's'}" %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table <%= ":#{file_name + 's'}" %> do |t|
4
+ t.string :title
5
+ t.string :link
6
+ t.integer :parent_id
7
+ t.integer :position
8
+ t.integer :absolute_position
9
+ t.integer :depth
10
+ t.timestamps
11
+ end
12
+
13
+ <%= file_name.capitalize %>.create :id => 1
14
+ end
15
+
16
+
17
+ def self.down
18
+ drop_table <%= ":#{file_name + 's'}" %>
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ class <%= file_name.capitalize %> < ActiveRecord::Base
2
+ acts_as_menu
3
+ end
@@ -0,0 +1,2 @@
1
+ <%= "The last parameter determines normal mode(FALSE) or edit mode(TRUE)...remove this annoying line" %>
2
+ <%% mega_menus(<%= file_name.capitalize %>, <%= "'#{file_name+ "editor"}'"%>, TRUE) %>
@@ -0,0 +1 @@
1
+ page.replace_html "mega_menus", :partial => <%= "'#{file_name}editor/#{file_name}'" %>
@@ -0,0 +1,2 @@
1
+ page.toggle "add_menu_form_#{@menu_id}"
2
+
@@ -0,0 +1 @@
1
+ page.replace_html "mega_menus", :partial => <%= "'#{file_name}editor/#{file_name}'" %>
@@ -0,0 +1 @@
1
+ page.replace_html "mega_menus", :partial => <%= "'#{file_name}editor/#{file_name}'" %>
@@ -0,0 +1 @@
1
+ page.replace_html "mega_menus", :partial => <%= "'#{file_name}editor/#{file_name}'" %>
@@ -0,0 +1 @@
1
+ page.toggle "edit_menu_form_#{@menu_id}"
@@ -0,0 +1 @@
1
+ page.replace_html "mega_menus", :partial => <%= "'#{file_name}editor/#{file_name}'" %>
@@ -0,0 +1,50 @@
1
+ require 'test/unit'
2
+
3
+ require 'rubygems'
4
+ gem 'activerecord'
5
+ require 'active_record'
6
+
7
+ require "#{File.dirname(__FILE__)}/../lib/mega_menus"
8
+ require 'mega_menus'
9
+ MegaMenus.enable_activerecord
10
+
11
+ def setup_db
12
+ ActiveRecord::Schema.define(:version => 1) do
13
+ create_table :topics do |t|
14
+ t.column :pos, :integer
15
+ t.column :parent_id, :integer
16
+ t.column :created_at, :datetime
17
+ t.column :updated_at, :datetime
18
+ end
19
+ end
20
+ end
21
+
22
+ def teardown_db
23
+ ActiveRecord::Base.connection.tables.each do |table|
24
+ ActiveRecord::Base.connection.drop_table(table)
25
+ end
26
+ end
27
+
28
+ class Topic < ActiveRecord::Base
29
+ acts_as_menu
30
+ end
31
+
32
+ class TestEditor < Test::Unit::TestCase
33
+ def setup
34
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
35
+ setup_db
36
+ (1..5).each { |counter| Topic.create! :pos => counter, :parent_id => counter }
37
+ end
38
+
39
+ def teardown
40
+ teardown_db
41
+ end
42
+
43
+ def test_small
44
+ assert_equal 5, Topic.count
45
+ end
46
+
47
+ def test_other
48
+ end
49
+ #add root, add menu, delete menu, ..., change position,...
50
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mtoros-mega_menus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.9
5
+ platform: ruby
6
+ authors:
7
+ - Marko Toros, Rails Core
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-10 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: echoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ 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
25
+ email: mtoros@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - lib/mega_menus.rb
33
+ - lib/mega_menus/editor.rb
34
+ - lib/mega_menus/view_helpers.rb
35
+ files:
36
+ - Manifest
37
+ - README
38
+ - Rakefile
39
+ - lib/mega_menus.rb
40
+ - lib/mega_menus/editor.rb
41
+ - lib/mega_menus/view_helpers.rb
42
+ - test/test_editor.rb
43
+ - rails_generators/menu/USAGE
44
+ - rails_generators/menu/menu_generator.rb
45
+ - rails_generators/menu/templates/controllers/menu_controller.rb
46
+ - rails_generators/menu/templates/views/add_menu_form.rjs
47
+ - rails_generators/menu/templates/views/add_menu.rjs
48
+ - rails_generators/menu/templates/views/delete_menu.rjs
49
+ - rails_generators/menu/templates/views/edit_menu_form.rjs
50
+ - rails_generators/menu/templates/views/edit_menu.rjs
51
+ - rails_generators/menu/templates/views/up_menu.rjs
52
+ - rails_generators/menu/templates/views/down_menu.rjs
53
+ - rails_generators/menu/templates/views/_menu.html.erb
54
+ - rails_generators/menu/templates/helpers/menu_helper.rb
55
+ - rails_generators/menu/templates/models/create_menus.rb
56
+ - rails_generators/menu/templates/models/menu.rb
57
+ - mega_menus.gemspec
58
+ has_rdoc: true
59
+ homepage: ""
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --line-numbers
63
+ - --inline-source
64
+ - --title
65
+ - Mega_menus
66
+ - --main
67
+ - README
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "1.2"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: mega_menus
85
+ rubygems_version: 1.2.0
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: Treeview menu Gem for Rails
89
+ test_files:
90
+ - test/test_editor.rb