OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # A python script that combines the javascript files needed by jstemplate into | 6 """Combines the javascript files needed by jstemplate into a single file.""" |
7 # a single file. | |
8 | 7 |
9 import httplib | 8 import httplib |
10 import urllib | 9 import urllib |
11 | 10 |
12 srcs ="util.js jsevalcontext.js jstemplate.js exports.js".split() | |
13 out = "jstemplate_compiled.js" | |
14 | 11 |
15 # Wrap the output in an anonymous function to prevent poluting the global | 12 def main(): |
16 # namespace. | 13 srcs = ['util.js', 'jsevalcontext.js', 'jstemplate.js', 'exports.js'] |
17 output_wrapper = "(function(){%s})()" | 14 out = 'jstemplate_compiled.js' |
18 | 15 |
19 # Define the parameters for the POST request and encode them in a URL-safe | 16 # Wrap the output in an anonymous function to prevent poluting the global |
20 # format. See http://code.google.com/closure/compiler/docs/api-ref.html for API | 17 # namespace. |
21 # reference. | 18 output_wrapper = '(function(){%s})()' |
22 params = urllib.urlencode( | |
23 map(lambda src: ('js_code', file(src).read()), srcs) + | |
24 [ | |
25 ('compilation_level', 'ADVANCED_OPTIMIZATIONS'), | |
26 ('output_format', 'text'), | |
27 ('output_info', 'compiled_code'), | |
28 ]) | |
29 | 19 |
30 # Always use the following value for the Content-type header. | 20 # Define the parameters for the POST request and encode them in a URL-safe |
31 headers = {'Content-type': 'application/x-www-form-urlencoded'} | 21 # format. See http://code.google.com/closure/compiler/docs/api-ref.html for |
32 conn = httplib.HTTPConnection('closure-compiler.appspot.com') | 22 # API reference. |
33 conn.request('POST', '/compile', params, headers) | 23 params = urllib.urlencode( |
34 response = conn.getresponse() | 24 map(lambda src: ('js_code', file(src).read()), srcs) + |
35 out_file = file(out, 'w') | 25 [ |
36 out_file.write(output_wrapper % response.read()) | 26 ('compilation_level', 'ADVANCED_OPTIMIZATIONS'), |
37 out_file.close() | 27 ('output_format', 'text'), |
38 conn.close() | 28 ('output_info', 'compiled_code'), |
| 29 ]) |
| 30 |
| 31 # Always use the following value for the Content-type header. |
| 32 headers = {'Content-type': 'application/x-www-form-urlencoded'} |
| 33 conn = httplib.HTTPConnection('closure-compiler.appspot.com') |
| 34 conn.request('POST', '/compile', params, headers) |
| 35 response = conn.getresponse() |
| 36 out_file = file(out, 'w') |
| 37 out_file.write(output_wrapper % response.read()) |
| 38 out_file.close() |
| 39 conn.close() |
| 40 return 0 |
| 41 |
| 42 |
| 43 if __name__ == '__main__': |
| 44 sys.exit(main()) |
OLD | NEW |