Skip to content

Commit f34ad02

Browse files
authored
Merge pull request #79 from python-project-templates/tkp/b
Add sphinx-js integration
2 parents 30b515e + 411114f commit f34ad02

File tree

14 files changed

+780
-0
lines changed

14 files changed

+780
-0
lines changed

.github/workflows/build.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ jobs:
4242
- name: Install Rust
4343
uses: dtolnay/rust-toolchain@stable
4444

45+
- name: Setup Node.js
46+
uses: actions/setup-node@v4
47+
with:
48+
node-version: '20'
49+
50+
- name: Install JSDoc/TypeDoc
51+
run: npm install -g jsdoc typedoc
52+
4553
- name: Install doxygen
4654
run: sudo apt-get install -y doxygen
4755

.github/workflows/docs.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ jobs:
1515
- name: Install Rust
1616
uses: dtolnay/rust-toolchain@stable
1717

18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20'
22+
23+
- name: Install JSDoc/TypeDoc
24+
run: npm install -g jsdoc typedoc
25+
1826
- name: Install doxygen
1927
run: sudo apt-get install -y doxygen
2028

docs/src/api.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,47 @@ Or document specific structs, enums, and functions:
103103
104104
```
105105

106+
## JavaScript Example
107+
108+
This is an example of documenting JavaScript code using sphinx-js integration.
109+
110+
### Document Functions
111+
112+
Use `js:autofunction` to document individual functions:
113+
114+
```{eval-rst}
115+
.. js:autofunction:: add
116+
117+
```
118+
119+
```{eval-rst}
120+
.. js:autofunction:: subtract
121+
122+
```
123+
124+
```{eval-rst}
125+
.. js:autofunction:: multiply
126+
127+
```
128+
129+
```{eval-rst}
130+
.. js:autofunction:: divide
131+
132+
```
133+
134+
### Document Classes
135+
136+
Use `js:autoclass` to document classes:
137+
138+
```{eval-rst}
139+
.. js:autoclass:: Calculator
140+
:members:
141+
142+
```
143+
144+
```{eval-rst}
145+
.. js:autoclass:: ScientificCalculator
146+
:members:
147+
148+
```
149+

docs/src/configuration.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,118 @@ Then in your documentation files, you can use sphinx-rust directives:
562562

563563
\`\`\`
564564
````
565+
566+
## Sphinx-JS Integration
567+
568+
Yardang provides integration with [sphinx-js](https://pypi.org/project/sphinx-js/) for documenting JavaScript and TypeScript code. To use this feature, you also need JSDoc or TypeDoc installed:
569+
570+
```bash
571+
# For JavaScript projects
572+
npm install jsdoc
573+
574+
# For TypeScript projects
575+
npm install typedoc
576+
```
577+
578+
All sphinx-js configuration is under `[tool.yardang.sphinx-js]`.
579+
580+
### `js-source-path`
581+
582+
A list of directories containing your JS/TS source files, relative to the project root. This is required to enable sphinx-js.
583+
584+
```toml
585+
[tool.yardang.sphinx-js]
586+
js-source-path = ["src", "lib"]
587+
```
588+
589+
Or as a single path:
590+
591+
```toml
592+
[tool.yardang.sphinx-js]
593+
js-source-path = "src"
594+
```
595+
596+
### `js-language`
597+
598+
The language of your source files. Use `"javascript"` (default) or `"typescript"`.
599+
600+
```toml
601+
[tool.yardang.sphinx-js]
602+
js-language = "typescript"
603+
```
604+
605+
### `root-for-relative-js-paths`
606+
607+
The root directory for resolving relative JS entity paths. Required if you have multiple `js-source-path` entries.
608+
609+
```toml
610+
[tool.yardang.sphinx-js]
611+
root-for-relative-js-paths = "src"
612+
```
613+
614+
### `jsdoc-config-path`
615+
616+
Path to a JSDoc configuration file.
617+
618+
```toml
619+
[tool.yardang.sphinx-js]
620+
jsdoc-config-path = "jsdoc.json"
621+
```
622+
623+
### `jsdoc-tsconfig-path`
624+
625+
Path to a TypeScript configuration file (for TypeDoc).
626+
627+
```toml
628+
[tool.yardang.sphinx-js]
629+
jsdoc-tsconfig-path = "tsconfig.json"
630+
```
631+
632+
### `ts-type-bold`
633+
634+
Make TypeScript types bold in the output. Defaults to `false`.
635+
636+
```toml
637+
[tool.yardang.sphinx-js]
638+
ts-type-bold = true
639+
```
640+
641+
### Complete Example
642+
643+
Here's a complete example configuration for a TypeScript project:
644+
645+
```toml
646+
[tool.yardang]
647+
title = "My TypeScript Library"
648+
root = "docs/index.md"
649+
pages = ["docs/api.md", "docs/examples.md"]
650+
use-autoapi = false
651+
652+
[tool.yardang.sphinx-js]
653+
js-language = "typescript"
654+
js-source-path = ["src"]
655+
jsdoc-tsconfig-path = "tsconfig.json"
656+
ts-type-bold = true
657+
```
658+
659+
Then in your documentation files, you can use sphinx-js directives:
660+
661+
````markdown
662+
# API Reference
663+
664+
## Functions
665+
666+
\`\`\`{js:autofunction} myFunction
667+
\`\`\`
668+
669+
## Classes
670+
671+
\`\`\`{js:autoclass} MyClass
672+
:members:
673+
\`\`\`
674+
675+
## Modules
676+
677+
\`\`\`{js:automodule} myModule
678+
\`\`\`
679+
````

examples/js/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
docs/

examples/js/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# JavaScript Calculator Example
2+
3+
This is an example JavaScript project demonstrating sphinx-js documentation with yardang.
4+
5+
## Features
6+
7+
- Basic arithmetic operations (add, subtract, multiply, divide)
8+
- Calculator class with operation history
9+
- Scientific calculator with trigonometric functions
10+
- Full JSDoc documentation
11+
12+
## Usage
13+
14+
```javascript
15+
import { Calculator, Operation, add, multiply } from 'calculator';
16+
17+
// Using standalone functions
18+
const sum = add(5, 3); // 8
19+
const product = multiply(4, 5); // 20
20+
21+
// Using the Calculator class
22+
const calc = new Calculator();
23+
calc.calculate(10, 5, Operation.ADD); // 15
24+
calc.calculate(20, 4, Operation.DIVIDE); // 5
25+
26+
// View history
27+
console.log(calc.getHistory());
28+
```
29+
30+
## Documentation
31+
32+
Documentation is generated using JSDoc and integrated into the main yardang documentation using sphinx-js.

examples/js/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "calculator",
3+
"version": "1.0.0",
4+
"description": "A simple calculator library demonstrating JavaScript documentation with sphinx-js",
5+
"main": "src/index.js",
6+
"type": "module",
7+
"scripts": {
8+
"docs": "jsdoc src -d docs"
9+
},
10+
"keywords": ["calculator", "math", "example"],
11+
"author": "yardang authors",
12+
"license": "Apache-2.0",
13+
"devDependencies": {
14+
"jsdoc": "^4.0.0"
15+
}
16+
}

0 commit comments

Comments
 (0)