-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
72 lines (58 loc) · 1.22 KB
/
Rakefile
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
require "yaml"
require 'erb'
require 'fileutils'
require 'pry'
class Memory
@@_file = File.dirname(__FILE__) + '/build/memory.yml'
@@_mem = nil
def lookup(value)
@@_mem ||= self.read
@@_mem[value]
end
def save(key, value)
@@_mem ||= self.read
@@_mem[key] = value
File.open(@@_file, 'w') do |f|
f.puts YAML::dump(@@_mem)
end
FileUtils.chmod 0600, @@_file
end
private
def read
if File.exist? @@_file
YAML::load(File.read(@@_file))
else
{}
end
end
end
def get_value(name)
mem = Memory.new
old_value = mem.lookup(name)
begin
print(name)
print " (enter to keep #{old_value})" if old_value
print " : "
STDOUT.flush
res = STDIN.gets.chomp
end while res == "" && !old_value
value = (res == "") ? old_value : res
binding.pry
mem.save(name, value)
value
end
desc "Build the ERB files if modified"
task :build do
puts "Building"
files = Dir['**/*.erb']
files.each do |file|
next if file =~ /build/
tpl = ERB.new(File.read(file))
# Make sure the dir exists
outfile = './build/' + file
FileUtils.mkdir_p File.dirname(outfile)
File.open(outfile, 'w') do |f|
f.puts tpl.result(binding)
end
end
end