bootstrap_admin 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
@@ -20,105 +20,109 @@ module BootstrapAdmin::MenuHelper
|
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
# =============================================================================
|
24
|
+
def build_bootstrap_admin_menu_from_controller_names
|
25
|
+
namespace = BootstrapAdmin.admin_namespace
|
26
|
+
Dir["./app/controllers/#{namespace}/**/*.rb"].each do |controller|
|
27
|
+
require controller
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
yml_menu = AdminController.descendants.map do |controller|
|
31
|
+
ename = controller.name.demodulize.gsub("Controller","").singularize
|
32
|
+
"- :item: #{ename}"
|
33
|
+
end.join("\n")
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
@bootstrap_admin_menu_items = YAML.load(yml_menu)
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
@bootstrap_admin_menu_load_timestamp = Time.now
|
38
|
+
# =============================================================================
|
39
|
+
def load_bootstrap_admin_menu_items
|
40
|
+
@bootstrap_admin_menu_items = YAML.load_file(BOOTSTRAP_ADMIN_MENU_FILE)
|
41
|
+
unless @bootstrap_admin_menu_items
|
42
|
+
build_bootstrap_admin_menu_from_controller_names
|
45
43
|
end
|
44
|
+
@bootstrap_admin_menu_load_timestamp = Time.now
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
@bootstrap_admin_menu_items
|
47
|
+
# =============================================================================
|
48
|
+
def bootstrap_admin_menu_items
|
49
|
+
if @bootstrap_admin_menu_load_timestamp.nil? or
|
50
|
+
File.mtime(BOOTSTRAP_ADMIN_MENU_FILE) > @bootstrap_admin_menu_load_timestamp
|
51
|
+
load_bootstrap_admin_menu_items
|
54
52
|
end
|
53
|
+
@bootstrap_admin_menu_items
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
56
|
+
# =============================================================================
|
57
|
+
def bootstrap_admin_menu_item row
|
58
|
+
if respond_to?(:cannot?) && cannot?(:read, item_class(row))
|
59
|
+
"".html_safe
|
60
|
+
else
|
61
|
+
content_tag(:li) do
|
62
|
+
bootstrap_admin_menu_link row
|
64
63
|
end
|
65
64
|
end
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
# =============================================================================
|
68
|
+
def bootstrap_admin_menu_dropdown row
|
69
|
+
content_tag(:li, :class=>"dropdown", :"data-dropdown"=>"dropdown") do
|
70
|
+
bootstrap_admin_menu_link(row) +
|
71
71
|
content_tag(:ul, :class=>"dropdown-menu") do
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
72
|
+
row[:item].map do |sub|
|
73
|
+
if sub[:item].is_a? Symbol
|
74
|
+
bootstrap_admin_menu_separator sub
|
75
|
+
else
|
76
|
+
bootstrap_admin_menu_item sub
|
77
|
+
end
|
78
|
+
end.join.html_safe
|
80
79
|
end
|
81
80
|
end
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
# =============================================================================
|
84
|
+
def bootstrap_admin_menu_separator row
|
85
|
+
content_tag(:li, :class => row[:item]){""}
|
86
|
+
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
url = row[:url ] || "#"
|
97
|
-
css_class = row[:class] || "dropdown-toggle"
|
98
|
-
data_attr = { :toggle => "dropdown" }
|
99
|
-
|
100
|
-
|
101
|
-
else #then its a resource link.
|
102
|
-
model_class = if row[:namespace]
|
103
|
-
"#{row[:namespace]}::#{row[:item]}".classify.constantize
|
104
|
-
else
|
105
|
-
row[:item].classify.constantize
|
106
|
-
end
|
107
|
-
|
108
|
-
model_symbol = row[:item].underscore.pluralize.to_sym
|
109
|
-
|
110
|
-
label = if row[:label].is_a? Symbol
|
111
|
-
t row[:label]
|
112
|
-
else
|
113
|
-
row[:label] || model_class.model_name.human.pluralize
|
114
|
-
end
|
115
|
-
|
116
|
-
url = row[:url] || bootstrap_url_for(:controller => "#{row[:namespace] || BootstrapAdmin.admin_namespace}::#{row[:item]}".underscore.pluralize)
|
117
|
-
css_class = row[:class]
|
118
|
-
data_attr = {}
|
88
|
+
# =============================================================================
|
89
|
+
def bootstrap_admin_menu_link row
|
90
|
+
if row[:item].is_a? Array #then its a dropdown menu
|
91
|
+
label = if row[:label].is_a? Symbol
|
92
|
+
t row[:label]
|
93
|
+
else
|
94
|
+
row[:label]
|
119
95
|
end
|
96
|
+
url = row[:url ] || "#"
|
97
|
+
css_class = row[:class] || "dropdown-toggle"
|
98
|
+
data_attr = { :toggle => "dropdown" }
|
99
|
+
|
120
100
|
|
121
|
-
|
101
|
+
else #then its a resource link.
|
102
|
+
model_class = item_class row
|
103
|
+
|
104
|
+
label = if row[:label].is_a? Symbol
|
105
|
+
t row[:label]
|
106
|
+
else
|
107
|
+
row[:label] || model_class.model_name.human.pluralize
|
108
|
+
end
|
109
|
+
|
110
|
+
ctrl = (row[:controller] || "#{row[:namespace] || BootstrapAdmin.admin_namespace}::#{row[:item]}").underscore.pluralize
|
111
|
+
|
112
|
+
url = row[:url] || bootstrap_url_for(:controller => ctrl)
|
113
|
+
css_class = row[:class]
|
114
|
+
data_attr = {}
|
122
115
|
end
|
123
116
|
|
117
|
+
link_to label, url, :class => css_class, :data => data_attr
|
118
|
+
end
|
119
|
+
|
120
|
+
# =============================================================================
|
121
|
+
def item_class row
|
122
|
+
if row[:namespace]
|
123
|
+
"#{row[:namespace]}::#{row[:item]}".classify.constantize
|
124
|
+
else
|
125
|
+
row[:item].classify.constantize
|
126
|
+
end
|
127
|
+
end
|
124
128
|
end
|