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

Side by Side Diff: pkg/docgen/lib/src/mdn.dart

Issue 242363004: pkg/docgen: moved model classes into minilibs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library docgen.mdn; 5 library docgen.mdn;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:logging/logging.dart'; 10 import 'package:logging/logging.dart';
11 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
12 12
13 // TODO(janicejl): Make MDN content generic or pluggable. 13 // TODO(janicejl): Make MDN content generic or pluggable.
14 14
15 /// Map of all the comments for dom elements from MDN. 15 /// Map of all the comments for dom elements from MDN.
16 Map<String, dynamic> _mdn; 16 Map<String, dynamic> _mdn;
17 17
18 /// Generates MDN comments from database.json. 18 /// Generates MDN comments from database.json.
19 String mdnComment(String root, Logger logger, String domName) { 19 String mdnComment(String root, Logger logger, String domName) {
20 //Check if MDN is loaded. 20 //Check if MDN is loaded.
kevmoo 2014/04/18 17:03:18 Just whitespace cleanup
21 if (_mdn == null) { 21 if (_mdn == null) {
22 // Reading in MDN related json file. 22 // Reading in MDN related json file.
23 var mdnPath = p.join(root, 'utils/apidoc/mdn/database.json'); 23 var mdnPath = p.join(root, 'utils/apidoc/mdn/database.json');
24 var mdnFile = new File(mdnPath); 24 var mdnFile = new File(mdnPath);
25 if (mdnFile.existsSync()) { 25 if (mdnFile.existsSync()) {
26 _mdn = JSON.decode(mdnFile.readAsStringSync()); 26 _mdn = JSON.decode(mdnFile.readAsStringSync());
27 } else { 27 } else {
28 logger.warning("Cannot find MDN docs expected at $mdnPath"); 28 logger.warning("Cannot find MDN docs expected at $mdnPath");
29 _mdn = {}; 29 _mdn = {};
30 } 30 }
31 } 31 }
32 32
33 var parts = domName.split('.'); 33 var parts = domName.split('.');
34 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]); 34 if (parts.length == 2) return _mdnMemberComment(parts[0], parts[1]);
35 if (parts.length == 1) return _mdnTypeComment(parts[0]); 35 if (parts.length == 1) return _mdnTypeComment(parts[0]);
36 36
37 throw new StateError('More than two items is not supported: $parts'); 37 throw new StateError('More than two items is not supported: $parts');
38 } 38 }
39 39
40 /// Generates the MDN Comment for variables and method DOM elements. 40 /// Generates the MDN Comment for variables and method DOM elements.
41 String _mdnMemberComment(String type, String member) { 41 String _mdnMemberComment(String type, String member) {
42 var mdnType = _mdn[type]; 42 var mdnType = _mdn[type];
43 if (mdnType == null) return ''; 43 if (mdnType == null) return '';
44 var mdnMember = mdnType['members'].firstWhere((e) => e['name'] == member, 44 var mdnMember = mdnType['members'].firstWhere((e) => e['name'] == member,
45 orElse: () => null); 45 orElse: () => null);
46 if (mdnMember == null) return ''; 46 if (mdnMember == null) return '';
47 if (mdnMember['help'] == null || mdnMember['help'] == '') return ''; 47 if (mdnMember['help'] == null || mdnMember['help'] == '') return '';
48 if (mdnMember['url'] == null) return ''; 48 if (mdnMember['url'] == null) return '';
49 return _htmlifyMdn(mdnMember['help'], mdnMember['url']); 49 return _htmlifyMdn(mdnMember['help'], mdnMember['url']);
50 } 50 }
51 51
52 /// Generates the MDN Comment for class DOM elements. 52 /// Generates the MDN Comment for class DOM elements.
53 String _mdnTypeComment(String type) { 53 String _mdnTypeComment(String type) {
54 var mdnType = _mdn[type]; 54 var mdnType = _mdn[type];
55 if (mdnType == null) return ''; 55 if (mdnType == null) return '';
56 if (mdnType['summary'] == null || mdnType['summary'] == "") return ''; 56 if (mdnType['summary'] == null || mdnType['summary'] == "") return '';
57 if (mdnType['srcUrl'] == null) return ''; 57 if (mdnType['srcUrl'] == null) return '';
58 return _htmlifyMdn(mdnType['summary'], mdnType['srcUrl']); 58 return _htmlifyMdn(mdnType['summary'], mdnType['srcUrl']);
59 } 59 }
60 60
61 /// Encloses the given content in an MDN div and the original source link. 61 /// Encloses the given content in an MDN div and the original source link.
62 String _htmlifyMdn(String content, String url) { 62 String _htmlifyMdn(String content, String url) {
63 return '<div class="mdn">' + content.trim() + '<p class="mdn-note">' 63 return '<div class="mdn">' + content.trim() + '<p class="mdn-note">'
64 '<a href="' + url.trim() + '">from Mdn</a></p></div>'; 64 '<a href="' + url.trim() + '">from Mdn</a></p></div>';
65 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698