Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Unified Diff: create_wrapped_standalone_js.py

Issue 863863007: Add support for wrapping the standalone JavaScript. (Closed) Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build.xml ('k') | war/wrapped_domdistiller_template.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: create_wrapped_standalone_js.py
diff --git a/create_wrapped_standalone_js.py b/create_wrapped_standalone_js.py
new file mode 100644
index 0000000000000000000000000000000000000000..234094b1f01b4c641ca20e16e951598059d83628
--- /dev/null
+++ b/create_wrapped_standalone_js.py
@@ -0,0 +1,53 @@
+# Copyright 2015 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.
+
+"""Wraps the standalone JavaScript inside a templated outer JavaScript.
+
+Chrome needs to wrap the standalone JavaScript so it does not access the real
+window object, which is done in the wrapper JS. The output of this script is
+the file which is included in the Chrome builds.
+"""
+
+import optparse
+import sys
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('-t', '--templatefile',
+ help='The path to the output JavaScript template.')
+ parser.add_option('-i', '--infile',
+ help='The path to the standalone JavaScript to inject into the template.')
+ parser.add_option('-o', '--outfile',
+ help='The path to the output JavaScript.')
+ options, _ = parser.parse_args(argv)
+
+ templatepath = options.templatefile
+ inpath = options.infile
+ outpath = options.outfile
+
+ if templatepath:
+ templatefile = open(templatepath, 'r')
+ else:
+ print 'Please provide path to the template file'
+ return 1
+
+ if inpath:
+ infile = open(inpath, 'r')
+ else:
+ print 'Reading input from stdin'
+ infile = sys.stdin
+
+ if outpath:
+ outfile = open(outpath, 'w')
+ else:
+ outfile = sys.stdout
+
+ standalone_js = infile.read()
+ template_js = templatefile.read()
+ output_js = template_js.replace('$$DISTILLER_JAVASCRIPT', standalone_js)
+ outfile.write(output_js)
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « build.xml ('k') | war/wrapped_domdistiller_template.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698