Created
June 17, 2012 04:44
-
-
Save chsh/2943435 to your computer and use it in GitHub Desktop.
Rails3 template to generate facebook app.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# facebootstrap: Rails3 template | |
app_h_name = app_name.gsub(/_/, '-') | |
app_c_name = app_name.classify | |
ruby_version = '1.9.3-p286' | |
repository_path = "[email protected]:chsh/#{app_h_name}.git" | |
target_branch = 'develop' # or master etc... | |
deploy_server = '[YOUR DEPLOY SERVER]' | |
target_mode = 'edge' # or 'live' or 'develop' etc... | |
# additional_path = '/usr/pgsql-9.1/bin' | |
# When you use codeplane, specify your name and key. | |
# codeplane = { | |
# username: '[CODEPLANE USER NAME]', | |
# api_key: '[CODE PLANE API KEY]' | |
# } | |
db_config = { | |
user: '[DATABASE USER NAME]', | |
password: '[DATABASE USER PASSWORD]' | |
} | |
# some functions | |
def get_ssl(url) | |
open(url,"r",{:ssl_verify_mode=>OpenSSL::SSL::VERIFY_NONE}).read | |
end | |
def get_ssl_with_keys(url, keys = {}) | |
content = get_ssl(url) | |
content.gsub(/@@(.+?)@@/) do |match| | |
keys[$1.downcase.to_sym] | |
end | |
end | |
git :init | |
append_file '.gitignore', <<-EOL | |
/config/database.yml | |
/config/settings/production.rb | |
/config/settings/development.rb | |
/config/*.production | |
/public/system | |
EOL | |
gem 'therubyracer', group: :assets | |
gem 'bootstrap-sass', group: :assets | |
gem 'font-awesome-sass-rails' | |
gem 'slim-rails' | |
gem 'formtastic', | |
git: 'git://github.com/justinfrench/formtastic.git', | |
branch: '2.1-stable' | |
gem 'formtastic-bootstrap', | |
git: 'https://github.com/cgunther/formtastic-bootstrap.git', | |
branch: 'bootstrap2-rails3-2-formtastic-2-1' | |
gem 'configuration' | |
gem 'devise' | |
gem 'omniauth' | |
gem 'omniauth-facebook' | |
gem 'koala' | |
gem 'unicorn' | |
gem 'capistrano' | |
gem 'thin', group: :development | |
require 'open-uri' | |
# generate capistrano settings. | |
create_file 'Capfile' do | |
<<EOL | |
load 'deploy' | |
load 'deploy/assets' | |
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
load 'config/deploy' # remove this line to skip loading any of the default tasks | |
EOL | |
end | |
repo_prefix = 'https://raw.github.com/chsh/facebootstrap-for-template/master' | |
create_file 'config/deploy.rb' do | |
get_ssl_with_keys "#{repo_prefix}/config/deploy.rb.template", { | |
app_name: app_h_name, | |
repository_path: repository_path, | |
target_branch: target_branch, | |
deploy_server: deploy_server, | |
target_mode: target_mode, # or 'live' | |
ruby_version: ruby_version, | |
additional_path: additional_path | |
} | |
end | |
run 'mkdir config/deploy' | |
## install deploy modules. | |
# config symlink module | |
create_file 'config/deploy/config.rb' do | |
get_ssl_with_keys "#{repo_prefix}/config/deploy/config.rb.template", { | |
yaml_files: 'database.yml' | |
} | |
end | |
# unicorn.module | |
create_file 'config/deploy/unicorn.rb' do | |
get_ssl_with_keys "#{repo_prefix}/config/deploy/unicorn.rb.template" | |
end | |
# unicorn server config | |
create_file 'config/unicorn.rb' do | |
get_ssl_with_keys "#{repo_prefix}/config/unicorn.rb.template" | |
end | |
create_file '.rvmrc' do | |
"rvm use #{ruby_version} --create" | |
end | |
run "bundle" | |
## setup database. | |
run 'cp config/database.yml config/database.yml.example' | |
if defined? db_config | |
remove_file 'config/database.yml' | |
create_file 'config/database.yml' do | |
<<EOL | |
development: | |
adapter: postgresql | |
encoding: unicode | |
database: #{app_name}_d | |
pool: 5 | |
username: #{db_config[:user]} | |
password: #{db_config[:password]} | |
test: | |
adapter: postgresql | |
encoding: unicode | |
database: #{app_name}_t | |
pool: 5 | |
username: #{db_config[:user]} | |
password: #{db_config[:password]} | |
EOL | |
end | |
end | |
# add lib/utils to auto load paths. | |
inject_into_file 'config/application.rb', after: /# config¥.autoload_paths.+?¥n/ do | |
<<EOL | |
config.autoload_paths += %W(¥#{config.root}/lib/utils) | |
EOL | |
end | |
remove_file 'app/views/layouts/application.html.erb' | |
git add: '.', commit: '-m "Initial commit"' | |
rake 'db:create' | |
###### create devise related files | |
generate 'devise:install' | |
generate 'devise', 'User' | |
run 'mkdir app/controllers/users' | |
# omniauth_callbacks | |
%w( | |
app/assets/stylesheets/layouts.css.scss | |
app/controllers/users/omniauth_callbacks_controller.rb | |
app/controllers/users/sessions_controller.rb | |
app/views/layouts/application.html.slim | |
app/models/facebook.rb | |
config/initializers/configuration.rb | |
config/initializers/formtastic.rb | |
config/initializers/fix_openssl_verification_error.rb | |
config/settings/application.rb | |
config/settings/development.rb | |
config/settings/production.rb | |
lib/utils/config_or_env.rb | |
lib/utils/hash_with_method.rb | |
).each do |path| | |
create_file path do | |
get_ssl_with_keys "#{repo_prefix}/#{path}", { | |
app_c_name: app_c_name | |
} | |
end | |
end | |
gsub_file 'config/routes.rb', /devise_for :users/ do |match| | |
<<EOL | |
devise_for :users, controllers: { | |
omniauth_callbacks: "users/omniauth_callbacks", | |
sessions: 'users/sessions' | |
} | |
EOL | |
end | |
# replace auto-generated migration file which has unknown name. | |
run "wget -q -O db/migrate/*.rb #{repo_prefix}/db/migrate/devise_create_users.rb" | |
remove_file 'app/models/user.rb' | |
create_file 'app/models/user.rb' do | |
get_ssl_with_keys "#{repo_prefix}/app/models/user.rb" | |
end | |
inject_into_file 'config/initializers/devise.rb', before: /^end/ do | |
<<EOL | |
config.omniauth :facebook, Facebook::Config.app_id, Facebook::Config.app_secret, | |
scope: Facebook::Config.app_scope | |
EOL | |
end | |
git add: '.', commit: '-m "Add authentication related files."' | |
## remote repository integration | |
if defined? codeplane | |
require 'codeplane' | |
Codeplane.configure do |config| | |
config.username = codeplane[:username] | |
config.api_key = codeplane[:api_key] | |
end | |
cp = Codeplane::Client.new | |
repo = cp.repositories.create(name: app_h_name) | |
if repo.id.nil? | |
puts "CodePlane repository:#{app_h_name} creation failed." | |
else | |
puts "CodePlane repository:#{app_h_name} created" | |
run "git remote add origin #{repository_path}" | |
git push: 'origin master' | |
end | |
end | |
git flow: 'init -d' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment