dynamic_menu 3.0.0.rc2 → 3.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ module DynamicMenu
2
+ module AdvancedObjects
3
+
4
+ class AdvancedArray < AdvancedHash
5
+
6
+ def initialize
7
+ @instance = []
8
+ end
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module DynamicMenu
2
- module AdvancedHash
2
+ module AdvancedObjects
3
3
  class AdvancedHash
4
4
 
5
5
  def initialize
@@ -7,8 +7,13 @@ module DynamicMenu
7
7
  end
8
8
 
9
9
  def tap! *args, &block
10
- @instance = @instance.tap(*args, &block)
10
+ yield block;
11
+ # @instance = @instance.map(*args, &block)
11
12
  end
13
+
14
+ def add *args
15
+ @instance.merge(args);
16
+ end
12
17
 
13
18
  def method_missing method, *args, &block
14
19
  super unless @instance.methods.index method
@@ -3,11 +3,13 @@ module DynamicMenu
3
3
 
4
4
  def initialize(parent)
5
5
  @parent ||= parent
6
- @menuLinks = build_menu
6
+ load_instance_vars
7
+ @menuLinks = AdvancedArray.new
8
+ build_menu
7
9
  end
8
10
 
9
11
  def get_menu_links
10
- @menuLinks || AdvancedHash::AdvancedHash.new
12
+ @menuLinks || AdvancedArray.new
11
13
  end
12
14
 
13
15
  def method_missing(method, *args)
@@ -20,11 +22,23 @@ module DynamicMenu
20
22
  file = Rails.root.to_s+"/app/menus/#{params[:controller]}/#{menu_name}.rb"
21
23
  load file
22
24
  links_obj = "#{menu_name}Menu".classify.constantize.new(@parent)
23
- @menuLinks = @menuLinks.merge(links_obj.get_menu_links)
25
+ @menuLinks << links_obj.get_menu_links
26
+ end
27
+
28
+ def load_instance_vars
29
+ @parent.instance_variables.each do |var|
30
+ instance_variable_set(var.intern,@parent.instance_variable_get(var.intern))
31
+ end
24
32
  end
25
33
 
26
34
  def menu_instance
27
- @menuLinks ||= AdvancedHash::AdvancedHash.new
35
+ @menuLinks ||= AdvancedArray.new
36
+ end
37
+
38
+ def add *args
39
+ args.each do |arg|
40
+ @menuLinks << arg
41
+ end
28
42
  end
29
43
 
30
44
  end
@@ -2,16 +2,33 @@ module DynamicMenu
2
2
  module InheritableMenus
3
3
  mattr_accessor :menu
4
4
  @@menu = Hash.new
5
-
6
-
7
5
  def get_current_menu
8
6
  path = Rails.root.join('app/menus')
9
7
  full_path = path + "#{params[:controller]}/#{params[:action]}.rb"
10
8
  if File.exists?(full_path)
11
9
  load full_path
12
10
  "#{params[:action]}Menu".classify.constantize.new(self)
11
+ else
12
+ #Depending on the action (for example edit) it should look for a relationship (:create=:new or :update=:edit)
13
13
  end
14
14
  end
15
-
15
+
16
+ def dynamic_menu_file_loader controller, action
17
+ path = Rails.root.join('app/menus')
18
+ full_path += "#{controller}/#{action}.rb"
19
+ try_again_des = try_again? action
20
+ if !try_again_des.nil?
21
+ dynamic_menu_file_loader controller, try_again_des
22
+ end
23
+ end
24
+
25
+ def try_again? action
26
+ if action == :create
27
+ return :new
28
+ elsif action == :update
29
+ return :edit
30
+ end
31
+ end
32
+
16
33
  end
17
34
  end
@@ -1,3 +1,3 @@
1
1
  module DynamicMenu
2
- VERSION = "3.0.0.rc2"
2
+ VERSION = "3.0.0.rc3"
3
3
  end
data/lib/dynamic_menu.rb CHANGED
@@ -3,5 +3,6 @@ module DynamicMenu
3
3
  require "dynamic_menu/inheritable_menus.rb"
4
4
  require "dynamic_menu/base.rb"
5
5
  require "dynamic_menu/advanced_hash.rb"
6
+ require "dynamic_menu/advanced_array.rb"
6
7
  require "engine.rb"
7
8
  end
data/lib/engine.rb CHANGED
@@ -2,8 +2,9 @@ module DynamicMenu
2
2
  class Engine < ::Rails::Engine
3
3
  initializer "dynamic_menu.inheritable_menus" do |app|
4
4
  ActionView::Base.send :include, DynamicMenu::InheritableMenus
5
- ActionView::Base.send :include, DynamicMenu::AdvancedHash
6
- ActionController::Base.send :include, DynamicMenu::AdvancedHash
5
+ ActionView::Base.send :include, DynamicMenu::AdvancedObjects
6
+ ActionController::Base.send :include, DynamicMenu::AdvancedObjects
7
+ DynamicMenu::Base.send :include, DynamicMenu::AdvancedObjects
7
8
  end
8
9
  end
9
10
  end
@@ -1,7 +1,6 @@
1
1
  class <%= @menu_name.capitalize %>Menu < DynamicMenu::Base
2
2
  def build_menu
3
- Hash.new.tap do |menu|
4
- menu["Change Me"] = "http://example.com/change_the_url"
3
+ add link_to "Change me","#" if can? :read, All #change this line and add lines using add
5
4
  end
6
5
  end
7
6
  end
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: 3.0.0.rc2
4
+ version: 3.0.0.rc3
5
5
  prerelease: 6
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: 2013-07-12 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -50,6 +50,7 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - lib/dynamic_menu/advanced_array.rb
53
54
  - lib/dynamic_menu/advanced_hash.rb
54
55
  - lib/dynamic_menu/base.rb
55
56
  - lib/dynamic_menu/inheritable_menus.rb