Class: Menus::DevelopmentMenu

Inherits:
Hash
  • Object
show all
Defined in:
app/models/crud/menus/development_menu.rb

Instance Method Summary collapse

Constructor Details

#initializeDevelopmentMenu

Returns a new instance of DevelopmentMenu.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/crud/menus/development_menu.rb', line 4

def initialize
  root_dir = Crud::Engine.root

  Dir.glob( File.join(root_dir, 'app', 'controllers', '**', '*_controller.rb') ).sort.each do |controller_file|
    controller_prefix = File.dirname( controller_file.gsub(/^.*controllers/, "").gsub(/^[\\\/]/, "") )
    controller_prefix = (controller_prefix.length == 1) ? '' : controller_prefix + '/'
    controller = File.basename(controller_file, ".rb")
    controller_object = controller.camelize

    model_prefix = controller_prefix.gsub(/^.*admin/,"").gsub(/^[\\\/]/, "")
    model = controller.gsub("_controller","").singularize
    model_object = model.camelize

    if File.exist?( File.join(root_dir, 'app', 'models', model_prefix, model + '.rb') )
      next if ['report'].include?(model)

      #link_text = t(model + '.object_name').to_s.humanize
      #link_text = t(model + '.object_name').to_s.humanize.pluralize
      link_text = model.to_s.humanize.pluralize
      controller_for_url = "#{controller_prefix}#{controller.gsub("_controller","")}"
      action_for_url = 'index'

      # Initialise section reference
      section = self

      controller_prefix.split(File::SEPARATOR).each do |sub_section|
        if section[sub_section].nil?
          section[sub_section] = Hash.new
          #section[sub_section]['name'] = sub_section.to_s.humanize
        end
        section = section[sub_section]
      end

      section = Hash.new if section.nil?
      section[controller] = Hash.new if section[controller].nil?
      section[controller]['name'] = link_text
      section[controller]['controller'] = controller_for_url
      section[controller]['action'] = action_for_url
    end
  end
end

Instance Method Details

#depth(menu = self, count = 0) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/crud/menus/development_menu.rb', line 46

def depth(menu = self, count = 0)
  count += 1

  menu.each do |key, value|
    break if value.class != Hash || value.has_key?('controller')

    tmp_depth = depth(value, count)
    count = tmp_depth if tmp_depth > count
  end

  count
end

#itemsObject



59
60
61
# File 'app/models/crud/menus/development_menu.rb', line 59

def items
  self
end