-
-
Save SomeKay/b523851257b21a558318 to your computer and use it in GitHub Desktop.
Added slim layout file and removed erb layout file
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
### Rails app generator template. Run it: | |
### rails new _app_name_ -m https://gist.githubusercontent.com/DamirSvrtan/28a28e50d639b9445bbc/raw/app_template.rb | |
bin_setup_file = <<-FILE | |
#!/bin/sh | |
bundle install | |
bundle exec rake db:setup | |
FILE | |
File.open('bin/setup', 'w'){|file| file.write(bin_setup_file)} | |
remove_file "README.rdoc" | |
create_file "README.md", "Development: run ./bin/setup" | |
run 'mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss' | |
database_type = ask("Do you want to use postgres or mysql?", limited_to: ["pg", "mysql"]) | |
adapter = if database_type == 'pg' | |
gem 'pg' | |
'postgresql' | |
else | |
gem 'mysql2' | |
'mysql2' | |
end | |
database_file = <<-FILE | |
default: &default | |
adapter: <%= adapter %> | |
pool: 5 | |
timeout: 5000 | |
host: localhost | |
username: root | |
development: | |
<<: *default | |
database: <%= @app_name %>_development | |
password: | |
test: | |
<<: *default | |
database: <%= @app_name %>_test | |
production: | |
<<: *default | |
database: <%= @app_name %>_production | |
FILE | |
File.open('config/database.yml', 'w') do |file| | |
file.write(ERB.new(database_file).result(binding)) | |
end | |
# Remove unwanted gems. spring will be added later in the development group of gems | |
%w(spring coffee-rails sqlite3).each do |unwanted_gem| | |
gsub_file("Gemfile", /gem '#{unwanted_gem}'.*\n/, '') | |
end | |
# Replace erb layout file with slim layout file | |
layout_file = <<-FILE | |
doctype html | |
html | |
head | |
title Site title | |
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true | |
= javascript_include_tag 'application', 'data-turbolinks-track' => true | |
= csrf_meta_tags | |
body | |
= yield | |
FILE | |
File.delete('app/views/layouts/application.html.erb') | |
File.open('app/views/layouts/application.html.slim', 'w') do |file| | |
file.write(ERB.new(layout_file).result(binding)) | |
end | |
# remove commented lines | |
gsub_file("Gemfile", /#.*\n/, '') | |
# remove double newlines | |
gsub_file("Gemfile", /^\n\n/, '') | |
simple_form_installation = "simple_form:install" | |
if yes?('Use bootstrap?') | |
gem 'bootstrap-sass' | |
simple_form_installation << " --bootstrap" | |
end | |
gem 'simple_form' | |
gem 'slim-rails' | |
gem 'draper' | |
gem_group :development do | |
gem 'spring' | |
gem 'better_errors' | |
gem 'binding_of_caller' | |
gem 'quiet_assets' | |
gem 'pry-rails' | |
gem 'bullet' | |
gem 'traceroute' | |
gem 'letter_opener' | |
end | |
run "bundle install" | |
generate simple_form_installation | |
git :init | |
%w(.sass-cache powder public/system dump.rdb logfile .DS_Store).each do |gitignored| | |
append_file ".gitignore", gitignored | |
end | |
git add: ".", commit: "-m 'Initial commit'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, thnx for the fork, i needed this. One comment:
Since you're not embedding any variables in the layout file, you don't need the ERB evaluation, you could just use:
But perhaps it would be good to have the site title set as the app name, so you could keep the ruby embedding when writing to the file, and just modify the
layout_file
: