Skip to content

Commit 2cd659a

Browse files
committed
Merge pull request #720 from dart-lang/devoncarew_source_link
show a source link in the subnav
2 parents 7597201 + 56115da commit 2cd659a

File tree

9 files changed

+49
-21
lines changed

9 files changed

+49
-21
lines changed

lib/src/html_generator.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ class HtmlGeneratorInstance {
323323
'layoutTitle': _layoutTitle(
324324
constructor.name, 'constructor', constructor.isDeprecated),
325325
'navLinks': [package, lib, clazz],
326+
'subnavItems': _gatherSubnavForInvokable(constructor),
326327
'htmlBase': '../..',
327328
'self': constructor
328329
};
@@ -362,6 +363,7 @@ class HtmlGeneratorInstance {
362363
'metaDescription':
363364
'API docs for the ${function.name} function from the ${lib.name} library, for the Dart programming language.',
364365
'navLinks': [package, lib],
366+
'subnavItems': _gatherSubnavForInvokable(function),
365367
'htmlBase': '..',
366368
'self': function
367369
};
@@ -386,6 +388,7 @@ class HtmlGeneratorInstance {
386388
'metaDescription':
387389
'API docs for the ${method.name} method from the ${clazz.name} class, for the Dart programming language.',
388390
'navLinks': [package, lib, clazz],
391+
'subnavItems': _gatherSubnavForInvokable(method),
389392
'htmlBase': '../..',
390393
'self': method
391394
};
@@ -601,6 +604,15 @@ List<Subnav> _gatherSubnavForClass(Class clazz) {
601604
return navs;
602605
}
603606

607+
List<Subnav> _gatherSubnavForInvokable(ModelElement element) {
608+
if (element is SourceCodeMixin &&
609+
(element as SourceCodeMixin).hasSourceCode) {
610+
return [new Subnav('Source', '${element.href}#source')];
611+
} else {
612+
return [];
613+
}
614+
}
615+
604616
String _layoutTitle(String name, String kind, bool isDeprecated) {
605617
if (kind.isEmpty) kind =
606618
'&nbsp;'; // Ugly. fixes https://github.com/dart-lang/dartdoc/issues/695

lib/src/model.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,10 +1126,13 @@ abstract class SourceCodeMixin {
11261126
String remainer = source.trimLeft();
11271127
String indent = source.substring(0, source.length - remainer.length);
11281128
return source.split('\n').map((line) {
1129+
line = line.trimRight();
11291130
return line.startsWith(indent) ? line.substring(indent.length) : line;
11301131
}).join('\n');
11311132
}
11321133

1134+
bool get hasSourceCode => sourceCode.trim().isNotEmpty;
1135+
11331136
Element get element;
11341137
}
11351138

lib/templates/_source_code.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<section class="summary source-code">
1+
<section class="summary source-code" id="source">
22
<h2>Source</h2>
33
<pre><code class="prettyprint lang-dart">{{ sourceCode }}</code></pre>
44
</section>

lib/templates/constant.html

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
{{>head}}
2+
<div class="row row-offcanvas row-offcanvas-left">
23

3-
<section class="multi-line-signature">
4-
{{#property}}
5-
<span class="returntype">{{{ linkedReturnType }}}</span>
6-
{{>name_summary}}
7-
=
8-
<span class="constant-value">{{{ constantValue }}}</span>
9-
{{/property}}
10-
</section>
11-
12-
{{#property}}
13-
{{>documentation}}
14-
{{/property}}
4+
<div class="col-xs-6 col-sm-3 sidebar-offcanvas">
5+
6+
<h5>{{{class.linkedName}}}</h5>
7+
8+
{{>sidebar_for_class}}
9+
10+
</div><!--/.sidebar-offcanvas-->
11+
12+
<div class="col-xs-12 col-sm-9">
13+
14+
<section class="multi-line-signature">
15+
{{#property}}
16+
<span class="returntype">{{{ linkedReturnType }}}</span>
17+
{{>name_summary}}
18+
=
19+
<span class="constant-value">{{{ constantValue }}}</span>
20+
{{/property}}
21+
</section>
22+
23+
{{#property}}
24+
{{>documentation}}
25+
{{/property}}
26+
27+
</div> <!-- /.col-xs-12.col-sm-9 -->
28+
29+
</div> <!-- /.row-offcanvas -->
1530

1631
{{>footer}}

lib/templates/constructor.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ <h5>{{{class.linkedName}}}</h5>
2828
{{>documentation}}
2929
{{/constructor}}
3030

31+
{{#constructor}}
32+
{{#hasSourceCode}}
33+
{{>source_code}}
34+
{{/hasSourceCode}}
35+
{{/constructor}}
36+
3137
</div> <!-- /.col-xs-12.col-sm-9 -->
3238

3339
</div> <!-- /.row-offcanvas -->

lib/templates/function.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<div class="row row-offcanvas row-offcanvas-left">
44

55
<div class="col-xs-6 col-sm-3 sidebar-offcanvas">
6-
<h5>{{{library.linkedName}}}</h5>
7-
86
<ol id="sidebar">
97
{{#library.hasConstants}}
108
<li class="section-title"><a href="{{library.href}}#constants">Constants</a></li>

lib/templates/top_level_constant.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<div class="row row-offcanvas row-offcanvas-left">
44

55
<div class="col-xs-6 col-sm-3 sidebar-offcanvas">
6-
<h5>{{{library.linkedName}}}</h5>
7-
86
<ol id="sidebar">
97
{{#library.hasConstants}}
108
<li class="section-title"><a href="{{library.href}}#constants">Constants</a></li>

lib/templates/top_level_property.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<div class="row row-offcanvas row-offcanvas-left">
44

55
<div class="col-xs-6 col-sm-3 sidebar-offcanvas">
6-
<h5>{{{library.linkedName}}}</h5>
7-
86
<ol id="sidebar">
97
{{#library.hasConstants}}
108
<li class="section-title"><a href="{{library.href}}#constants">Constants</a></li>

lib/templates/typedef.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
<div class="row row-offcanvas row-offcanvas-left">
44

55
<div class="col-xs-6 col-sm-3 sidebar-offcanvas">
6-
<h5>{{{library.linkedName}}}</h5>
7-
86
<ol id="sidebar">
97
{{#library.hasConstants}}
108
<li class="section-title"><a href="{{library.href}}#constants">Constants</a></li>

0 commit comments

Comments
 (0)