#!/usr/bin/env ruby # copied from hobo and then modified. Some stuff is there because of that. require 'fileutils' require 'pathname' require 'rbconfig' RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"') if RUBY.empty? puts "ruby not found" exit 2 end Signal.trap("INT") { puts; exit } src = File.join(File.dirname(__FILE__), "..") require "#{src}/lib/inline_forms/version.rb" USAGE = " USAGE: inline_forms 'inline_forms MyApp' will create a rails app in directory MyApp. It will also try to create a MyApp_development mysql database and grant permissions on that database to user 'MyApp' identified by 'MyApp', unless you specify --skip-db-setup Options: --skip-db-setup # skip setup of mysql development database --help # show this message VERSION: #{InlineForms::VERSION} " skip_db_setup = false while true case arg_name = ARGV.shift when "--skip-db-setup" skip_db_setup = true when "--help" puts USAGE exit else app_name = arg_name break end end if !ARGV.empty? || app_name.nil? || !/^[a-zA-Z][0-9a-zA-Z_-]+/.match(app_name) || File.exists?(app_name) puts USAGE exit 1 end puts "\nGenerating Rails app '#{app_name}'...\n" system("#{RUBY} -S rails new #{app_name}") Dir.chdir(app_name) puts "\nWorking directory is now #{`pwd`}" puts "\nInstalling Gemfile and running Bundle...\n" gemfile_sources = " source 'http://rubygems.org' " gemfile_gems = " gem 'rails', '~> 3.1.0' gem 'rake' gem 'jquery-rails' gem 'mysql2' gem 'capistrano' gem 'will_paginate', :git => 'git://github.com/acesuares/will_paginate.git', :branch => 'rails3' gem 'tabs_on_rails' gem 'ckeditor', :git => 'git://github.com/acesuares/ckeditor.git', :branch => 'master' gem 'carrierwave' gem 'remotipart', '~> 1.0' gem 'paper_trail' gem 'devise' gem 'cancan' gem 'inline_forms' " gemfile_development_group =" # Include everything needed to run rake, tests, features, etc. group :development do gem 'rspec-rails' gem 'shoulda', '>= 0' gem 'bundler', '~> 1.0.0' gem 'jeweler', '~> 1.5.2' gem 'rcov', '>= 0' end " gemfile_production_group =" # these are just for production group :production do gem 'therubyracer' gem 'uglifier' end " File.open( 'Gemfile', 'w') {|f| f.write(gemfile_sources + gemfile_gems + gemfile_development_group + gemfile_production_group ) } system('bundle install') if skip_db_setup puts "\nDatabase setup skipped on your request!\n" else puts "\nDatabase setup: creating config/database.yml\n" development_stanza = " development: adapter: mysql2 database: #{app_name}_development username: #{app_name} password: #{app_name} " production_stanza = " production: adapter: mysql2 database: #{app_name}_production username: #{app_name} password: #{app_name}444 " File.open( 'config/database.yml', 'w') {|f| f.write(development_stanza + production_stanza) } puts "CREATE #{app_name}_development database" system("sudo mysqladmin create #{app_name}_development") puts "GRANT ALL ON #{app_name}_development.* to '#{app_name}'@'localhost' identified by '#{app_name}'" system("echo \"GRANT ALL ON #{app_name}_development.* to '#{app_name}'@'localhost' identified by '#{app_name}';\" | sudo mysql -v mysql") system('echo "FLUSH PRIVILEGES;" | sudo mysql mysql') end puts "\nDevise install..." system('bundle exec rails g devise:install') puts "\nDevise User model install with added name field..." system('bundle exec rails g devise User name:string') puts "\nInstall ckeditor..." system('bundle exec rails g ckeditor:install') puts "Create config file in app/assets/javascripts/ckeditor/config.js" FileUtils.mkdir_p 'app/assets/javascripts/ckeditor' system("cp #{src}/lib/app/assets/javascripts/ckeditor/config.js app/assets/javascripts/ckeditor") puts "Add remotipart to app/assets/javascripts/application.js..." system('echo >> app/assets/javascripts/application.js') system('echo "//= require jquery.remotipart" >> app/assets/javascripts/application.js') system('echo >> app/assets/javascripts/application.js') puts "Paper_trail install..." system('bundle exec rails g paper_trail:install') if skip_db_setup puts "Migrations skipped on your request!\n" else puts "Migrating Devise and Versions" system('bundle exec rake db:migrate') end puts "Creating header in app/views/inline_forms/_header.html.erb...\n" header_src = " " FileUtils.mkdir_p 'app/views/inline_forms' File.open( 'app/views/inline_forms/_header.html.erb', 'w') {|f| f.write(header_src) } puts "Capify...\n" system('capify .') puts "Initializing git...\n" system('git init') system('echo >> .gitignore') system('echo "nbproject" >> .gitignore') system('echo "public/uploads" >> .gitignore') system('echo >> .gitignore') system('git add .') system('git commit -a -m " * Initial"') puts "\n\nDone! Now make your tables with 'rails g inline_forms ...\n\n\n"