-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend.rb
executable file
·65 lines (53 loc) · 1.6 KB
/
frontend.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
# coding: utf-8
# clean file
run "rm README.rdoc"
run "rm -f public/favicon.ico"
run "cp config/database.yml config/database.yml.example"
# 聽說 turbolinks 還有問題,所以先取消
file_name = 'Gemfile'
tmp = File.read(file_name)
ret = tmp.gsub(/gem 'turbolinks'/, "# gem 'turbolinks'")
File.open(file_name, 'w') {|file| file.puts ret}
file_name = 'app/assets/javascripts/application.js'
tmp = File.read(file_name)
ret = tmp.gsub(/= require turbolinks/, " require turbolinks")
File.open(file_name, 'w') {|file| file.puts ret}
# add to Gemfile
append_file 'Gemfile', <<-CODE
gem 'kaminari'
gem 'therubyracer'
gem 'simple_form'
gem 'google-analytics-rails'
group :development do
gem 'guard-livereload', require: false
gem 'guard-rails', require: false
gem 'meta_request'
end
CODE
# bundle install
run 'bundle install'
# default controller
run 'rails g controller welcome index'
# 改 route.rb 啟用 welcome/index
file_name = 'config/routes.rb'
tmp = File.read(file_name)
ret = tmp.gsub(/# root 'welcome#index'/, "root 'welcome#index'")
File.open(file_name, 'w') {|file| file.puts ret}
# 增加 helper
run 'cd app/helpers/; wget -N https://raw.github.com/4point/rails4-template/master/replace/frontend/application_helper.rb'
# 改 layout
run 'cd app/views/layouts/; wget -N https://raw.github.com/4point/rails4-template/master/replace/frontend/application.html.erb'
# apply css
append_file 'app/assets/stylesheets/application.css', <<-CODE
p.alert { display: none }
CODE
# git ignore
append_file '.gitignore', <<-CODE
*~
*.swp
CODE
# git init
git :init
git :add => '.'
git :commit => "-a -m 'init'"