| OLD | NEW |
| 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 /** | 5 /** |
| 6 * Code for displaying the API as HTML. This is used both for generating a | 6 * Code for displaying the API as HTML. This is used both for generating a |
| 7 * full description of the API as a web page, and for generating doc comments | 7 * full description of the API as a web page, and for generating doc comments |
| 8 * in generated code. | 8 * in generated code. |
| 9 */ | 9 */ |
| 10 library to.html; | 10 library to.html; |
| 11 | 11 |
| 12 import 'dart:convert'; | 12 import 'dart:convert'; |
| 13 | 13 |
| 14 import 'package:analyzer/src/codegen/html.dart'; | 14 import 'package:analyzer/src/codegen/html.dart'; |
| 15 import 'package:analyzer/src/codegen/tools.dart'; | 15 import 'package:analyzer/src/codegen/tools.dart'; |
| 16 import 'package:html/dom.dart' as dom; | 16 import 'package:html/dom.dart' as dom; |
| 17 | 17 |
| 18 import 'api.dart'; | 18 import 'api.dart'; |
| 19 import 'from_html.dart'; | 19 import 'from_html.dart'; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Embedded stylesheet | 22 * Embedded stylesheet |
| 23 */ | 23 */ |
| 24 final String stylesheet = ''' | 24 final String stylesheet = ''' |
| 25 body { | 25 body { |
| 26 font-family: sans-serif, serif; | 26 font-family: 'Roboto', sans-serif; |
| 27 padding-left: 5%; | 27 max-width: 800px; |
| 28 padding-right: 5%; | 28 margin: 0 auto; |
| 29 padding: 0 16px; |
| 30 font-size: 16px; |
| 31 line-height: 1.5; |
| 32 color: #111; |
| 33 background-color: #fdfdfd; |
| 34 font-weight: 300; |
| 35 -webkit-font-smoothing: auto; |
| 29 } | 36 } |
| 37 |
| 30 h1 { | 38 h1 { |
| 31 text-align: center; | 39 text-align: center; |
| 32 } | 40 } |
| 41 |
| 42 h2, h3, h4, h5 { |
| 43 margin-bottom: 0; |
| 44 } |
| 45 |
| 33 h2.domain { | 46 h2.domain { |
| 34 border-bottom: 3px solid rgb(160, 160, 160); | 47 border-bottom: 1px solid rgb(200, 200, 200); |
| 48 margin-bottom: 0.5em; |
| 35 } | 49 } |
| 50 |
| 51 h4 { |
| 52 font-size: 18px; |
| 53 } |
| 54 |
| 55 h5 { |
| 56 font-size: 16px; |
| 57 } |
| 58 |
| 59 p { |
| 60 margin-top: 0; |
| 61 } |
| 62 |
| 36 pre { | 63 pre { |
| 37 margin: 0px; | 64 margin: 0; |
| 65 font-family: 'Source Code Pro', monospace; |
| 66 font-size: 15px; |
| 38 } | 67 } |
| 68 |
| 39 div.box { | 69 div.box { |
| 40 border: 1px solid rgb(0, 0, 0); | 70 background-color: rgb(240, 245, 240); |
| 41 background-color: rgb(207, 226, 243); | 71 border-radius: 4px; |
| 42 padding: 0.5em; | 72 padding: 4px 12px; |
| 73 margin: 16px 0; |
| 43 } | 74 } |
| 75 |
| 44 div.hangingIndent { | 76 div.hangingIndent { |
| 45 padding-left: 3em; | 77 padding-left: 3em; |
| 46 text-indent: -3em; | 78 text-indent: -3em; |
| 47 } | 79 } |
| 80 |
| 81 dl dt { |
| 82 font-weight: bold; |
| 83 } |
| 84 |
| 85 dl dd { |
| 86 margin-left: 16px; |
| 87 } |
| 88 |
| 48 dt { | 89 dt { |
| 49 margin-top: 1em; | 90 margin-top: 1em; |
| 50 margin-bottom: 1em; | |
| 51 } | 91 } |
| 92 |
| 52 dt.notification { | 93 dt.notification { |
| 53 font-weight: bold; | 94 font-weight: bold; |
| 54 } | 95 } |
| 96 |
| 55 dt.refactoring { | 97 dt.refactoring { |
| 56 font-weight: bold; | 98 font-weight: bold; |
| 57 } | 99 } |
| 100 |
| 58 dt.request { | 101 dt.request { |
| 59 font-weight: bold; | 102 font-weight: bold; |
| 60 } | 103 } |
| 104 |
| 61 dt.typeDefinition { | 105 dt.typeDefinition { |
| 62 font-weight: bold; | 106 font-weight: bold; |
| 63 } | 107 } |
| 64 | 108 |
| 65 */ | 109 a { |
| 66 * Styles for index | 110 text-decoration: none; |
| 67 */ | 111 } |
| 112 |
| 113 a:focus, a:hover { |
| 114 text-decoration: underline; |
| 115 } |
| 116 |
| 117 /* Styles for index */ |
| 68 | 118 |
| 69 .subindex { | 119 .subindex { |
| 70 } | 120 } |
| 71 | 121 |
| 72 .subindex ul { | 122 .subindex ul { |
| 73 padding-left: 0px; | 123 padding-left: 0; |
| 74 margin-left: 0px; | 124 margin-left: 0; |
| 75 | 125 |
| 76 -webkit-margin-before: 0px; | 126 -webkit-margin-before: 0; |
| 77 -webkit-margin-start: 0px; | 127 -webkit-margin-start: 0; |
| 78 -webkit-padding-start: 0px; | 128 -webkit-padding-start: 0; |
| 79 | 129 |
| 80 list-style-type: none; | 130 list-style-type: none; |
| 81 } | 131 } |
| 82 ''' | 132 ''' |
| 83 .trim(); | 133 .trim(); |
| 84 | 134 |
| 85 final GeneratedFile target = | 135 final GeneratedFile target = |
| 86 new GeneratedFile('doc/api.html', (String pkgPath) { | 136 new GeneratedFile('doc/api.html', (String pkgPath) { |
| 87 ToHtmlVisitor visitor = new ToHtmlVisitor(readApi(pkgPath)); | 137 ToHtmlVisitor visitor = new ToHtmlVisitor(readApi(pkgPath)); |
| 88 dom.Document document = new dom.Document(); | 138 dom.Document document = new dom.Document(); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 translateHtml(node, squashParagraphs: squashParagraphs); | 399 translateHtml(node, squashParagraphs: squashParagraphs); |
| 350 continue; | 400 continue; |
| 351 } | 401 } |
| 352 switch (node.localName) { | 402 switch (node.localName) { |
| 353 case 'domain': | 403 case 'domain': |
| 354 visitDomain(apiMappings.domains[node]); | 404 visitDomain(apiMappings.domains[node]); |
| 355 break; | 405 break; |
| 356 case 'head': | 406 case 'head': |
| 357 head(() { | 407 head(() { |
| 358 translateHtml(node, squashParagraphs: squashParagraphs); | 408 translateHtml(node, squashParagraphs: squashParagraphs); |
| 409 element('link', { |
| 410 'rel': 'stylesheet', |
| 411 'href': 'https://fonts.googleapis.com/css?family=Source+Code+Pro
|Roboto:500,400italic,300,400', |
| 412 'type': 'text/css' |
| 413 }); |
| 359 element('style', {}, () { | 414 element('style', {}, () { |
| 360 writeln(stylesheet); | 415 writeln(stylesheet); |
| 361 }); | 416 }); |
| 362 }); | 417 }); |
| 363 break; | 418 break; |
| 364 case 'refactorings': | 419 case 'refactorings': |
| 365 visitRefactorings(api.refactorings); | 420 visitRefactorings(api.refactorings); |
| 366 break; | 421 break; |
| 367 case 'types': | 422 case 'types': |
| 368 visitTypes(api.types); | 423 visitTypes(api.types); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 398 }); | 453 }); |
| 399 } | 454 } |
| 400 | 455 |
| 401 @override | 456 @override |
| 402 void visitDomain(Domain domain) { | 457 void visitDomain(Domain domain) { |
| 403 if (domain.experimental) { | 458 if (domain.experimental) { |
| 404 return; | 459 return; |
| 405 } | 460 } |
| 406 h2('domain', () { | 461 h2('domain', () { |
| 407 anchor('domain_${domain.name}', () { | 462 anchor('domain_${domain.name}', () { |
| 408 write('Domain: ${domain.name}'); | 463 write('${domain.name} domain'); |
| 409 }); | 464 }); |
| 410 }); | 465 }); |
| 411 translateHtml(domain.html); | 466 translateHtml(domain.html); |
| 412 if (domain.requests.isNotEmpty) { | 467 if (domain.requests.isNotEmpty) { |
| 413 h3(() { | 468 h3(() { |
| 414 write('Requests'); | 469 write('Requests'); |
| 415 }); | 470 }); |
| 416 dl(() { | 471 dl(() { |
| 417 domain.requests.forEach(visitRequest); | 472 domain.requests.forEach(visitRequest); |
| 418 }); | 473 }); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 438 write('#'); | 493 write('#'); |
| 439 }); | 494 }); |
| 440 write(')'); | 495 write(')'); |
| 441 }); | 496 }); |
| 442 dd(() { | 497 dd(() { |
| 443 box(() { | 498 box(() { |
| 444 showType( | 499 showType( |
| 445 'notification', notification.notificationType, notification.params); | 500 'notification', notification.notificationType, notification.params); |
| 446 }); | 501 }); |
| 447 translateHtml(notification.html); | 502 translateHtml(notification.html); |
| 448 describePayload(notification.params, 'Parameters'); | 503 describePayload(notification.params, 'parameters:'); |
| 449 }); | 504 }); |
| 450 } | 505 } |
| 451 | 506 |
| 452 @override | 507 @override |
| 453 visitRefactoring(Refactoring refactoring) { | 508 visitRefactoring(Refactoring refactoring) { |
| 454 dt('refactoring', () { | 509 dt('refactoring', () { |
| 455 write(refactoring.kind); | 510 write(refactoring.kind); |
| 456 }); | 511 }); |
| 457 dd(() { | 512 dd(() { |
| 458 translateHtml(refactoring.html); | 513 translateHtml(refactoring.html); |
| 459 describePayload(refactoring.feedback, 'Feedback', force: true); | 514 describePayload(refactoring.feedback, 'Feedback:', force: true); |
| 460 describePayload(refactoring.options, 'Options', force: true); | 515 describePayload(refactoring.options, 'Options:', force: true); |
| 461 }); | 516 }); |
| 462 } | 517 } |
| 463 | 518 |
| 464 @override | 519 @override |
| 465 void visitRefactorings(Refactorings refactorings) { | 520 void visitRefactorings(Refactorings refactorings) { |
| 466 translateHtml(refactorings.html); | 521 translateHtml(refactorings.html); |
| 467 dl(() { | 522 dl(() { |
| 468 super.visitRefactorings(refactorings); | 523 super.visitRefactorings(refactorings); |
| 469 }); | 524 }); |
| 470 } | 525 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 481 }); | 536 }); |
| 482 write(')'); | 537 write(')'); |
| 483 }); | 538 }); |
| 484 dd(() { | 539 dd(() { |
| 485 box(() { | 540 box(() { |
| 486 showType('request', request.requestType, request.params); | 541 showType('request', request.requestType, request.params); |
| 487 br(); | 542 br(); |
| 488 showType('response', request.responseType, request.result); | 543 showType('response', request.responseType, request.result); |
| 489 }); | 544 }); |
| 490 translateHtml(request.html); | 545 translateHtml(request.html); |
| 491 describePayload(request.params, 'Parameters'); | 546 describePayload(request.params, 'parameters:'); |
| 492 describePayload(request.result, 'Returns'); | 547 describePayload(request.result, 'returns:'); |
| 493 }); | 548 }); |
| 494 } | 549 } |
| 495 | 550 |
| 496 @override | 551 @override |
| 497 void visitTypeDefinition(TypeDefinition typeDefinition) { | 552 void visitTypeDefinition(TypeDefinition typeDefinition) { |
| 498 if (typeDefinition.experimental) { | 553 if (typeDefinition.experimental) { |
| 499 return; | 554 return; |
| 500 } | 555 } |
| 501 dt('typeDefinition', () { | 556 dt('typeDefinition', () { |
| 502 anchor('type_${typeDefinition.name}', () { | 557 anchor('type_${typeDefinition.name}', () { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 void visitTypeObject(TypeObject typeObject) { | 609 void visitTypeObject(TypeObject typeObject) { |
| 555 dl(() { | 610 dl(() { |
| 556 super.visitTypeObject(typeObject); | 611 super.visitTypeObject(typeObject); |
| 557 }); | 612 }); |
| 558 } | 613 } |
| 559 | 614 |
| 560 @override | 615 @override |
| 561 void visitTypeObjectField(TypeObjectField typeObjectField) { | 616 void visitTypeObjectField(TypeObjectField typeObjectField) { |
| 562 dt('field', () { | 617 dt('field', () { |
| 563 b(() { | 618 b(() { |
| 564 i(() { | 619 write(typeObjectField.name); |
| 565 write(typeObjectField.name); | 620 if (typeObjectField.value != null) { |
| 566 if (typeObjectField.value != null) { | 621 write(' = ${JSON.encode(typeObjectField.value)}'); |
| 567 write(' = ${JSON.encode(typeObjectField.value)}'); | 622 } else { |
| 568 } else { | 623 write(' ('); |
| 569 write(' ( '); | 624 if (typeObjectField.optional) { |
| 570 if (typeObjectField.optional) { | 625 gray(() { |
| 571 gray(() { | 626 write('optional'); |
| 572 write('optional'); | 627 }); |
| 573 }); | 628 write(' '); |
| 574 write(' '); | |
| 575 } | |
| 576 TypeVisitor typeVisitor = new TypeVisitor(api, short: true); | |
| 577 addAll(typeVisitor.collectHtml(() { | |
| 578 typeVisitor.visitTypeDecl(typeObjectField.type); | |
| 579 })); | |
| 580 write(' )'); | |
| 581 } | 629 } |
| 582 }); | 630 TypeVisitor typeVisitor = new TypeVisitor(api, short: true); |
| 631 addAll(typeVisitor.collectHtml(() { |
| 632 typeVisitor.visitTypeDecl(typeObjectField.type); |
| 633 })); |
| 634 write(')'); |
| 635 } |
| 583 }); | 636 }); |
| 584 }); | 637 }); |
| 585 dd(() { | 638 dd(() { |
| 586 translateHtml(typeObjectField.html); | 639 translateHtml(typeObjectField.html); |
| 587 }); | 640 }); |
| 588 } | 641 } |
| 589 | 642 |
| 590 @override | 643 @override |
| 591 void visitTypeReference(TypeReference typeReference) {} | 644 void visitTypeReference(TypeReference typeReference) {} |
| 592 | 645 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 bool verticalBarNeeded = false; | 762 bool verticalBarNeeded = false; |
| 710 for (TypeDecl choice in typeUnion.choices) { | 763 for (TypeDecl choice in typeUnion.choices) { |
| 711 if (verticalBarNeeded) { | 764 if (verticalBarNeeded) { |
| 712 write(' | '); | 765 write(' | '); |
| 713 } | 766 } |
| 714 visitTypeDecl(choice); | 767 visitTypeDecl(choice); |
| 715 verticalBarNeeded = true; | 768 verticalBarNeeded = true; |
| 716 } | 769 } |
| 717 } | 770 } |
| 718 } | 771 } |
| OLD | NEW |