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

Side by Side Diff: tools/json_schema_compiler/idl_schema.py

Issue 12996003: Dynamically generate a heading for Extension Docs API pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments - Patch currently being broken up Created 7 years, 6 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 unified diff | Download patch
OLDNEW
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 import itertools 6 import itertools
7 import json 7 import json
8 import os.path 8 import os.path
9 import re 9 import re
10 import sys 10 import sys
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 result[property_name] = True 302 result[property_name] = True
303 return result 303 return result
304 304
305 305
306 class Namespace(object): 306 class Namespace(object):
307 ''' 307 '''
308 Given an IDLNode representing an IDL namespace, converts into a Python 308 Given an IDLNode representing an IDL namespace, converts into a Python
309 dictionary that the JSON schema compiler expects to see. 309 dictionary that the JSON schema compiler expects to see.
310 ''' 310 '''
311 311
312 def __init__(self, namespace_node, nodoc=False, internal=False): 312 def __init__(self, namespace_node, nodoc=False, internal=False,
313 description=None):
313 self.namespace = namespace_node 314 self.namespace = namespace_node
314 self.nodoc = nodoc 315 self.nodoc = nodoc
315 self.internal = internal 316 self.internal = internal
316 self.events = [] 317 self.events = []
317 self.functions = [] 318 self.functions = []
318 self.types = [] 319 self.types = []
319 self.callbacks = OrderedDict() 320 self.callbacks = OrderedDict()
321 self.description = description
320 322
321 def process(self): 323 def process(self):
322 for node in self.namespace.children: 324 for node in self.namespace.children:
323 if node.cls == 'Dictionary': 325 if node.cls == 'Dictionary':
324 self.types.append(Dictionary(node).process(self.callbacks)) 326 self.types.append(Dictionary(node).process(self.callbacks))
325 elif node.cls == 'Callback': 327 elif node.cls == 'Callback':
326 k, v = Member(node).process(self.callbacks) 328 k, v = Member(node).process(self.callbacks)
327 self.callbacks[k] = v 329 self.callbacks[k] = v
328 elif node.cls == 'Interface' and node.GetName() == 'Functions': 330 elif node.cls == 'Interface' and node.GetName() == 'Functions':
329 self.functions = self.process_interface(node) 331 self.functions = self.process_interface(node)
330 elif node.cls == 'Interface' and node.GetName() == 'Events': 332 elif node.cls == 'Interface' and node.GetName() == 'Events':
331 self.events = self.process_interface(node) 333 self.events = self.process_interface(node)
332 elif node.cls == 'Enum': 334 elif node.cls == 'Enum':
333 self.types.append(Enum(node).process(self.callbacks)) 335 self.types.append(Enum(node).process(self.callbacks))
334 else: 336 else:
335 sys.exit('Did not process %s %s' % (node.cls, node)) 337 sys.exit('Did not process %s %s' % (node.cls, node))
336 return {'namespace': self.namespace.GetName(), 338 return {'namespace': self.namespace.GetName(),
339 'description': self.description,
337 'nodoc': self.nodoc, 340 'nodoc': self.nodoc,
338 'types': self.types, 341 'types': self.types,
339 'functions': self.functions, 342 'functions': self.functions,
340 'internal': self.internal, 343 'internal': self.internal,
341 'events': self.events} 344 'events': self.events}
342 345
343 def process_interface(self, node): 346 def process_interface(self, node):
344 members = [] 347 members = []
345 for member in node.children: 348 for member in node.children:
346 if member.cls == 'Member': 349 if member.cls == 'Member':
347 name, properties = Member(member).process(self.callbacks) 350 name, properties = Member(member).process(self.callbacks)
348 members.append(properties) 351 members.append(properties)
349 return members 352 return members
350 353
351 class IDLSchema(object): 354 class IDLSchema(object):
352 ''' 355 '''
353 Given a list of IDLNodes and IDLAttributes, converts into a Python list 356 Given a list of IDLNodes and IDLAttributes, converts into a Python list
354 of api_defs that the JSON schema compiler expects to see. 357 of api_defs that the JSON schema compiler expects to see.
355 ''' 358 '''
356 359
357 def __init__(self, idl): 360 def __init__(self, idl):
358 self.idl = idl 361 self.idl = idl
359 362
360 def process(self): 363 def process(self):
361 namespaces = [] 364 namespaces = []
362 nodoc = False 365 nodoc = False
363 internal = False 366 internal = False
367 description = None
364 for node in self.idl: 368 for node in self.idl:
365 if node.cls == 'Namespace': 369 if node.cls == 'Namespace':
366 namespace = Namespace(node, nodoc, internal) 370 namespace = Namespace(node, nodoc, internal, description)
367 namespaces.append(namespace.process()) 371 namespaces.append(namespace.process())
368 nodoc = False 372 nodoc = False
369 internal = False 373 internal = False
370 elif node.cls == 'Copyright': 374 elif node.cls == 'Copyright':
371 continue 375 continue
372 elif node.cls == 'Comment': 376 elif node.cls == 'Comment':
373 continue 377 description = node.GetName()
378 if description == '':
379 description = None
374 elif node.cls == 'ExtAttribute': 380 elif node.cls == 'ExtAttribute':
375 if node.name == 'nodoc': 381 if node.name == 'nodoc':
376 nodoc = bool(node.value) 382 nodoc = bool(node.value)
377 elif node.name == 'internal': 383 elif node.name == 'internal':
378 internal = bool(node.value) 384 internal = bool(node.value)
379 else: 385 else:
380 continue 386 continue
381 else: 387 else:
382 sys.exit('Did not process %s %s' % (node.cls, node)) 388 sys.exit('Did not process %s %s' % (node.cls, node))
383 return namespaces 389 return namespaces
(...skipping 16 matching lines...) Expand all
400 ''' 406 '''
401 Dump a json serialization of parse result for the IDL files whose names 407 Dump a json serialization of parse result for the IDL files whose names
402 were passed in on the command line. 408 were passed in on the command line.
403 ''' 409 '''
404 for filename in sys.argv[1:]: 410 for filename in sys.argv[1:]:
405 schema = Load(filename) 411 schema = Load(filename)
406 print json.dumps(schema, indent=2) 412 print json.dumps(schema, indent=2)
407 413
408 if __name__ == '__main__': 414 if __name__ == '__main__':
409 Main() 415 Main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/templates/public/extensions/webstore.html ('k') | tools/json_schema_compiler/model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698