lib/generators/effective/menu_generator.rb in effective_developer-0.0.10 vs lib/generators/effective/menu_generator.rb in effective_developer-0.1.1
- old
+ new
@@ -16,37 +16,63 @@
say_status :invoke, :menu, :white
end
def create_menu
begin
- Effective::CodeWriter.new((['app/views'] + namespaces + ['_navbar.html.haml']).join('/')) do |w|
- if w.find { |line, _| line == content.last.strip }
- say_status :identical, index_path, :blue
+ Effective::CodeWriter.new((['app/views'] + resource.namespaces + ['_navbar.html.haml']).join('/')) do |w|
+ if w.find { |line, _| line == menu_content.last.strip }
+ say_status :identical, resource.index_path, :blue
else
index = w.last { |line, _| line.start_with?('- if can?') }
if index.blank?
say_status(:skipped, :menu, :yellow) and return
end
- w.insert_raw(content, index+1, w.depth_at(index))
- say_status :menu, index_path, :green
+ w.insert_raw(menu_content, index+1, w.depth_at(index))
+ say_status :menu, resource.index_path, :green
end
end
rescue Errno::ENOENT
# This will raise an error if the navbar file isn't present
say_status :skipped, :menu, :yellow
end
end
+ def create_effective_menus
+ begin
+ Effective::CodeWriter.new('lib/tasks/generate/effective_menus.rake') do |w|
+ if w.find { |line, _| line == effective_menus_content }
+ say_status :identical, resource.index_path, :blue
+ else
+ index = w.first { |line, _| line.start_with?('item') }
+
+ w.insert(effective_menus_content, index)
+
+ system('rake generate:effective_menus')
+
+ say_status :effective_menus, resource.plural_name + '_path', :green
+ end
+ end
+ rescue Errno::ENOENT
+ # This will raise an error if the navbar file isn't present
+ say_status :skipped, :effective_menus, :yellow
+ end
+ end
+
private
- def content
+ def menu_content
[
"\n",
- "- if can? :manage, #{class_name}",
- " %li= link_to '#{plural_name.titleize}', #{index_path}"
+ "- if can? :manage, #{resource.class_name}",
+ " %li= link_to '#{resource.plural_name.titleize}', #{resource.index_path}"
]
end
+
+ def effective_menus_content
+ "item '#{resource.plural_name.titleize}', :#{resource.plural_name}_path"
+ end
+
end
end
end