forked from pixels-and-bits/strappy
/
template.rb
56 lines (49 loc) · 1.08 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
# use this for local installs
SOURCE=ENV['SOURCE'] || 'https://github.com/jeanmartin/strappy/raw/master'
# I'm lazy
def gen(what)
generate what
end
def file_append(file, data)
log :append, file
File.open(file, 'a') {|f| f.write(data) }
end
def file_inject(file_name, sentinel, string, before_after=:after)
log :inject, file_name
gsub_file file_name, /(#{Regexp.escape(sentinel)})/mi do |match|
if :after == before_after
"#{match}\n#{string}"
else
"#{string}\n#{match}"
end
end
end
def file_str_replace(file_name, sentinel, replacement)
log :gsub, file_name
gsub_file file_name, /(#{Regexp.escape(sentinel)})/mi do |match|
replacement
end
end
puts
puts "\n#{'*' * 80}\n"
puts "Applying template: #{SOURCE}/base.rb"
puts "#{'*' * 80}\n\n"
[
:questions,
:initial_setup,
:database_config,
:gems,
:plugins,
:generators,
:patches,
:html5boilerplate,
:routes,
:mvc_scaffold,
:custom_files_and_patches,
:ci_and_deployment,
:cleanup,
:migrate_and_bootstrap,
:bye
].each do |recipe|
apply("#{SOURCE}/recipes/#{recipe}.rb")
end