OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 * To use it, from this directory, run: | 6 * To use it, from this directory, run: |
7 * | 7 * |
8 * $ ./dartdoc <path to .dart file> | 8 * $ ./dartdoc <path to .dart file> |
9 * | 9 * |
10 * This will create a "docs" directory with the docs for your libraries. To | 10 * This will create a "docs" directory with the docs for your libraries. To |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 int _totalTypes = 0; | 97 int _totalTypes = 0; |
98 int _totalMembers = 0; | 98 int _totalMembers = 0; |
99 | 99 |
100 Dartdoc() | 100 Dartdoc() |
101 : _comments = new CommentMap() { | 101 : _comments = new CommentMap() { |
102 // Patch in support for [:...:]-style code to the markdown parser. | 102 // Patch in support for [:...:]-style code to the markdown parser. |
103 // TODO(rnystrom): Markdown already has syntax for this. Phase this out? | 103 // TODO(rnystrom): Markdown already has syntax for this. Phase this out? |
104 md.InlineParser.syntaxes.insertRange(0, 1, | 104 md.InlineParser.syntaxes.insertRange(0, 1, |
105 new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]')); | 105 new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]')); |
106 | 106 |
107 md.setImplicitLinkResolver(resolveNameReference); | 107 md.setImplicitLinkResolver((name) => resolveNameReference(name, |
108 currentLibrary: _currentLibrary, currentType: _currentType, | |
109 currentMember: _currentMember)); | |
108 } | 110 } |
109 | 111 |
110 document(String entrypoint) { | 112 document(String entrypoint) { |
111 var oldDietParse = options.dietParse; | 113 var oldDietParse = options.dietParse; |
112 try { | 114 try { |
113 options.dietParse = true; | 115 options.dietParse = true; |
114 | 116 |
115 // Handle the built-in entrypoints. | 117 // Handle the built-in entrypoints. |
116 switch (entrypoint) { | 118 switch (entrypoint) { |
117 case 'corelib': | 119 case 'corelib': |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 | 775 |
774 // Syntax highlight. | 776 // Syntax highlight. |
775 return classifySource(new SourceFile('', code)); | 777 return classifySource(new SourceFile('', code)); |
776 } | 778 } |
777 | 779 |
778 /** | 780 /** |
779 * This will be called whenever a doc comment hits a `[name]` in square | 781 * This will be called whenever a doc comment hits a `[name]` in square |
780 * brackets. It will try to figure out what the name refers to and link or | 782 * brackets. It will try to figure out what the name refers to and link or |
781 * style it appropriately. | 783 * style it appropriately. |
782 */ | 784 */ |
783 md.Node resolveNameReference(String name) { | 785 md.Node resolveNameReference(String name, [Member currentMember = null, |
Bob Nystrom
2012/01/09 22:48:20
I wouldn't use "current", just "member", "type" an
| |
786 Type currentType = null, Library currentLibrary = null]) { | |
784 makeLink(String href) { | 787 makeLink(String href) { |
785 final anchor = new md.Element.text('a', name); | 788 final anchor = new md.Element.text('a', name); |
786 anchor.attributes['href'] = relativePath(href); | 789 anchor.attributes['href'] = relativePath(href); |
787 anchor.attributes['class'] = 'crossref'; | 790 anchor.attributes['class'] = 'crossref'; |
788 return anchor; | 791 return anchor; |
789 } | 792 } |
790 | 793 |
791 findMember(Type type) { | 794 findMember(Type type) { |
792 final member = type.members[name]; | 795 final member = type.members[name]; |
793 if (member == null) return null; | 796 if (member == null) return null; |
794 | 797 |
795 // Special case: if the member we've resolved is a property (i.e. it wraps | 798 // Special case: if the member we've resolved is a property (i.e. it wraps |
796 // a getter and/or setter then *that* member itself won't be on the docs, | 799 // a getter and/or setter then *that* member itself won't be on the docs, |
797 // just the getter or setter will be. So pick one of those to link to. | 800 // just the getter or setter will be. So pick one of those to link to. |
798 if (member.isProperty) { | 801 if (member.isProperty) { |
799 return member.canGet ? member.getter : member.setter; | 802 return member.canGet ? member.getter : member.setter; |
800 } | 803 } |
801 | 804 |
802 return member; | 805 return member; |
803 } | 806 } |
804 | 807 |
805 // See if it's a parameter of the current method. | 808 // See if it's a parameter of the current method. |
806 if (_currentMember != null) { | 809 if (currentMember != null) { |
807 for (final parameter in _currentMember.parameters) { | 810 for (final parameter in currentMember.parameters) { |
808 if (parameter.name == name) { | 811 if (parameter.name == name) { |
809 final element = new md.Element.text('span', name); | 812 final element = new md.Element.text('span', name); |
810 element.attributes['class'] = 'param'; | 813 element.attributes['class'] = 'param'; |
811 return element; | 814 return element; |
812 } | 815 } |
813 } | 816 } |
814 } | 817 } |
815 | 818 |
816 // See if it's another member of the current type. | 819 // See if it's another member of the current type. |
817 if (_currentType != null) { | 820 if (currentType != null) { |
818 final member = findMember(_currentType); | 821 final member = findMember(currentType); |
819 if (member != null) { | 822 if (member != null) { |
820 return makeLink(memberUrl(member)); | 823 return makeLink(memberUrl(member)); |
821 } | 824 } |
822 } | 825 } |
823 | 826 |
824 // See if it's another type in the current library. | 827 // See if it's another type in the current library. |
825 if (_currentLibrary != null) { | 828 if (currentLibrary != null) { |
826 final type = _currentLibrary.types[name]; | 829 final type = currentLibrary.types[name]; |
827 if (type != null) { | 830 if (type != null) { |
828 return makeLink(typeUrl(type)); | 831 return makeLink(typeUrl(type)); |
829 } | 832 } |
830 | 833 |
831 // See if it's a top-level member in the current library. | 834 // See if it's a top-level member in the current library. |
832 final member = findMember(_currentLibrary.topType); | 835 final member = findMember(currentLibrary.topType); |
833 if (member != null) { | 836 if (member != null) { |
834 return makeLink(memberUrl(member)); | 837 return makeLink(memberUrl(member)); |
835 } | 838 } |
836 } | 839 } |
837 | 840 |
838 // TODO(rnystrom): Should also consider: | 841 // TODO(rnystrom): Should also consider: |
839 // * Names imported by libraries this library imports. | 842 // * Names imported by libraries this library imports. |
840 // * Type parameters of the enclosing type. | 843 // * Type parameters of the enclosing type. |
841 | 844 |
842 return new md.Element.text('code', name); | 845 return new md.Element.text('code', name); |
843 } | 846 } |
844 | 847 |
845 // TODO(rnystrom): Move into SourceSpan? | 848 // TODO(rnystrom): Move into SourceSpan? |
846 int getSpanColumn(SourceSpan span) { | 849 int getSpanColumn(SourceSpan span) { |
847 final line = span.file.getLine(span.start); | 850 final line = span.file.getLine(span.start); |
848 return span.file.getColumn(line, span.start); | 851 return span.file.getColumn(line, span.start); |
849 } | 852 } |
850 } | 853 } |
OLD | NEW |