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

Side by Side Diff: tools/dom/scripts/generator.py

Issue 12045076: Second half of HTML json docs. This reads the json file and inserts the docs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Line too long. Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « tools/dom/docs/lib/docs.dart ('k') | tools/dom/scripts/htmleventgenerator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import json
11 import os
10 import re 12 import re
11 from htmlrenamer import html_interface_renames 13 from htmlrenamer import html_interface_renames
12 14
13 _pure_interfaces = set([ 15 _pure_interfaces = set([
14 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. 16 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>.
15 'DOMStringMap', 17 'DOMStringMap',
16 'ElementTimeControl', 18 'ElementTimeControl',
17 'ElementTraversal', 19 'ElementTraversal',
18 'EventListener', 20 'EventListener',
19 'MediaQueryListListener', 21 'MediaQueryListListener',
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 'SpeechRecognitionResult': _speech_recognition_annotations, 790 'SpeechRecognitionResult': _speech_recognition_annotations,
789 'WebSocket': _all_but_ie9_annotations, 791 'WebSocket': _all_but_ie9_annotations,
790 'WorkerContext.indexedDB': _indexed_db_annotations, 792 'WorkerContext.indexedDB': _indexed_db_annotations,
791 'WorkerContext.webkitRequestFileSystem': _file_system_annotations, 793 'WorkerContext.webkitRequestFileSystem': _file_system_annotations,
792 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations, 794 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations,
793 'WorkerContext.webkitResolveLocalFileSystemSyncURL': _file_system_annotations, 795 'WorkerContext.webkitResolveLocalFileSystemSyncURL': _file_system_annotations,
794 'WorkerContext.webkitResolveLocalFileSystemURL': _file_system_annotations, 796 'WorkerContext.webkitResolveLocalFileSystemURL': _file_system_annotations,
795 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations, 797 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations,
796 } 798 }
797 799
798 def FindCommonAnnotations(interface_name, member_name=None): 800 def GetComments(interface_name, member_name=None, library_name=None):
801 """ Finds all comments for the interface or member and returns a list. """
802
803 # Add documentation from JSON.
804 current_dir = os.path.dirname(__file__)
805 json_path = os.path.join(current_dir, '..', 'docs', 'docs.json')
806 html_json = json.load(open(json_path))
blois 2013/01/25 18:49:13 dom_json, unless it's only for dart:html.
blois 2013/01/25 18:49:13 Is this really opening & parsing this file for eve
Andrei Mouravski 2013/01/25 19:11:52 Done.
Andrei Mouravski 2013/01/25 19:11:52 Done.
807
808 comments = []
809
810 if library_name in html_json and interface_name in html_json[library_name]:
811 if member_name and member_name in html_json[library_name][interface_name]['m embers']:
blois 2013/01/25 18:49:13 line length
Andrei Mouravski 2013/01/25 19:11:52 Done.
812 comments = html_json[library_name][interface_name]['members'][member_name]
813 elif 'comments' in html_json[library_name][interface_name]:
814 comments = html_json[library_name][interface_name]['comment']
815
816 return comments
817
818 def GetAnnotationsAndComments(interface_name, member_name=None,
819 library_name=None):
820 annotations = GetComments(interface_name, member_name, library_name)
821 annotations.extend(FindCommonAnnotations(interface_name, member_name,
822 library_name))
823 return annotations
824
825 def FindCommonAnnotations(interface_name, member_name=None, library_name=None):
799 """ Finds annotations common between dart2js and dartium. 826 """ Finds annotations common between dart2js and dartium.
800 """ 827 """
801 if member_name: 828 if member_name:
802 key = '%s.%s' % (interface_name, member_name) 829 key = '%s.%s' % (interface_name, member_name)
803 else: 830 else:
804 key = interface_name 831 key = interface_name
805 832
806 annotations = ["@DomName('" + key + "')",] 833 annotations = ["@DomName('" + key + "')"]
834
807 # Only add this for members, so we don't add DocsEditable to templated classes 835 # Only add this for members, so we don't add DocsEditable to templated classes
808 # (they get it from the default class template) 836 # (they get it from the default class template)
809 if member_name: 837 if member_name:
810 annotations.append('@DocsEditable'); 838 annotations.append('@DocsEditable');
811 839
812 if (dart_annotations.get(key) != None): 840 if (dart_annotations.get(key) != None):
813 annotations.extend(dart_annotations.get(key)) 841 annotations.extend(dart_annotations.get(key))
814 842
815 return annotations 843 return annotations
816 844
817 def FindDart2JSAnnotations(idl_type, interface_name, member_name): 845 def FindDart2JSAnnotations(idl_type, interface_name, member_name,
blois 2013/01/25 18:49:13 Should rename to include comments.
Andrei Mouravski 2013/01/25 19:11:52 Done.
846 library_name=None):
818 """ Finds all annotations for Dart2JS members- including annotations for 847 """ Finds all annotations for Dart2JS members- including annotations for
819 both dart2js and dartium. 848 both dart2js and dartium.
820 """ 849 """
821 annotations = FindCommonAnnotations(interface_name, member_name) 850 annotations = GetAnnotationsAndComments(interface_name, member_name,
851 library_name)
822 852
823 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name) 853 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)
824 if ann2: 854 if ann2:
825 if annotations: 855 if annotations:
826 annotations.extend(ann2) 856 annotations.extend(ann2)
827 else: 857 else:
828 annotations = ann2 858 annotations = ann2
829 return annotations 859 return annotations
830 860
831 def AnyConversionAnnotations(idl_type, interface_name, member_name): 861 def AnyConversionAnnotations(idl_type, interface_name, member_name):
832 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or 862 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or
833 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)): 863 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)):
834 return True 864 return True
835 else: 865 else:
836 return False 866 return False
837 867
838 def FormatAnnotations(annotations, indentation): 868 def FormatAnnotationsAndComments(annotations, indentation):
839 if annotations: 869 if annotations:
840 newline = '\n%s' % indentation 870 newline = '\n%s' % indentation
841 result = newline.join(annotations) + newline 871 result = newline.join(annotations) + newline
842 return result 872 return result
843 return '' 873 return ''
844 874
845 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name): 875 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name):
846 """ Finds dart2js-specific annotations. This does not include ones shared with 876 """ Finds dart2js-specific annotations. This does not include ones shared with
847 dartium. 877 dartium.
848 """ 878 """
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 self) 1419 self)
1390 1420
1391 if type_data.clazz == 'SVGTearOff': 1421 if type_data.clazz == 'SVGTearOff':
1392 dart_interface_name = self._renamer.RenameInterface( 1422 dart_interface_name = self._renamer.RenameInterface(
1393 self._database.GetInterface(type_name)) 1423 self._database.GetInterface(type_name))
1394 return SVGTearOffIDLTypeInfo( 1424 return SVGTearOffIDLTypeInfo(
1395 type_name, type_data, dart_interface_name, self) 1425 type_name, type_data, dart_interface_name, self)
1396 1426
1397 class_name = '%sIDLTypeInfo' % type_data.clazz 1427 class_name = '%sIDLTypeInfo' % type_data.clazz
1398 return globals()[class_name](type_name, type_data) 1428 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « tools/dom/docs/lib/docs.dart ('k') | tools/dom/scripts/htmleventgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698