| Index: utils/apidoc/mdn/prettyPrint.dart
|
| diff --git a/utils/apidoc/mdn/postProcess.dart b/utils/apidoc/mdn/prettyPrint.dart
|
| similarity index 76%
|
| copy from utils/apidoc/mdn/postProcess.dart
|
| copy to utils/apidoc/mdn/prettyPrint.dart
|
| index 687d00ca2071c35bd38cc9ede958a927ec35506e..6f6447e7c8916b2daf155cb211de0a1303600474 100644
|
| --- a/utils/apidoc/mdn/postProcess.dart
|
| +++ b/utils/apidoc/mdn/prettyPrint.dart
|
| @@ -1,29 +1,13 @@
|
| -#library("postProcess");
|
| +#library("prettyPrint");
|
|
|
| #import("../../../frog/lib/node/node.dart");
|
| #import("dart:json");
|
| -
|
| -// TODO(jacobr): this file conflates pretty printing of the JSON database with
|
| -// filtering the database to select the best matches per file.
|
| -// Separate out the two tasks as quick and dirty coding is correct for pretty
|
| -// printing but more carefully documented code is required for the code
|
| -// filtering the database.
|
| -Map<String, List> database;
|
| -Map<String, Map> allProps;
|
| -Set<String> matchedTypes;
|
| +#import("util.dart");
|
|
|
| String orEmpty(String str) {
|
| return str == null ? "" : str;
|
| }
|
|
|
| -/** Returns whether the type has any member matching the specified name. */
|
| -bool hasAny(String type, String prop) {
|
| - final data = allProps[type];
|
| - return data['properties'].containsKey(prop) ||
|
| - data['methods'].containsKey(prop) ||
|
| - data['constants'].containsKey(prop);
|
| -}
|
| -
|
| List<String> sortStringCollection(Collection<String> collection) {
|
| final out = <String>[];
|
| out.addAll(collection);
|
| @@ -31,19 +15,6 @@ List<String> sortStringCollection(Collection<String> collection) {
|
| return out;
|
| }
|
|
|
| -/**
|
| - * Return the members from an [entry] as Map of member names to member
|
| - * objects.
|
| - */
|
| -Map getMembersMap(Map entry) {
|
| - List<Map> rawMembers = entry["members"];
|
| - final members = {};
|
| - for (final entry in rawMembers) {
|
| - members[entry['name']] = entry;
|
| - }
|
| - return members;
|
| -}
|
| -
|
| int addMissing(StringBuffer sb, String type, Map members) {
|
| int total = 0;
|
| /**
|
| @@ -74,59 +45,11 @@ int addMissing(StringBuffer sb, String type, Map members) {
|
| return total;
|
| }
|
|
|
| -/**
|
| - * Score entries using similarity heuristics calculated from the observed and
|
| - * expected list of members. We could be much less naive and penalize spurious
|
| - * methods, prefer entries with class level comments, etc. This method is
|
| - * needed becase we extract entries for each of the top search results for
|
| - * each class name and rely on these scores to determine which entry was
|
| - * best. Typically all scores but one will be zero. Multiple pages have
|
| - * non-zero scores when MDN has multiple pages on the same class or pages on
|
| - * similar classes (e.g. HTMLElement and Element), or pages on Mozilla
|
| - * specific classes that are similar to DOM classes (Console).
|
| - */
|
| -num scoreEntry(Map entry, String type) {
|
| - num score = 0;
|
| - // TODO(jacobr): consider removing skipped entries completely instead of
|
| - // just giving them lower scores.
|
| - if (!entry.containsKey('skipped')) {
|
| - score++;
|
| - }
|
| - if (entry.containsKey("members")) {
|
| - Map members = getMembersMap(entry);
|
| - for (String name in members.getKeys()) {
|
| - if (hasAny(type, name)) {
|
| - score++;
|
| - }
|
| - }
|
| - }
|
| - return score;
|
| -}
|
| -
|
| -/**
|
| - * Given a list of candidates for the documentation for a type, find the one
|
| - * that is the best.
|
| - */
|
| -Map pickBestEntry(List entries, String type) {
|
| - num bestScore = -1;
|
| - Map bestEntry;
|
| - for (Map entry in entries) {
|
| - if (entry != null) {
|
| - num score = scoreEntry(entry, type);
|
| - if (score > bestScore) {
|
| - bestScore = score;
|
| - bestEntry = entry;
|
| - }
|
| - }
|
| - }
|
| - return bestEntry;
|
| -}
|
| -
|
| void main() {
|
| // Database of code documentation.
|
| - database = JSON.parse(fs.readFileSync('output/database.json', 'utf8'));
|
| - // Database of expected property names for each type in WebKit.
|
| - allProps = JSON.parse(fs.readFileSync('data/dartIdl.json', 'utf8'));
|
| + final Map<String, Map> database = JSON.parse(fs.readFileSync(
|
| + 'output/database.filtered.json', 'utf8'));
|
| +
|
| // Types we have documentation for.
|
| matchedTypes = new Set<String>();
|
| int numMissingMethods = 0;
|
| @@ -136,7 +59,6 @@ void main() {
|
| int numSkipped = 0;
|
| final sbSkipped = new StringBuffer();
|
| final sbAllExamples = new StringBuffer();
|
| - final filteredDb = {};
|
|
|
| // Table rows for all obsolete members.
|
| final sbObsolete = new StringBuffer();
|
| @@ -226,10 +148,8 @@ void main() {
|
| <li><a href="#dart_summary">Summary</a></li>
|
| </li>
|
| """);
|
| -
|
| for (String type in sortStringCollection(database.getKeys())) {
|
| - Map entry = pickBestEntry(database[type], type);
|
| - filteredDb[type] = entry;
|
| + final entry = database[type];
|
| if (entry == null || entry.containsKey('skipped')) {
|
| numSkipped++;
|
| sbSkipped.add("""
|
| @@ -264,9 +184,9 @@ void main() {
|
| </tr>
|
| """);
|
| for (String name in sortStringCollection(members.getKeys())) {
|
| - Map memberData = members[name];
|
| - bool unknown = !hasAny(type, name);
|
| - StringBuffer classes = new StringBuffer();
|
| + Map memberData = members[name];
|
| + bool unknown = !hasAny(type, name);
|
| + StringBuffer classes = new StringBuffer();
|
| if (unknown) classes.add("unknown ");
|
| if (unknown) {
|
| numExtraMethods++;
|
| @@ -503,7 +423,4 @@ $sbObsolete
|
| </body>
|
| </html>
|
| """);
|
| -
|
| - fs.writeFileSync("output/database.filtered.json",
|
| - JSON.stringify(filteredDb));
|
| -}
|
| +}
|
|
|