Skip to content

Instantly share code, notes, and snippets.

@whiteskull
Last active December 14, 2015 00:59
Show Gist options
  • Save whiteskull/5002608 to your computer and use it in GitHub Desktop.
Save whiteskull/5002608 to your computer and use it in GitHub Desktop.
Create a new application in Rails
run 'rm public/index.html'
if yes? 'Would you like to use haml instead erb?(y/n) >'
gem 'haml-rails'
gem 'hpricot', :group => :development
gem 'ruby_parser', :group => :development
run 'bundle install'
initializer 'generator.rb', <<-INIT
Rails.application.config.generators do |g|
g.stylesheet_engine = :scss
g.javascript_engine = :coffee
g.template_engine = :haml
end
INIT
haml_doc = true
end
generate :controller, 'General index'
route "root :to => 'general#index'"
if yes? 'Would you like to install Devise?(y/n) >'
gem 'devise'
model_name = ask 'Enter model name for devise. Press <enter> for [user] >'
model_name = 'user' if model_name.blank?
generate 'devise:install'
generate 'devise', model_name
rake 'db:migrate'
generate 'devise:views -e erb'
devise_doc = true
if yes? 'Would you like to install Cancan?(y/n) >'
gem 'cancan'
run 'bundle install'
generate 'cancan:ability'
cancan_doc = true
elsif yes? 'Would you like to add user admin role?(y/n) >'
rails_admin_name = ask 'Enter field name for admin. Press <enter> for [admin] >'
rails_admin_name = 'admin' if rails_admin_name.blank?
generate :migration, "Add#{rails_admin_name.capitalize}To#{model_name.capitalize} #{rails_admin_name}:boolean"
yes? "WARNING! You need add in this migration 'default: false' to column #{rails_admin_name}, then press <enter>"
rake 'db:migrate'
run "echo \"User.create({email: 'admin@mail.com', password: 'password', admin: true}, without_protection: true)\" >> db/seeds.rb"
rake 'db:seed'
admin_role_doc = true
end
if yes? 'Would you like to install Rails Admin?(y/n) >'
gem 'rails_admin'
run 'bundle install'
generate 'rails_admin:install'
rake 'db:migrate'
rails_admin_doc = true
if yes? 'Would you like to install Ckeditor (also will be added gems carrierwave and mini_magick)?(y/n) >'
gem 'ckeditor'
gem 'carrierwave'
gem 'mini_magick'
run 'bundle install'
generate 'ckeditor:install --orm=active_record --backend=carrierwave'
rake 'db:migrate'
ckeditor_doc = true
end
end
end
if yes? 'Would you like to install Bootstrap?(y/n) >'
gem 'bootstrap-sass', :group => :assets
run 'bundle install'
run 'touch app/assets/stylesheets/bootsrap_and_overrides.css.scss'
run 'echo \'@import "\'bootstrap\'";\' >> app/assets/stylesheets/bootsrap_and_overrides.css.scss'
run 'rm app/assets/stylesheets/application.css'
run 'touch app/assets/stylesheets/application.css.scss'
css = <<-CSS
/*
*= require_self
*= require bootsrap_and_overrides
*/
CSS
run "echo \"#{css}\" >> app/assets/stylesheets/application.css.scss"
bootstrap_doc = true
end
if yes? 'Would you like to install SimpleForm?(y/n) >'
gem 'simple_form'
run 'bundle install'
generator = bootstrap_doc ? 'simple_form:install --bootstrap' : 'simple_form:install'
generate generator
simpleform_doc = true
end
run 'echo "/.idea" >> .gitignore'
run 'echo "/public/uploads" >> .gitignore'
run 'echo "/config/database.yml" >> .gitignore'
if haml_doc
run 'for i in `find app/views -name "*.erb"` ; do html2haml -e $i ${i%erb}haml ; rm $i ; done'
end
git :init
git :add => '.'
git :commit => '-m "init project"'
documentation = <<-DOC
=================== POSSIBLE IMPROVEMENTS ===================
DOC
if admin_role_doc && rails_admin_doc
documentation << <<-DOC
== Rails Admin can use only admin
https://github.com/sferik/rails_admin
Add to rails_admin.rb:
config.authorize_with do
redirect_to main_app.root_path unless current_#{model_name}.try(:#{rails_admin_name}?)
end
And then you can enter to the admin part:
localhost:3000/admin
email: admin@mail.ru
password: password
DOC
end
if cancan_doc && rails_admin_doc
documentation << <<-DOC
== Rails Admin can use only admin
https://github.com/ryanb/cancan
https://github.com/sferik/rails_admin/wiki/CanCan
DOC
end
if ckeditor_doc
documentation << <<-DOC
== To use ckeditor field in rails admin
https://github.com/galetahub/ckeditor
Add to rails_admin.rb:
config.model ModelName do
include_all_fields
edit do
field :field_name do
ckeditor do
true
end
end
end
end
DOC
end
if bootstrap_doc
documentation << <<-DOC
== Twitter bootstrap
https://github.com/thomas-mcdonald/bootstrap-sass
There is a helper that includes all available javascripts:
//= require bootstrap
Or you can also load individual modules:
//= require bootstrap-scrollspy
//= require bootstrap-modal
//= require bootstrap-dropdown
And so on...
DOC
end
if simpleform_doc
documentation << <<-DOC
== SimpleForm
https://github.com/plataformatec/simple_form
Example:
= simple_form_for @user do |f|
= f.input :username
= f.input :password
= f.button :submit
DOC
end
run "echo \"#{documentation}\" >> README.rdoc"
yes? 'CONGRATULATIONS! Please view README.rdoc, especially section === POSSIBLE IMPROVEMENTS === maybe there is something you need to do, press <enter>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment