class NitroLayoutGenerator < Rails::Generator::NamedBase default_options :app_name => 'Web App', :layout_type => :administration, :theme => :default, :no_layout => false def initialize(runtime_args, runtime_options = {}) super @name = @args.first || 'application' end def manifest record do |m| if !options[:without_public] m.directory("app/views/admin/shared") m.directory("app/views/shared") m.directory("public/javascripts/admin") m.directory("public/stylesheets/themes/#{options[:theme]}/") m.directory("public/stylesheets/themes/default/") m.directory('app/controllers/admin') #adding layout m.template("admin/view_layout_#{options[:layout_type]}.html.erb", File.join("app/views/layouts", "admin.html.erb")) unless options[:no_layout] m.template("stylesheets/base.css", File.join("public/stylesheets", "base.css")) m.template("stylesheets/themes/#{options[:theme]}/style.css", File.join("public/stylesheets/themes/#{options[:theme]}", "style.css")) m.template("stylesheets/themes/default/style.css", File.join("public/stylesheets/themes/default", "style.css")) m.template("javascripts/jquery-1.3.min.js", File.join("public/javascripts", "jquery-1.3.min.js")) m.template("javascripts/application.js", File.join("public/javascripts/admin", "application.js")) m.template("admin/view_sidebar.html.erb", File.join("app/views/admin/shared", "_sidebar.html.erb")) m.template("view_sidebar.html.erb", File.join("app/views/shared", "_sidebar.html.erb")) m.template("app_helper.rb", File.join("app/helpers", "application_helper.rb")) # Layout and stylesheet. m.template('layout.html.erb', File.join('app/views/layouts', "application.html.erb")) m.template( 'admin/admin_controller.rb', File.join('app/controllers/admin', "admin_controller.rb") ) end end end protected # Override with your own usage banner. def banner "Usage: #{$0} nitro_layout" end def add_options!(opt) opt.separator '' opt.separator 'Options:' opt.on("--app_name=app_name", String, "") { |v| options[:app_name] = v } opt.on("--type=layout_type", String, "Specify the layout type") { |v| options[:layout_type] = v } opt.on("--theme=theme", String, "Specify the theme") { |v| options[:theme] = v } opt.on("--no-layout", "Don't create layout") { |v| options[:no_layout] = true } end end