Skip to content

Commit b799598

Browse files
committed
Add template.sources config
1 parent ac9af00 commit b799598

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

packages/webdoc-cli/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ The `template` object is used by the site template.
138138
item defines a name and URI.
139139
* `template.routes`: This can be used to override specific routes generated by the template. For example, you can move the
140140
`tutorials` to be outputted at "/faq" instead of "/tutorials", if desired.
141+
* `template.sources`: (enabled by default) This will output the source code of the project as well and link symbols to their
142+
locations in the code.
141143
* `template.title`: This is the title shown in the browser tabs (defaults to `template.applicationName`). You should use this
142144
if you have HTML in the application name.
143145
* `template.meta`: (optional) This can be used to define the `<meta>` key-value tags. The `{{url}}` variable can be used

packages/webdoc-cli/src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type ConfigSchema = {
4848
routes: {
4949
tutorials: string,
5050
},
51+
sources: boolean,
5152
stylesheets: Array<string>,
5253
siteDomain?: string,
5354
siteRoot: string,
@@ -104,6 +105,7 @@ const defaultConfig: ConfigSchema = {
104105
tutorials: "tutorials",
105106
},
106107
siteRoot: "",
108+
sources: true,
107109
stylesheets: [],
108110
mainPage: {
109111
title: "Main Page",

packages/webdoc-default-template/publish.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ async function outSource(
270270
source /*: ?$ReadOnlyArray<SourceFile> */,
271271
mainThread /*:: ?: boolean */,
272272
)/*: Promise<void> */ {
273-
if (!source) return;
273+
if (!source || !config.template.sources) return;
274274

275275
function renderSource(file /*: SourceFile */, raw /*: string */) {
276276
const pkgName = file.package.name || "";
@@ -467,6 +467,7 @@ async function outReference(
467467
appBar: {current: "reference"},
468468
document: doc,
469469
explorerData,
470+
sources: config.template.sources,
470471
title: doc.name,
471472
require,
472473
env: config,

packages/webdoc-default-template/tmpl/components/member/index.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Object member render component.
44
*/
5-
const { doc, require } = obj;
5+
const { doc, require, sources } = obj;
66
const linkSvg = this.getPlugin("linker").getResourceURI("icons/link.svg");
77
const pkgName = doc.loc && doc.loc.file && doc.loc.file.package && doc.loc.file.package.name || "";
88
const pkgRelativePath = (doc.loc && doc.loc.file && doc.loc.file.package
@@ -33,7 +33,7 @@ const modifiers = [
3333
(deprecated)
3434
<?js } ?>
3535
</span>
36-
<?js if (source) { ?>
36+
<?js if (source && sources) { ?>
3737
<span class="tag--source">
3838
<a href="<?js= source + sourceLinkFragment ?>">
3939
<?js= sourceName + sourceStart ?>

packages/webdoc-default-template/tmpl/components/members.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const
3939
return true;
4040
});
4141
const require = obj.require;
42+
const sources = obj.sources;
4243

4344
if (categoryMembers.length === 0) {
4445
return;
@@ -49,6 +50,6 @@ if (categoryMembers.length === 0) {
4950
<hr />
5051

5152
<?js categoryMembers.forEach((member) => { ?>
52-
<?js= this.partial("components/member/index.tmpl", { doc: member, require }) ?>
53+
<?js= this.partial("components/member/index.tmpl", { doc: member, require, sources }) ?>
5354
<?js }) ?>
5455
</div>

packages/webdoc-default-template/tmpl/document.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
const doc = obj.document;
66
const require = obj.require;
7+
const sources = obj.sources;
78

89
const titleMods = [
910
doc.deprecated ? "document__title_deprecated" : ""
@@ -50,6 +51,7 @@
5051
type: "constructor",
5152
},
5253
require,
54+
sources,
5355
}) ?>
5456
<?js } ?>
5557

@@ -63,6 +65,7 @@
6365
type: "PropertyDoc",
6466
},
6567
require,
68+
sources,
6669
}) ?>
6770
<?js= this.partial("components/members.tmpl", {
6871
title: "Protected Properties",
@@ -72,6 +75,7 @@
7275
type: "PropertyDoc"
7376
},
7477
require,
78+
sources,
7579
}) ?>
7680
<?js= this.partial("components/members.tmpl", {
7781
title: "Public Methods",
@@ -81,6 +85,7 @@
8185
type: ["MethodDoc", "FunctionDoc"],
8286
},
8387
require,
88+
sources,
8489
}) ?>
8590
<?js= this.partial("components/members.tmpl", {
8691
title: "Protected Methods",
@@ -90,6 +95,7 @@
9095
type: ["MethodDoc", "FunctionDoc"]
9196
},
9297
require,
98+
sources,
9399
}) ?>
94100
<?js= this.partial("components/members.tmpl", {
95101
title: "Events",
@@ -98,6 +104,7 @@
98104
type: "EventDoc"
99105
},
100106
require,
107+
sources,
101108
}) ?>
102109
</div>
103110
<div class="footer-gap" style="min-height: 48px;"></div>

0 commit comments

Comments
 (0)