blob: 3e75807525ccdc8f5fef6b858da5d25286bb9cf1 [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Combines the javascript files needed by jstemplate into a single file."""
import httplib
import urllib
def main():
srcs = ['util.js', 'jsevalcontext.js', 'jstemplate.js', 'exports.js']
out = 'jstemplate_compiled.js'
# Wrap the output in an anonymous function to prevent poluting the global
# namespace.
output_wrapper = '(function(){%s})()'
# Define the parameters for the POST request and encode them in a URL-safe
# format. See for
# API reference.
params = urllib.urlencode(
map(lambda src: ('js_code', file(src).read()), srcs) +
('compilation_level', 'ADVANCED_OPTIMIZATIONS'),
('output_format', 'text'),
('output_info', 'compiled_code'),
# Always use the following value for the Content-type header.
headers = {'Content-type': 'application/x-www-form-urlencoded'}
conn = httplib.HTTPConnection('')
conn.request('POST', '/compile', params, headers)
response = conn.getresponse()
out_file = file(out, 'w')
out_file.write(output_wrapper %
return 0
if __name__ == '__main__':