-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_ajax_includes.rb
37 lines (29 loc) · 1.48 KB
/
update_ajax_includes.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
#!/usr/bin/ruby
# This script is run by the Time Machine Creator software. Do not run this on your own unless you know what you are doing.
current_script_dir = File.dirname(__FILE__);
Dir.chdir(current_script_dir)
outfile = "ajax_includes.js"
puts "Creating #{outfile}";
open("#{outfile}.tmp", "w") do |out|
out.puts "// Autogenerated by update_ajax_includes.rb #{Time.now}"
out.puts "cached_ajax={};"
# Pull dataset json info (tm.json and r.json from the videoset directory)
(Dir.glob("./*/r.json") + ["./tm.json"]).each do |file|
contents = open(file, 'r') {|f| f.read}.gsub("\n", "")
# Legacy code. If old naming scheme found, convert it.
contents = contents.gsub("lower-right-lat", "south");
contents = contents.gsub("lower-right-lon", "east" );
contents = contents.gsub("upper-left-lat" , "north");
contents = contents.gsub("upper-left-lon" , "west" );
out.puts "cached_ajax['#{file}']=#{contents};"
puts "Added #{file} (literal, #{contents.size} bytes)"
end
# Pull templates
['templates/browser_not_supported_template.html', 'templates/player_template.html', 'templates/time_warp_composer.html', 'templates/annotation_editor.html'].each do |file|
contents = open(file, 'r') {|f| f.read}
contents = contents.gsub('\\', '\\\\').gsub("\n", '\\n').gsub("\r", "").gsub('"', '\\"');
out.puts "cached_ajax['#{file}']=\"#{contents}\";"
puts "Added #{file} (json quoted, #{contents.size} bytes)"
end
end
File.rename "#{outfile}.tmp", outfile;