Skip to content

Instantly share code, notes, and snippets.

@exocode
Last active December 16, 2015 21:59
Show Gist options
  • Save exocode/5504194 to your computer and use it in GitHub Desktop.
Save exocode/5504194 to your computer and use it in GitHub Desktop.
SETUP your advanced Ruby on Rails app in seconds. This generator-setup-script which I call "MegaGen" provides a complete automatic setup of mongoid, mySQL, pg, Guard, rSpec, Cucumber, Shoulda Matchers, Capybara, fabrication, factory_girl, haml, amazon-aws, omniauth, devise, cancan, carrierwave, paperclip, and more. Simply choose your desired add…
####
# Copyright by mediatainemnt-productions.com
# Created by Jan Jezek
# 2012
############################
## PLUGIN
#########
## plugin will install a plugin into the current application
# plugin("dynamic-form", :git => "git://github.com/rails/dynamic-form.git")
## GEM #
#########
## Specifies a gem dependency of the application.
# gem("rspec", :group => "test", :version => "2.1.0")
# gem("devise", "1.1.5")
## GEM IN GROUPS #
##################
## Wraps gem entries inside a group
# gem_group :development, :test do
# gem "rspec-rails"
# end
## ADD SOURCE TO GEMFILE #
##########################
## Adds a specified source to Gemfile
# add_source "http://gems.github.com"
## APPLICATION #
################
## Adds a line to config/application.rb directly after the application class definition
# application "config.asset_host = 'http://example.com'"
# can also take a block
# application do
# "config.asset_host = 'http://example.com'"
# end
# available options are
# application(nil, :env => "development") do
#   "config.asset_host = 'http://localhost:3000'"
# end
## GIT #
########
## Runs the specified git command:
# git :init
# git :add => "."
# git :commit => "-m First commit!"
# git :add => "onefile.rb", :rm => "badfile.cxx"
## SHELL USAGE #
################
# run "rm README.rdoc public/index.html app/assets/images/rails.png"
## VENDOR #
###########
## Places a file into vendor which contains the specified
# vendor("sekrit.rb", '#top secret stuff')
# vendor("seeds.rb") do
#   "puts 'in ur app, seeding ur database'"
# end
## LIB #
########
## Places a file into lib which contains the specified code.
# lib("special.rb", 'p Rails.root')
# lib("super_special.rb") do
#   puts "Super special!"
# end
## RAKE #
#########
## Creates a Rake file in the lib/tasks directory of the application
# rakefile("test.rake", 'hello there')
## or as a block
# rakefile("test.rake") do
#   %Q{
#     task :rock => :environment do
#       puts "Rockin'"
#     end
#   }
# end
#
## INITIALIZER #
################
## Creates an initializer in the config/initializers directory of the application:
# initializer("begin.rb", "puts 'this is the beginning'")
# initializer("begin.rb") do
#   puts "Almost done!"
# end
## GENERATE #
#############
## Runs the specified generator where the first argument is the generator name and the remaining arguments are passed directly to the generator
# generate("scaffold", "forums title:string description:text")
## RAKE #
#########
## Runs the specified Rake task
# rake("db:migrate")
## ROUTE #
##########
## Adds text to the config/routes.rb file:
# route("resources :people")
## README #
###########
## Output the contents of a file in the template’s source_path, usually a README.
# readme("README")
########################################################
########################################################
require 'fileutils'
## Helpers
def content_changer(file_in, pattern, insert)
File.write(f = file_in, File.read(f).gsub(pattern.to_s, insert.to_s))
end
def comment_out(file_in, pattern)
content_changer(file_in, pattern, ("# "+pattern))
end
def comment_in(file_in, pattern)
content_changer(file_in, ("# "+pattern), pattern)
end
def insert_before(file_in, pattern, insert)
content_changer(file_in, pattern, (insert + "\n" + pattern))
end
def insert_after(file_in, pattern, insert)
content_changer(file_in, pattern, (pattern + "\n" + insert))
end
def method_missing(m, *args, &block)
return false
end
def add_requirement(file_in, text_to_prepend)
file = IO.read(file_in)
open(file_in, 'w') { |f| f << (text_to_prepend+"\n") << file }
end
def mark_content(file_in, start_content_to_cut, end_content_to_cut)
#TODO
str.sub /#{end_content_to_cut}.+/, end_content_to_cut
end
def cut_content_and_return(file_to_cut, start_content_to_cut, end_content_to_cut)
#TODO
end
def content_mover(file_to_cut, start_content_to_cut, end_content_to_cut, file_to_place, content_put_after )
#TODO
insert_after(file_to_place, content_put_after)
end
#### PLEASE COMPLETE THIS CODE
#def move_content(file_in, regex_to_move, insert_point)
# regex_to_move ="RSpec.configure do \|config\|((.|\n)*?)end\n"
# content_changer(file_in, pattern, insert_point)
#end
##################
# Basic Settings #
##################
# Host
rails3 = yes? "Rails 3? (4=empty)"
if rails3
rails3 = true
else
rails3 = false
end
osx = ask "Your operating System OSX= leave empty || [yes] for windows"
osx = true if osx
host_name = ask "Host for production Site? Example: http://www.example.com"
heroku = yes? "Deploying on heroku?"
# Server
localserver = ask "Which Server do you wanna use in development? [thin] || [webrick]=default"
(thin = true) if (localserver == "thin")
# Index page
puts "Scaffolding an INDEX Controller an INDEX Model, INDEX view and point root to index!"
indexpage = true
# Usermodel
user_model_name = ask("What would you like the user model to be called? [user]=default")
user_model_name = "user" if user_model_name.blank?
user_model_parameters = ask("Please provide the parameters for your User model")
user_model_parameters = "" if user_model_parameters.blank?
# Database #
if yes?("DROP DATABASE FOR THIS PROJECT?")
if yes?("ARE YOU SURE TO DELETE???")
rake "db:drop"
end
end
database = ask "Which Database? [mongo] [mysql2] [pg]"
case database
when "mongo"
mongo = true
mongo_session = true if yes? "Do you wanna have mongo-session-store? (only for mongoid2)"
when "mysql2"
mysql = true
when 'pg'
postgres = true
end
# active admin
active_admin = yes? "Wanna use ACTIVE ADMIN?"
if active_admin
active_admin = true
end
# Testing
testing = yes? "Wanna deactivate Testing System?"
unless testing
testing = true
spork = true unless yes? "Deactivate Spork?"
rspec = true unless yes? "Deactivate rSpec?"
cucumber = true unless yes? "Deactivate Cucumber?"
guard = true unless yes? "Deactivate Guard?"
minitest = true if yes? "minitest?"
capybara = true unless yes? "Deactivate Capybara?" if rspec
shoulda = true unless yes? "Deactivate Shoulda Matchers?" if rspec
puts "[fac] = factory_girl || [fab] = fabrication"
mocking = ask "Which MOCKING you prefer? (keep empty for none)"
case mocking
when "fac"
factory_girl = true
when "fab"
fabrication = true
end
puts "factory_girl: " + factory_girl.to_s
puts "fabrication: " + fabrication.to_s
new_relic = true if yes? "NewRelic?"
end
# Layout
if yes?('Wanna delete a Layout?')
delete_layout = true
end
# CSS Functions and Framework
unless yes?('Deactivate COMPASS?')
compass = true
end
unless yes?('Deactivate TWITTER BOOTSTRAP')
bootstrap = true
end
# Attachment handling
attachment = ask 'Which attachment System do you wanna provide? [paperclip] || [carrierwave]?'
case attachment
when "paperclip"
paperclip = true
when 'carrierwave'
carrierwave = true
if yes? 'Would you like to use Carrierwave in the S3 cloud?'
carrierwave_aws = true
end
if yes? 'Would you like the Image Attachment System "Attachinary"?'
attachinary = true
end
end
## Authentication System
if yes?("Would you like an User AUTHENTICATION system?")
puts "DEVISE => [devise]"
authsystem = ask "Which one? devise = default"
case authsystem
when "devise"
devise = true
if yes?('Wanna use your own Devise views?')
own_devise_views = yes
end
else
devise = true
end
puts "devise: " + devise.to_s
if authsystem
if yes? "Also wanna FB, Twitter, Google,... authentication?"
puts "OMNIAUTH [omni]"
omnisystem = ask "Which one you wanna have? omniauth = default "
case omnisystem
when "omni"
omniauth = true
else
omniauth = true
end
end
puts "omniauth: " + omniauth.to_s
# ROLE SYSTEM
if yes? 'Would you provide a RoleSystem?'
puts "CANCAN => [can]"
rolesystem = ask "Which RoleSystem? cancan = default"
case rolesystem
when "can"
cancan = true
else
cancan = true
end
puts "cancan: " + cancan.to_s
end
end
end
# tree system
tree = true if yes? "Wanna have a tree system?"
if tree
puts "mongoid-tree [mongo_tree]" if mongo
puts "mongoid-tree [acts_as_tree]" if mysql || pg
tree_system = ask "Which one?"
end
# Geocoding
if yes?('Wanna use a GEOCODER?')
geocoding = true
end
# Easier writing HTML CODE?
if yes?('Wanna use HAML?')
haml = true
end
# Pagination System
pagination = ask 'Which pagination System you prefer (leave blank for nothing) [1]willpaginate || [2]kaminari'
if pagination == "1"
willpaginate = true
end
if pagination == "2"
kaminari = true
end
################
# PUTTING GEMS #
################
# DBs
gem 'pg' if postgres
gem 'mysql2' if mysql
gem 'mongoid', "~> 3.0.0" if mongo && rails3
gem 'mongoid', github: 'mongoid/mongoid' if mongo && !rails3
gem 'mongoid_session_store', :git => "https://github.com/hayesr/mongoid_session_store.git" if mongo_session
gem 'mongoid-tree', :require => 'mongoid/tree' if tree_system == "mongoid_tree"
gem 'activeadmin' if active_admin && (pg || mysql2)
gem 'activeadmin-mongoid' if mongoid
# Server
gem 'thin' if thin
gem 'haml' if haml
# Performance
gem 'newrelic_rpm' if new_relic
# Attachment
if paperclip || carrierwave
gem 'paperclip' if paperclip
gem 'carrierwave' if carrierwave
gem "mongoid-paperclip", :require => "mongoid_paperclip" if mongoid
gem 'carrierwave-aws' if carrierwave_aws
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid' if carrierwave && mongo # extension for mongoid
if attachinary
gem 'cloudinary' # carrierwave extension for images in the cloud
gem 'attachinary' # cloudinary attachment handler
end
end
# Authtentication
if devise || omniauth
gem "devise" if devise
if omniauth
gem "omniauth"
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem "fb_graph"
end
end
# RoleSystem
if cancan || acl9 || decau
gem 'cancan' if cancan
end
# Geocoding
gem "geocoder" if geocoder
# Pagination
gem "kaminari" if kaminari
# Cateogry Management
gem 'acts_as_tree' if tree_system == "acts_as_tree" # self_referenced table tool
gem 'will_paginate', '~> 3.0' if tree_system == "will_paginate"
gem_group :assets do
gem 'compass-960-plugin' if compass # Plugin for compass and 960.gs
gem "twitter-bootstrap-rails" if bootstrap && !compass
gem 'bootstrap-datepicker-rails' if bootstrap
gem 'bootstrap-timepicker-rails' if bootstrap
end
gem 'bootstrap-sass' if bootstrap && compass
if compass
gem 'compass-rails' if rails3 # implementation for rails
gem 'compass-rails', github: 'milgner/compass-rails', branch: 'rails4' unless rails3
end
gem_group :production do
end
gem_group :test do
gem 'cucumber-rails', :require => false if cucumber # cucumber use case testing
gem 'email_spec' if rspec # collection of RSpec matchers and Cucumber steps to make testing emails go smoothly
gem 'spork' if spork
gem 'factory_girl' if factory_girl
gem 'database_cleaner' if spork
gem "shoulda" if shoulda && rspec
gem "minitest" if minitest
end
gem_group :development, :test do
gem "rspec-rails" # rspec unit testing
gem 'fabrication' if fabrication
# Spork
if testing
gem "spork-rails" if spork
gem 'capybara' if capybara
end
if guard
gem 'guard'
gem 'rb-fsevent', '~> 0.9', :require => "guard" if osx
gem 'guard-compass', :require => "guard" if compass
gem 'guard-cucumber', :require => "guard" if cucumber
gem 'guard-rspec', :require => "guard" if rspec
gem 'guard-rails-assets', :require => "guard"
gem 'guard-sass', :require => "guard"
gem 'guard-spork', :require => "guard" if spork
gem 'guard-livereload', :require => "guard" if livereload
gem 'ruby_gntp' if osx
end
end
gem_group :development do
end
run 'bundle install'
###############
#### Tasks ####
###############
# Server
application 'config.assets.initialize_on_precompile = false' if heroku
application '## HEROKU Specific' if heroku
# Testing Setup
if rspec
generate "rspec:install"
add_requirement(".rspec", "\n--drb\n") if spork
comment_out "spec/spec_helper.rb", "config.use_transactional_fixtures" if mongo
puts "# commented out use_transactional_fixtures" if mongo
insert_after "spec/spec_helper.rb", "config.mock_with :rr", "config.mock_with :rspec"
end
if testing
# CUCUMBER
if cucumber
puts "# CUCUMBER"
FileUtils.mkdir_p "features/support"
puts "# created features/support folder"
if capybara
cuca = "--capybara "
else
cuca = ""
end
if rspec
curs = "--rspec "
else
curs = ""
end
if spork
cusp = "--spork "
else
cusp = ""
end
cucumber_options = cuca + curs + cusp
generate "cucumber:install", cucumber_options
if mongo
content_changer "features/support/env.rb", "DatabaseCleaner.strategy = :transaction", "DatabaseCleaner.strategy = :truncation"
end
if capybara
comment_in "features/support/env.rb", "Capybara.default_selector = :xpath"
content_changer "features/support/env.rb", "Capybara.default_selector = :xpath", "Capybara.default_selector = :css"
end
end
# SPORK
if spork
run "spork rspec --bootstrap" if rspec
puts "# Spork RSPEC bootstrapped" if rspec
run "spork cucumber --bootstrap" if cucumber
puts "# Spork cucumber bootstrapped" if cucumber
if capybara
insert_after "spec/spec_helper.rb", "Spork.prefork do", " require 'capybara/rspec'" if rspec
insert_after "features/support/env.rb", "Spork.prefork do", "require 'capybara/cucumber'" if cucumber
puts "# Placed capbyara requirements in Spork prefork"
end
if factory_girl
puts "# Installing factory_girl"
insert_after "features/support/env.rb", "Spork.prefork do", "require 'factory_girl_rails'"
insert_after "spec/spec_helper.rb", "Spork.each_run do", 'include ActionDispatch::TestProcess' if paperclip && rspec
insert_after "spec/spec_helper.rb", "Spork.each_run do", 'Dir.glob("#{::Rails.root}/spec/factories/*.rb").each { |file| load "#{file}" }' if rspec
insert_after "spec/spec_helper.rb", "Spork.each_run do", 'FactoryGirl.reload' if rspec
insert_after "spec/spec_helper.rb", "Spork.each_run do", "FactoryGirl.factories.clear" if rspec
insert_after "spec/spec_helper.rb", "Spork.each_run do", 'require "factory_girl_rails"' if rspec
puts "# Installed factory_girl for SPORK"
end
end
if fabrication
if rspec
insert_after "config/application.rb", "class Application < Rails::Application", " # Fabrication Gem
config.generators do |g|
g.test_framework :rspec, fixture: true
g.fixture_replacement :fabrication
end"
end
if minitest
insert_after "config/application.rb", "class Application < Rails::Application", ' # Fabrication Gem
config.generators do |g|
g.test_framework :mini_test, fixture_replacement: :fabrication
g.fixture_replacement :fabrication, dir: "test/fabricators"
end'
end
if (minitest || fabrication) && rspec
(insert_after "config/application.rb", "config.generators do |g|", " g.orm :mongoid") if mongo
insert_after "config/application.rb", "config.generators do |g|", " g.fixture_replacement :factory_girl, dir: 'spec/support/factories'" if factory_girl
end
puts "# fabrication config added to config/application.rb"
generate "fabrication:cucumber_steps" if fabrication
end
if rspec
FileUtils.mkdir_p "spec/support"
run "rm -R test"
puts "# removed test/ folder & content"
insert_after "spec/spec_helper.rb", "Spork.prefork do", " require 'rails/mongoid'" if mongo
insert_after "spec/spec_helper.rb", "Spork.prefork do", " require 'capybara/rspec'\n require 'capybara/rails'" if capybara
insert_after "spec/spec_helper.rb", "Rspec.configure do |config|", " config.include HelperMethods\n config.include Mongoid::Matchers"
if devise
File.write("spec/support/devise.rb", "RSpec.configure do |config|\n config.include Devise::TestHelpers, :type => :controller\nend")
end
end
if mongo
File.write(f = "config/environments/test.rb", File.read(f).gsub('config.active_record.mass_assignment_sanitizer', "#config.active_record.mass_assignment_sanitizer"))
insert_after "spec/spec_helper.rb","RSpec.configure do |config|","\n config.before(:each) do\n Mongoid.purge!\n end"
end
if nokogiri
run "gem install nokogiri -- --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local" if osx
insert_after "spec/spec_helper.rb", "Spork.prefork do", " ENV['RAILS_ENV'] ||= 'test'" if rspec
insert_after "spec/spec_helper.rb", "Spork.prefork do", " require 'rails/application'" if rspec
run "bundle install"
end
# GUARD
if guard
run "bundle exec guard init spork" if spork
run "bundle exec guard init rspec" if rspec
run "bundle exec guard init cucumber" if cucumber
end
end
# Database
if mongo
#run "rm config/database.yml"
comment_out "config/environments/development.rb", "config.active_record.mass_assignment_sanitizer"
comment_out "config/environments/development.rb", "config.active_record.auto_explain_threshold_in_seconds"
comment_out "config/application.rb", "config.active_record.whitelist_attributes"
#content_changer "Gemfile", "gem 'sqlite3'", ""
generate "mongoid:config"
initializer "mongoid.rb" do
'Mongoid.load!(Rails.root.to_s+"/config/mongoid.yml")'
end
generate "mongoid:devise" if devise
comment_out "spec/spec_helper.rb", "config.fixture_path" if rspec
# File.write(f = "spec/spec_helper.rb", File.read(f).gsub('config.fixture_path', "#config.fixture_path"))
# comment_out "config/application.rb", "require 'rails/all'"
# add_requirement "config/application.rb", "require 'action_controller/railtie'"
# add_requirement "config/application.rb", "require 'action_mailer/railtie'"
# add_requirement "config/application.rb", "require 'active_resource/railtie'"
# add_requirement "config/application.rb", "require 'sprockets/railtie'"
comment_out "config/application.rb", "config.active_record.mass_assignment_sanitizer" if testing
end
# COMPASS
if compass
initializer("begin.rb") do
puts "require 'compass'\nrequire 'compass/app_integration/rails'\nrequire 'fileutils'"
end
# FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))
end
# Index Controller
if indexpage
generate "controller", "Index index"
route "root :to => 'index#index'"
end
# Layout
if delete_layout
run "rm app/views/layouts/application.html.erb"
puts "# Deleted layout!"
else
insert_after "app/views/layouts/application.html.erb", "<body>", '<p class="notice"><%= notice %></p>'
insert_after "app/views/layouts/application.html.erb", "<body>", '<p class="alert"><%= alert %></p>'
puts "# inserted alert & notice to layout"
end
# BOOTSTRAP
if bootstrap
if File.exists? "app/assets/stylesheets/application.css"
File.rename "app/assets/stylesheets/application.css", "app/assets/stylesheets/application.scss"
end
File.write(f = "app/assets/stylesheets/application.scss", File.read(f).gsub(" */", " */\n@import 'bootstrap';")) if bootstrap
end
run "bundle install" if compass
run "bundle exec compass init rails" if compass
generate "scaffold", (user_model_name.to_s + " " + user_model_parameters.to_s) if mysql || pg
## Devise
if devise
application "config.case_insensitive_keys = [:email]"
application "# Settings for Devise"
application nil, :env => "production" do
"config.action_mailer.default_url_options = { :host => '#{host_name}' }"
"# Setting for Devise"
""
end
generate "devise:install"
puts "# generated devise:install"
generate "devise", (user_model_name.to_s)
puts "# generated devise user model"
generate "devise:views", user_model_name
puts "# generated devise views"
if own_devise_views
comment_in "config/initializers/devise.rb", "config.scoped_views"
content_changer("config/initializers/devise.rb", "config.scoped_views = false", "config.scoped_views = false")
end
end
## Scaffold User
# do this also when devise
if mongo && devise
insert_after "spec/controllers/users_controller_spec.rb", "describe UsersController do", " include Devise::TestHelpers"
end
rake "db:migrate" if (mysql || pg) && !devise
# Authentication
generate "cancan:ability" if cancan
application "config.case_insensitive_keys = [:email]"
# Make the magic happen
run 'bundle install'
# Remove unnecessary stuff
puts "# Removing unnecessary stuff:"
run "rm README.rdoc public/index.html app/assets/images/rails.png"
# CARRIERWAVE
if carrierwave
if carrierwave_aws
puts "# create a carrierwave initializer"
initializer("carrierwave.rb", "")
File.write("config/initializers/carrierwave.rb", "CarrierWave.configure do |config|
config.storage = :aws
config.aws_bucket = ENV['S3_BUCKET_NAME']
config.aws_acl = :public_read
config.aws_authenticated_url_expiration = 60 * 60 * 24 * 365
config.aws_credentials = {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
end")
end
end
# ATTACHNINARY
if attachinary
if mongo
insert_after("config/application.rb", "require File.expand_path('../boot', __FILE__)", 'require "attachinary/orm/mongoid" # active_record or mongoid"')
end
if mysql || postgres || sqlite3
insert_after("config/application.rb", "require File.expand_path('../boot', __FILE__)", 'require "attachinary/orm/active_record" # active_record or mongoid')
end
run "rake attachinary:install:migrations" if mysql || postgres
run "rake db:migrate" if mysql || postgres
route('mount Attachinary::Engine => "/attachinary"')
insert_before("app/views/layouts/application.html.erb", "</head>", 'require "<%= cloudinary_js_config %>')
insert_after("app/assets/javascripts/application.js", "//\n", "//= require jquery.ui.widget\n//= require jquery.iframe-transport\n//= require jquery.fileupload\n//= require cloudinary/jquery.cloudinary\n//= require attachinary\n\n$('.attachinary-input').attachinary();")
run "rake attachinary:fetch_fileupload"
end
# OMNIAUTH
if omniauth
insert_after "config/initializers/devise.rb", "Devise.setup do |config|", " config.omniauth :facebook, FB_GRAPH_APP_ID, FB_GRAPH_SECRET, :scope => 'offline_access,email,offline_access,user_about_me,read_stream,user_location,user_birthday,user_hometown', :display => 'popup'"
insert_after "config/initializers/devise.rb", "Devise.setup do |config|", " config.omniauth :twitter, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET"
insert_after "config/environments/development.rb", "Application.configure do", " # FACEBOOK\n FB_GRAPH_APP_ID = ENV['FB_GRAPH_APP_ID']\n FB_GRAPH_SECRET = ENV['FB_GRAPH_SECRET']"
insert_after "config/environments/development.rb", "Application.configure do", " # TWITTER\n TWITTER_CONSUMER_KEY = ENV['TWITTER_CONSUMER_KEY']\n TWITTER_CONSUMER_SECRET = ENV['TWITTER_CONSUMER_SECRET']"
insert_after "config/environments/production.rb", "Application.configure do", " # FACEBOOK\n FB_GRAPH_APP_ID = ENV['FB_GRAPH_APP_ID']\n FB_GRAPH_SECRET = ENV['FB_GRAPH_SECRET']"
insert_after "config/environments/production.rb", "Application.configure do", " # TWITTER\n TWITTER_CONSUMER_KEY = ENV['TWITTER_CONSUMER_KEY']\n TWITTER_CONSUMER_SECRET = ENV['TWITTER_CONSUMER_SECRET']"
end
# MAILER SETTINGS
if active_admin || devise
application nil, :env => "development" do
"config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }"
"# Setting for Devise"
""
end
end
# Active Admin
if active_admin
generate("active_admin:install")
end
File.rm("db/database.yml") if mongo
run "rake db:migrate" if mysql || postgres
run "rake db:test:prepare" if testing
#########
## GIT ##
#########
git :init
git :add => '.'
git :commit => '-a -m "initial commit"'
##########################################
# Final Statements to get up and running #
##########################################
puts "############################################################"
puts "################## TEMPLATING SUCCESSFUL ###################"
puts "############################################################"
puts ""
puts "--->>> PLEASE DO THIS TASKS TO GET YOUR APP WORIKING <<<---"
puts ""
puts "Add $ //= require bootstrap" if bootstrap
puts 'ADD TO CSS FILE $ @import "bootstrap";' if bootstrap
puts "Go to the NEW RELIC homepage and copy the configuration file into your config folder" if new_relic
if omniauth
puts "############################################################"
puts "# OMNIAUTH"
puts "https://github.com/intridea/omniauth"
puts "please provide OMNIAUTH SETTINGS in config/environments/" if (omniauth && devise)
end
if acts_as_tree
puts "############################################################"
puts "# ACTS_AS_TREE"
puts ""
puts "https://github.com/amerine/acts_as_tree"
puts "include this two lines to your model to get acts_as_tree working"
puts "include ActsAsTree"
puts 'acts_as_tree order: "name"'
end
if carrierwave
puts "############################################################"
puts "# CARRIERWAVE"
puts ""
puts "https://github.com/jnicklas/carrierwave"
puts "run 'rails generate uploader [Modelname]"
puts "add -> require 'carrierwave/orm/activerecord' to your model" unless mongoid
puts "add -> require 'carrierwave/mongoid' to your model if mongoid" if mongoid
puts "add -> attr_accessible :avatar, :avatar_cache to your model"
puts "https://github.com/jnicklas/carrierwave-mongoid" if mongoid
end
if paperclip
puts "############################################################"
puts "# PAPERCLIP"
puts ""
puts "https://github.com/thoughtbot/paperclip"
puts "https://github.com/meskyanichi/mongoid-paperclip" if mongoid
puts "add to model -> attr_accessible :avatar"
puts 'add to model -> has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"'
puts "make a migration for your model:"
puts "class AddAvatarColumnsToUsers < ActiveRecord::Migration
def self.up
add_attachment :users, :avatar
end
def self.down
remove_attachment :users, :avatar
end
end"
end
if mongo_tree
puts "############################################################"
puts "# MONGO_TREE"
puts ""
puts "https://github.com/benedikt/mongoid-tree"
puts "include this line to your model to get the treestructure working"
puts "include Mongoid::Tree"
end
if geocoder
puts "############################################################"
puts "# GEOCODER"
puts ""
puts "How to use geocoder gem"
puts "http://www.rubygeocoder.com/"
end
if spork
puts "############################################################"
puts "Please put the content below Spork.each_run block INTO Spork prefork"
puts "Configure Spork to your needs"
end
if authlogic
puts "############################################################"
puts "# AUTHLOGIC"
puts ""
puts "Model User, Session... are generated"
puts "WRITE THIS IN YOUR APPLICATION TEMPLATE for Login/Logout Button"
puts ""
puts "<% if logged_in? %>"
puts " Welcome <%= current_user.username %>! Not you?"
puts " <%= link_to 'Log out', logout_path %>"
puts "<% else %>"
puts " <%= link_to 'Sign Up', signup_path %> or"
puts " <%= link_to 'log in', login_path %>."
puts "<% end %>"
puts "You can also restrict unregistered users from accessing a controller"
puts "using a before filter. For example:"
puts "before_filter :login_required, :except => [:index, :show]"
puts ""
puts "############################################################"
puts "############################################################"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment