#!/usr/bin/ruby

# Run this anytime a file in the templates directory is modified.

outfile = "template_includes.js"

puts "Creating #{outfile}";

open("#{outfile}.tmp", "w") do |out|
  out.puts "// Autogenerated by update_template_includes.rb #{Time.now}"
  out.puts "var cached_ajax=cached_ajax||{};"

  # 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;
