-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.rb
114 lines (99 loc) · 3.04 KB
/
template.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
module Gemfile
class GemInfo
def initialize(name) @name=name; @group=[]; @opts={}; end
attr_accessor :name, :version
attr_reader :group, :opts
def opts=(new_opts={})
new_group = new_opts.delete(:group)
if (new_group && self.group != new_group)
@group = ([self.group].flatten + [new_group].flatten).compact.uniq.sort
end
@opts = (self.opts || {}).merge(new_opts)
end
def group_key() @group end
def gem_args_string
args = ["'#{@name}'"]
args << "'#{@version}'" if @version
@opts.each do |name,value|
args << ":#{name}=>#{value.inspect}"
end
args.join(', ')
end
end
@geminfo = {}
class << self
# add(name, version, opts={})
def add(name, *args)
name = name.to_s
version = args.first && !args.first.is_a?(Hash) ? args.shift : nil
opts = args.first && args.first.is_a?(Hash) ? args.shift : {}
@geminfo[name] = (@geminfo[name] || GemInfo.new(name)).tap do |info|
info.version = version if version
info.opts = opts
end
end
def write
File.open('Gemfile', 'a') do |file|
file.puts
grouped_gem_names.sort.each do |group, gem_names|
indent = ""
unless group.empty?
file.puts "group :#{group.join(', :')} do" unless group.empty?
indent=" "
end
gem_names.sort.each do |gem_name|
file.puts "#{indent}gem #{@geminfo[gem_name].gem_args_string}"
end
file.puts "end" unless group.empty?
file.puts
end
end
end
private
#returns {group=>[...gem names...]}, ie {[:development, :test]=>['rspec-rails', 'mocha'], :assets=>[], ...}
def grouped_gem_names
{}.tap do |_groups|
@geminfo.each do |gem_name, geminfo|
(_groups[geminfo.group_key] ||= []).push(gem_name)
end
end
end
end
end
def add_gem(*all) Gemfile.add(*all); end
add_gem "haml"
add_gem "rspec-rails", "~> 2.0", :group => [:development, :test]
add_gem "guard-rspec", :group => [:development, :test]
add_gem "guard-rails", :group => [:development, :test]
add_gem "factory_girl_rails", :group => [:development, :test]
add_gem "database_cleaner", :group => [:development, :test]
add_gem "haml-rails", :group => [:development, :test]
Gemfile.write
run 'bundle install'
generate 'rspec:install'
run 'bundle exec guard init rspec rails'
inject_into_file "spec/spec_helper.rb", :after => "RSpec.configure do |config|\n" do
<<-CODE
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
end
config.after(:each) do
DatabaseCleaner.clean
end
CODE
end
inside('app/views/layouts') do
run "rm application.html.erb"
end
file 'app/views/layouts/application.html.haml', <<-CODE
!!!
%html
%head
%title Template
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
%body
= yield
CODE