-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.rb
33 lines (26 loc) · 956 Bytes
/
helpers.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
require "erb"
# Yoinked from Github
class String
def console_red; colorize(self, "\e[31m"); end
def console_green; colorize(self, "\e[32m"); end
def console_bold; colorize(self, "\e[1m"); end
def console_underline; colorize(self, "\e[4m"); end
def colorize(text, color_code) "#{color_code}#{text}\e[0m" end
end
# Compile source_dir/filename to destination_dir/filename
def ext_copy_file(filename, source_dir, destination_dir, with_erb: false)
source_file = File.join(source_dir, filename)
destination_file = File.join(destination_dir, filename)
mkdir_p destination_dir
destination_file.sub(/\.erb(\.[a-z]+)$/) {with_erb = true; "#{$1}"}
if with_erb
File.open(destination_file, "w") do |f|
f.puts ERB.new(IO.read(source_file)).result(binding)
puts "✔ Copied #{source_file.console_bold} (ERB)"
end
else
cp source_file, destination_dir
puts "✔ Copied #{source_file.console_bold} (no ERB)"
end
return destination_file
end