class StageGenerator < Merb::GeneratorBase attr_reader :controller_class_name, :controller_file_name, :controller_base_path, :controller_modules, :full_controller_const, :attributes, :resource_name, :resource_class_name, :resource_title_name, :resource_plural_name def initialize(runtime_args, runtime_options = {}) @base = File.dirname(__FILE__) super name = runtime_args.shift @controller_file_name = name.pluralize.snake_case.gsub("::", "/") unless @controller_file_name == File.basename(@controller_file_name) @controller_base_path = controller_file_name.split("/")[0..-2].join("/") end @controller_modules = name.to_const_string.split("::")[0..-2] @controller_class_name = name.to_const_string.split("::").last.pluralize @resource_name = name.downcase @resource_class_name = @resource_name.to_const_string @resource_title_name = name.capitalize.snake_case @resource_plural_name = @resource_name.pluralize @full_controller_const = ((@controller_modules.dup || []) << @controller_class_name).join("::") @attributes = Hash[*(args.map{|a| a.split(":") }.flatten)] end def manifest record do |m| @m = m m.directory File.join("app/controllers", controller_base_path) if controller_base_path m.directory File.join("app/helpers", controller_base_path) if controller_base_path @assigns = { :controller_modules => controller_modules, :controller_class_name => controller_class_name, :controller_file_name => controller_file_name, :controller_base_path => controller_base_path, :full_controller_const => full_controller_const, :resource_name => resource_name} sentinel = 'Merb::Router.prepare do |r|' m.gsub_file 'config/router.rb', /(#{Regexp.escape(sentinel)})/mi do |match| "#{match}\n r.resources :#{resource_plural_name}\n" end copy_dirs copy_files end end protected def banner <<-EOS Stages a resources. This includes the following: DataMapper Model Resource Controller Resource Views Resource Helpers (contains presentation code utilized by View) Example merb-gen stage post title:string content:text created_at:datetime USAGE: #{$0} #{spec.name} name" EOS end def route(m, resource_name) end end