-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript
More file actions
executable file
·58 lines (42 loc) · 1.41 KB
/
script
File metadata and controls
executable file
·58 lines (42 loc) · 1.41 KB
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
#!/usr/bin/env ruby
require 'yaml'
require 'fileutils'
THEMES_DIRECTORY = 'colors/themes'.freeze
TEMPLATES_DIRECTORY = 'templates'.freeze
BASE_OUT_DIR = 'build'.freeze
BASE_COLORS_FILENAME = 'colors/base.yaml'.freeze
def base_colors
File.open(BASE_COLORS_FILENAME) do |filename|
YAML.load(filename)
end
end
def themes
Dir.glob("#{THEMES_DIRECTORY}/*.yaml").map do |filename|
name = File.basename(filename, File.extname(filename))
contents = File.open(filename) { |f| YAML.load(f) }
[name, contents]
end.to_h
end
def process_template(template)
ext = File.extname(template)
app = File.basename(template, ext)
themes.each do |theme, theme_data|
out_dir = File.join(BASE_OUT_DIR, app)
out_file = File.join(out_dir, "#{theme}#{ext}")
puts "Creating #{out_file} from (#{app}, #{theme})"
FileUtils.mkdir_p(out_dir)
FileUtils.cp(template, out_file)
in_content = File.read(out_file)
theme_data.each do |k, v|
next if k.empty?
pattern = /@#{k}\b/
color = base_colors[v]
in_content = in_content.gsub(pattern, color)
end
in_content.gsub!('@themeName', "Solarized Simple: #{theme.capitalize}")
File.open(out_file, 'w') { |file| file.write(in_content) }
end
end
Dir.glob("#{TEMPLATES_DIRECTORY}/*").each do |template|
process_template(template)
end