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

Unified Diff: tools/json_schema_compiler/externs_js_generator.py

Issue 626653002: Automatically generate externs.js for a format (idl, json) supported by tools/json_schema_compiler. Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Minor changes. Created 6 years, 2 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 | « tools/json_schema_compiler/compiler.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/externs_js_generator.py
diff --git a/tools/json_schema_compiler/externs_js_generator.py b/tools/json_schema_compiler/externs_js_generator.py
new file mode 100644
index 0000000000000000000000000000000000000000..fb3e056c53ee3bcf9372679d31512fe51a1f3669
--- /dev/null
+++ b/tools/json_schema_compiler/externs_js_generator.py
@@ -0,0 +1,60 @@
+# Copyright 2014 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.
+"""
+Generates an externs.js file for Chrome extension APIs.
+"""
+
+from code import Code
+from model import CamelName, Function, PropertyType
+from schema_util import StripNamespace
+
+import os
+from datetime import datetime
+
+LICENSE = (
+"""// Copyright %s 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.""" %
+ datetime.now().year)
+
+PREAMBLE = (
+"""// Auto generated externs.js; do not edit.
+""")
+
+class ExternsJsGenerator(object):
+ def Generate(self, namespace):
+ self.api_namespace_ = 'chrome.%s' % CamelName(namespace.unix_name)
+
+ c = Code()
+ c.Append(LICENSE)
+
+ c.Append()
+
+ c.Append('/**')
+ c.Append(' * @const')
+ c.Append(' */')
+ c.Append('%s = {};' % self.api_namespace_)
+
+ # TODO(dtseng): Support namespace.functions, namespace.events.
+ for value in namespace.types.values():
+ c.Append('/**')
+ if value.description:
+ c.Append(' * %s' % value.description)
+ if value.property_type.name == 'enum':
+ c.Append(' * @enum {string}')
+ c.Append(' */')
+ c.Append('%s.%s = {' % (self.api_namespace_, value.name))
+ entries = []
+ for enum_value in value.enum_values:
+ entries.append(' %s: \'%s\'' % (enum_value.name, enum_value.name))
+ c.Append(',\n'.join(entries))
+ c.Append('};')
+ elif value.property_type.name == 'object':
+ # TODO(dtseng): Implement fully.
+ c.Append(' * @constructor')
+ c.Append(' */')
+ c.Append('%s.%s = function() {};' % (self.api_namespace_, value.name))
+ else:
+ raise Exception('Unknown property type: %s' % value.property_type.name)
+ return c
« no previous file with comments | « tools/json_schema_compiler/compiler.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698