| 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
|
|
|