Skip to content

Instantly share code, notes, and snippets.

@faouzzz
Last active August 9, 2016 15:41
Show Gist options
  • Save faouzzz/7f2ff5ec33b820a179a3cbd0c6d01c4a to your computer and use it in GitHub Desktop.
Save faouzzz/7f2ff5ec33b820a179a3cbd0c6d01c4a to your computer and use it in GitHub Desktop.
rails template
# >---------------------------------------------------------------------------<
#
# _____ _ _ __ ___ _
# | __ \ (_) | \ \ / (_) | |
# | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
# | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
# | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |
# |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_|
#
# This template was generated by RailsWizard, the amazing and awesome Rails
# application template builder. Get started at http://railswizard.org
#
# >---------------------------------------------------------------------------<
def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
def say_wizard(text); say_custom(@current_recipe || File.basename(__FILE__, '.rb'), text) end
def ask_wizard(question)
ask "\033[1m\033[30m\033[46m" + (@current_recipe || File.basename(__FILE__, '.rb')).rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
end
def yes_wizard?(question, default=nil)
choices = case default
when true then 'Y/n'
when false then 'y/N'
when nil then 'y/n'
end
answer = ask_wizard(question + " \033[33m(#{choices})\033[0m")
case answer.downcase
when "yes", "y"
true
when "no", "n"
false
else
default.nil? ? yes_wizard?(question) : default
end
end
def no_wizard?(question); !yes_wizard?(question) end
def multiple_choice(question, choices)
say_custom('question', question)
values = {}
choices.each_with_index do |choice,i|
values[(i + 1).to_s] = choice[1]
say_custom (i + 1).to_s + ')', choice[0]
end
answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
values[answer]
end
# >----------------------------[ helpers ]------------------------------<
run 'rm Gemfile'
file 'Gemfile', <<-GEMFILE
source 'https://rubygems.org'
GEMFILE
# default gems
gem 'rails'
gem 'sqlite3'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'jbuilder'
gem 'puma'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
# added gems
gem 'rails-i18n'
gem 'autoprefixer-rails'
gem 'haml-rails'
gem 'simple_form'
gem_group :development, :test do
gem 'faker'
gem 'better_errors'
gem 'binding_of_caller'
gem 'pry-rails'
gem 'pry-byebug'
gem 'bullet'
# default dev gems
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
gem 'turbolinks' unless remove_turbolink = yes_wizard?('Remove turbolinks gem ?', false)
gem 'devise' if setup_devise = yes_wizard?('Add devise gem ?', true)
if setup_devise
@devise_add_name = yes_wizard?('Add name field as string to user model ?', true)
@devise_add_firstname = yes_wizard?('Add firstname field as string to user model ?', true)
@devise_add_lastname = yes_wizard?('Add lastname field as string to user model ?', true)
@devise_add_role = yes_wizard?('Add role field as integer to user model ?', true)
end
gem 'cancancan' if setup_cancan = yes_wizard?('Add cancan gem ?', false)
gem 'semantic-ui-sass' if @setup_semantic = yes_wizard?('Add semantic-ui-sass gem ?', true)
gem 'angular-rails' if setup_angularjs = yes_wizard?('Add angularjs gem ?', false)
gem 'rails-angular-material' if setup_angularmd = yes_wizard?('Add angular material gem ?', false)
if yes_wizard?('Add capistrano-rails gem ?', false)
gem 'capistrano-rails'
gem 'capistrano-rvm'
end
generate_controller = yes_wizard?('Generate pages controller et set as root ?', true)
initialize_git = yes_wizard?('intialize as git repo ?', true)
after_bundle do
run 'spring stop'
remove_turbolink! if remove_turbolink
global_configurtion!
setup_simple_form!
setup_devise! if setup_devise
setup_sass!
setup_cancan! if setup_cancan
setup_semantic! if @setup_semantic
setup_angularjs! if setup_angularjs
setup_angularmd! if setup_angularmd
generate_controller! if generate_controller
setup_haml!
rake "db:migrate"
initialize_git! if initialize_git
end
def initialize_git!
git :init
git add: "."
git commit: %Q{-m "Initial commit"}
end
def setup_devise!
say_wizard 'setting up devise'
generate 'devise:install'
generate "devise user #{'name' if @devise_add_name} #{'firstname' if @devise_add_firstname} #{'lastname' if @devise_add_lastname} #{'role:integer' if @devise_add_role}"
generate 'devise:views'
#TODO configure devise initializer
end
def setup_cancan!
say_wizard 'setting up cancan'
generate 'cancancan:ability'
end
def setup_semantic!
say_wizard 'setting up semantic-ui'
open('app/assets/stylesheets/application.scss', 'a') { |f|
f.puts "@import 'semantic-ui';"
}
# TODO add semantic-ui to applications.js
end
def generate_controller!
say_wizard 'generating pages controller'
generate :controller, :pages, :index
route "root to: 'pages#index'"
end
def setup_simple_form!
say_wizard 'setting up simple_form'
require 'open-uri'
generate 'simple_form:install'
if @setup_semantic
run 'rm config/initializers/simple_form.rb'
initializer 'simple_form.rb',
open('https://gist.githubusercontent.com/faouzzz/6e0a6b96fb48838cc0c84d253e380f24/raw/0bdfb7b010a3da6871d5bdba2ecb96c4341604b4/simple_form.rb') {|f| f.read }
end
end
def setup_haml!
say_wizard 'setting up haml'
run 'rake haml:erb2haml app/views'
end
def setup_sass!
say_wizard 'setting up sass'
run 'rm app/assets/stylesheets/application.css'
file 'app/assets/stylesheets/application.scss'
end
def setup_angularjs!
#TODO add angular, angular-resource and angular-route to application.js
end
def setup_angularmd!
#TODO update css and js assets view doc for
end
def remove_turbolink!
#TODO remove from assets js and from application layout
end
def global_configurtion!
#TODO add div container to application layout
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment