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
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/navigator_rails/navigatable.rb', line 16
def path='/head/left'
= self.to_s.sub(/Controller$/,'')
self.navigator_rails_items ||= []
methods = []
methods << 'index' if self.action_methods.include? 'index'
methods << 'new' if self.action_methods.include? 'new'
methods << 'show' if self.action_methods.include? 'show'
methods << 'edit' if self.action_methods.include? 'edit'
methods << 'destroy' if self.action_methods.include? 'destroy'
methods += (self.action_methods.to_a - methods)
methods.each do |action|
params = {}
params[:constraint] = NavigatorRails.config[:default_constraint].to_s
params[:constraint] += ' and user_signed_in? ' if NavigatorRails.config[:use_devise]
case action.to_sym
when :create, :update
next
when :index
path_helper_string = "#{}Url".underscore
label = action
when :destroy
params[:constraint] += " and @#{.singularize.underscore} != nil"
path_helper_string = "@#{.singularize}, method: :delete".underscore
label = "#{action} \#{@#{.singularize.underscore}.to_s}"
when :show
params[:constraint] += " and @#{.singularize.underscore} != nil"
path_helper_string = "@#{.singularize}".underscore
label = "#{action} \#{@#{.singularize.underscore}.to_s}"
when :edit
params[:constraint] += " and @#{.singularize.underscore} != nil"
path_helper_string = "#{action.classify}#{.singularize}Url(@#{.singularize})".underscore
label = "#{action} \#{@#{.singularize.underscore}.to_s}"
else
path_helper_string = "#{action.classify}#{.singularize}Url".underscore
label = action
end
params[:path] = "#{path}/#{}/#{action}"
params[:content] = "link_to(\"#{label}\",#{path_helper_string})"
self.navigator_rails_items << Item.new(params)
end
end
|