@@ -105,17 +105,79 @@ enum hlvl {
105
105
h3 = 3
106
106
}
107
107
108
- fn write_header ( ctxt : ctxt , lvl : hlvl , title : str ) {
108
+ fn write_header ( ctxt : ctxt , lvl : hlvl , doc : doc:: itemtag ) {
109
+ let text = header_text ( doc) ;
110
+ write_header_ ( ctxt, lvl, text) ;
111
+ }
112
+
113
+ fn write_header_ ( ctxt : ctxt , lvl : hlvl , title : str ) {
109
114
let hashes = str:: from_chars ( vec:: init_elt ( lvl as uint , '#' ) ) ;
110
115
ctxt. w . write_line ( #fmt ( "%s %s" , hashes, title) ) ;
111
116
ctxt. w . write_line ( "" ) ;
112
117
}
113
118
119
+ fn header_text ( doc : doc:: itemtag ) -> str {
120
+ let fullpath = str:: connect ( doc. path ( ) + [ doc. name ( ) ] , "::" ) ;
121
+ alt doc {
122
+ doc : : modtag ( _) {
123
+ if doc. id ( ) == rustc:: syntax:: ast:: crate_node_id {
124
+ header_text_ ( "Crate" , doc. name ( ) )
125
+ } else {
126
+ header_text_ ( "Module" , fullpath)
127
+ }
128
+ }
129
+ doc:: nmodtag ( _) {
130
+ header_text_ ( "Native module" , fullpath)
131
+ }
132
+ doc:: fntag ( _) {
133
+ header_text_ ( "Function" , doc. name ( ) )
134
+ }
135
+ doc:: consttag ( _) {
136
+ header_text_ ( "Const" , doc. name ( ) )
137
+ }
138
+ doc:: enumtag ( _) {
139
+ header_text_ ( "Enum" , doc. name ( ) )
140
+ }
141
+ doc:: restag ( _) {
142
+ header_text_ ( "Resource" , doc. name ( ) )
143
+ }
144
+ doc:: ifacetag ( _) {
145
+ header_text_ ( "Interface" , doc. name ( ) )
146
+ }
147
+ doc:: impltag ( doc) {
148
+ assert option:: is_some ( doc. self_ty ) ;
149
+ let self_ty = option:: get ( doc. self_ty ) ;
150
+ alt doc. iface_ty {
151
+ some ( iface_ty) {
152
+ header_text_ (
153
+ "Implementation" ,
154
+ #fmt ( "%s of %s for %s" ,
155
+ doc. name ( ) , iface_ty, self_ty)
156
+ )
157
+ }
158
+ none {
159
+ header_text_(
160
+ "Implementation" ,
161
+ #fmt ( "%s for %s" , doc. name ( ) , self_ty)
162
+ )
163
+ }
164
+ }
165
+ }
166
+ doc:: tytag ( _) {
167
+ header_text_ ( "Type" , doc. name ( ) )
168
+ }
169
+ }
170
+ }
171
+
172
+ fn header_text_ ( kind : str , name : str ) -> str {
173
+ #fmt ( "%s `%s`" , kind, name)
174
+ }
175
+
114
176
fn write_crate (
115
177
ctxt : ctxt ,
116
178
doc : doc:: cratedoc
117
179
) {
118
- write_header ( ctxt, h1, # fmt ( "Crate %s" , doc. topmod . name ( ) ) ) ;
180
+ write_header ( ctxt, h1, doc :: modtag ( doc. topmod ) ) ;
119
181
write_top_module ( ctxt, doc. topmod ) ;
120
182
}
121
183
@@ -130,8 +192,7 @@ fn write_mod(
130
192
ctxt : ctxt ,
131
193
moddoc : doc:: moddoc
132
194
) {
133
- let fullpath = str:: connect ( moddoc. path ( ) + [ moddoc. name ( ) ] , "::" ) ;
134
- write_header ( ctxt, h1, #fmt ( "Module `%s`" , fullpath) ) ;
195
+ write_header ( ctxt, h1, doc:: modtag ( moddoc) ) ;
135
196
write_mod_contents ( ctxt, moddoc) ;
136
197
}
137
198
@@ -176,8 +237,7 @@ fn should_write_crate_description() {
176
237
}
177
238
178
239
fn write_nmod ( ctxt : ctxt , doc : doc:: nmoddoc ) {
179
- let fullpath = str:: connect ( doc. path ( ) + [ doc. name ( ) ] , "::" ) ;
180
- write_header ( ctxt, h1, #fmt ( "Native module `%s`" , fullpath) ) ;
240
+ write_header ( ctxt, h1, doc:: nmodtag ( doc) ) ;
181
241
182
242
write_brief ( ctxt, doc. brief ( ) ) ;
183
243
write_desc ( ctxt, doc. desc ( ) ) ;
@@ -205,7 +265,7 @@ fn write_fn(
205
265
ctxt : ctxt ,
206
266
doc : doc:: fndoc
207
267
) {
208
- write_header ( ctxt, h2, # fmt ( "Function `%s`" , doc. name ( ) ) ) ;
268
+ write_header ( ctxt, h2, doc:: fntag ( doc ) ) ;
209
269
write_fnlike (
210
270
ctxt,
211
271
doc. sig ,
@@ -469,7 +529,7 @@ fn write_const(
469
529
ctxt : ctxt ,
470
530
doc : doc:: constdoc
471
531
) {
472
- write_header ( ctxt, h2, # fmt ( "Const `%s`" , doc. name ( ) ) ) ;
532
+ write_header ( ctxt, h2, doc:: consttag ( doc ) ) ;
473
533
write_sig ( ctxt, doc. ty ) ;
474
534
write_brief ( ctxt, doc. brief ( ) ) ;
475
535
write_desc ( ctxt, doc. desc ( ) ) ;
@@ -493,7 +553,7 @@ fn write_enum(
493
553
ctxt : ctxt ,
494
554
doc : doc:: enumdoc
495
555
) {
496
- write_header ( ctxt, h2, # fmt ( "Enum `%s`" , doc. name ( ) ) ) ;
556
+ write_header ( ctxt, h2, doc:: enumtag ( doc ) ) ;
497
557
write_brief ( ctxt, doc. brief ( ) ) ;
498
558
write_desc ( ctxt, doc. desc ( ) ) ;
499
559
write_variants ( ctxt, doc. variants ) ;
@@ -575,7 +635,7 @@ fn should_write_variant_list_with_signatures() {
575
635
}
576
636
577
637
fn write_res ( ctxt : ctxt , doc : doc:: resdoc ) {
578
- write_header ( ctxt, h2, # fmt ( "Resource `%s`" , doc. name ( ) ) ) ;
638
+ write_header ( ctxt, h2, doc:: restag ( doc ) ) ;
579
639
write_sig ( ctxt, doc. sig ) ;
580
640
write_brief ( ctxt, doc. brief ( ) ) ;
581
641
write_desc ( ctxt, doc. desc ( ) ) ;
@@ -602,7 +662,7 @@ fn should_write_resource_args() {
602
662
}
603
663
604
664
fn write_iface ( ctxt : ctxt , doc : doc:: ifacedoc ) {
605
- write_header ( ctxt, h2, # fmt ( "Interface `%s`" , doc. name ( ) ) ) ;
665
+ write_header ( ctxt, h2, doc:: ifacetag ( doc ) ) ;
606
666
write_brief ( ctxt, doc. brief ( ) ) ;
607
667
write_desc ( ctxt, doc. desc ( ) ) ;
608
668
write_methods ( ctxt, doc. methods ) ;
@@ -613,7 +673,7 @@ fn write_methods(ctxt: ctxt, docs: [doc::methoddoc]) {
613
673
}
614
674
615
675
fn write_method ( ctxt : ctxt , doc : doc:: methoddoc ) {
616
- write_header ( ctxt, h3, # fmt ( "Method `%s` " , doc. name ) ) ;
676
+ write_header_ ( ctxt, h3, header_text_ ( "Method" , doc. name ) ) ;
617
677
write_fnlike (
618
678
ctxt,
619
679
doc. sig ,
@@ -695,20 +755,7 @@ fn should_write_iface_method_failure_conditions() {
695
755
}
696
756
697
757
fn write_impl ( ctxt : ctxt , doc : doc:: impldoc ) {
698
- assert option:: is_some ( doc. self_ty ) ;
699
- let self_ty = option:: get ( doc. self_ty ) ;
700
- alt doc. iface_ty {
701
- some ( iface_ty) {
702
- write_header ( ctxt, h2,
703
- #fmt ( "Implementation `%s` of `%s` for `%s`" ,
704
- doc. name ( ) , iface_ty, self_ty) ) ;
705
- }
706
- none {
707
- write_header( ctxt, h2,
708
- #fmt ( "Implementation `%s` for `%s`" ,
709
- doc. name ( ) , self_ty) ) ;
710
- }
711
- }
758
+ write_header ( ctxt, h2, doc:: impltag ( doc) ) ;
712
759
write_brief ( ctxt, doc. brief ( ) ) ;
713
760
write_desc ( ctxt, doc. desc ( ) ) ;
714
761
write_methods ( ctxt, doc. methods ) ;
@@ -717,13 +764,14 @@ fn write_impl(ctxt: ctxt, doc: doc::impldoc) {
717
764
#[ test]
718
765
fn should_write_impl_header ( ) {
719
766
let markdown = test:: render ( "impl i for int { fn a() { } }" ) ;
720
- assert str:: contains ( markdown, "## Implementation `i` for `int`" ) ;
767
+ log ( error, markdown) ;
768
+ assert str:: contains ( markdown, "## Implementation `i for int`" ) ;
721
769
}
722
770
723
771
#[ test]
724
772
fn should_write_impl_header_with_iface ( ) {
725
773
let markdown = test:: render ( "impl i of j for int { fn a() { } }" ) ;
726
- assert str:: contains ( markdown, "## Implementation `i` of `j` for ` int`" ) ;
774
+ assert str:: contains ( markdown, "## Implementation `i of j for int`" ) ;
727
775
}
728
776
729
777
#[ test]
@@ -793,7 +841,7 @@ fn write_type(
793
841
ctxt : ctxt ,
794
842
doc : doc:: tydoc
795
843
) {
796
- write_header ( ctxt, h2, # fmt ( "Type `%s`" , doc. name ( ) ) ) ;
844
+ write_header ( ctxt, h2, doc:: tytag ( doc ) ) ;
797
845
write_sig ( ctxt, doc. sig ) ;
798
846
write_brief ( ctxt, doc. brief ( ) ) ;
799
847
write_desc ( ctxt, doc. desc ( ) ) ;
@@ -881,7 +929,7 @@ mod test {
881
929
let doc = extract:: from_srv ( srv, "belch" ) ;
882
930
let doc = attr_pass:: mk_pass ( ) . f ( srv, doc) ;
883
931
let markdown = write_markdown_str ( doc) ;
884
- assert str:: contains ( markdown, "# Crate belch" ) ;
932
+ assert str:: contains ( markdown, "# Crate ` belch` " ) ;
885
933
}
886
934
}
887
935
0 commit comments