class LoadbehindGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) IMAGES=["error", "growl_bottom", "growl_repeat", "growl_top", "info"] JAVASCRIPTS=["loadbehind", "jquery.growl"] def generate_loadbehind view_dir = "app/views/#{plural_name}" JAVASCRIPTS.each do |js| copy_file "#{js}.js", "public/javascripts/#{js}.js" end IMAGES.each do |image| copy_file "images/#{image}.png", "public/images/growl/#{image}.png" end ["index", "show"].each do |act| self.action_name = act template "view.js.haml", "#{view_dir}/#{action_name}.js.haml" end self.action_name = "show" template "view.js.haml", "#{view_dir}/update.js.haml" ["edit", "new"].each do |act| self.action_name = act template "edit.js.haml", "#{view_dir}/#{action_name}.js.haml" end ["destroy.js", "_errors.html"].each do |file| template "#{file}.haml", "#{view_dir}/#{file}.haml" end puts "**** Remember to add loadbehind.js and jquery.growl.js to the javascript tags, or add it to your own js files. You'll also need to add handling to see that all your events are reconnected each time you reload. " end attr_accessor :action_name end