require 'rails/generators' module DynamicMenu class MenuGenerator < Rails::Generators::Base source_root File.expand_path('../templates',__FILE__) def generate_menu @args[0] =~ /(.+):.+/i file = $1 dir = "app/menus/#{file}" Dir.mkdir(dir) unless File.exists?(dir) @args[0] =~ /.+:(.+)/i @menu_name = $1 template "menu.rb", "app/menus/#{file}/#{@menu_name}.rb" end end end