#!/usr/bin/env ruby # copied from hobo and then modified. Some stuff is there because of that. require 'fileutils' require 'pathname' require 'rbconfig' require 'rvm' if not RVM.current puts "ruby or rvm 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. Options: --help # show this message VERSION: #{InlineForms::VERSION} " while true case arg_name = ARGV.shift 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" ruby_version = %x[rvm current] RVM.run "rails new #{app_name}" Dir.chdir(app_name) puts "\nWorking directory is now #{`pwd`}" puts "\nInstalling Gemfile...\n" gemfile_sources = " source 'http://rubygems.org' " gemfile_gems = " gem 'test-unit' gem 'rails' gem 'rake' gem 'jquery-rails' gem 'capistrano' gem 'will_paginate', :git => 'git://github.com/acesuares/will_paginate.git' gem 'tabs_on_rails' # , :git => 'git://github.com/acesuares/tabs_on_rails.git', :branch => 'add_remote' 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' gem 'mini_magick' gem 'jquery_datepicker' gem 'yaml_db' gem 'rails-i18n' gem 'unicorn' gem 'rvm' gem 'rvm-capistrano' " gemfile_development_group =" # Include everything needed to run rake, tests, features, etc. group :development do gem 'sqlite3' gem 'rspec-rails' gem 'shoulda', '>= 0' gem 'bundler' gem 'jeweler' # gem 'rcov', '>= 0' end " gemfile_production_group =" # these are just for production group :production do gem 'mysql2' gem 'therubyracer' gem 'uglifier' end " File.open( 'Gemfile', 'w') {|f| f.write(gemfile_sources + gemfile_gems + gemfile_development_group + gemfile_production_group ) } puts "\nCreating and trusting .rvmrc...\n" system "echo rvm use #{ruby_version.chop}@#{app_name} --create > .rvmrc" system "rvm rvmrc trust .rvmrc" RVM.use "#{ruby_version.chop}@#{app_name}" puts "\nRunning bundle...\n" RVM.run "bundle install" puts "\nDatabase setup: creating config/database.yml\n" development_stanza = " development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 " production_stanza = " production: adapter: mysql2 database: #{app_name}_p username: #{app_name} password: #{app_name}444 " File.open( 'config/database.yml', 'w') {|f| f.write(development_stanza + production_stanza) } puts "\nDevise install..." RVM.run "bundle exec rails g devise:install" puts "\nDevise User model install with added name field..." RVM.run "bundle exec rails g devise User name:string" puts "\nInstall ckeditor..." RVM.run "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..." RVM.run "bundle exec rails g paper_trail:install" puts "Migrating Devise and Versions" system('bundle exec rake db:migrate') 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 "Set application_name and _title in ApplicationHelper...\n" app_helper = " module ApplicationHelper def application_name #{app_name} end def application_title #{app_name} end end " File.open( 'app/helpers/application_helper.rb', 'w') {|f| f.write(app_helper) } puts "Overwriting application_controller...\n" app_cont = " class ApplicationController < ActionController::Base protect_from_forgery # before_filter :authenticate_user! # check_authorization :unless => :devise_controller? # rescue_from CanCan::AccessDenied do |exception| # sign_out :user if user_signed_in? # redirect_to new_user_session_path, :alert => exception.message # end end " File.open( 'app/controllers/application_controller.rb', 'w+') {|f| f.write(app_cont) } puts "Injecting precompile assets stuff in production.rb...\n" precomp = " \n \n # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) #{app_name}::Application.configure do config.assets.precompile += %w( inline_forms_application.js inline_forms_application.css devise.css ) # Fallback to assets pipeline if a precompiled asset is missed, we need this for ckeditor config.assets.compile = true # for devise config.action_mailer.default_url_options = { :protocol => 'https', :host => 'YOURHOSTNAME' } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => 'YOURMAILSERVER', :enable_starttls_auto => true, :password => 'YOURPASSWORD', :user_name => 'YOURUSERNAME' } end \n" File.open( 'config/environments/production.rb', 'a') {|f| f.write(precomp) } puts "Capify...\n" system('capify .') system("cp #{src}/lib/generators/templates/deploy.rb config/deploy.rb") puts "Unicorn Config...\n" system("cp #{src}/lib/generators/templates/unicorn.rb config/unicorn.rb") 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" puts "\nDon't forget: edit .rvmrc, config/{routes.rb, deploy.rb}, .git/config, delete public/index.html\n\n"