├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE.txt ├── LICENSE-MIT.txt ├── README.md ├── assets ├── fn-block.html.hbs ├── logo.png ├── logo.svg ├── page.html.hbs ├── rhai.toml └── styles.tpl.css ├── examples ├── README.md └── basic │ ├── assets │ ├── custom.css │ └── icon.png │ ├── example.rhai │ ├── nested │ ├── deep │ │ └── example.rhai │ └── empty.rhai │ ├── pages │ ├── another │ │ └── deep │ │ │ └── folder │ │ │ └── chain │ │ │ └── anything.md │ ├── home.md │ └── junk.md │ └── rhai.toml └── src ├── cli.rs ├── config.rs ├── data.rs ├── error.rs └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/dist 3 | .vscode 4 | Cargo.lock 5 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "ahash" 7 | version = "0.8.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107" 10 | dependencies = [ 11 | "cfg-if", 12 | "const-random", 13 | "getrandom", 14 | "once_cell", 15 | "version_check", 16 | ] 17 | 18 | [[package]] 19 | name = "atty" 20 | version = "0.2.14" 21 | source = "registry+https://github.com/rust-lang/crates.io-index" 22 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 23 | dependencies = [ 24 | "hermit-abi", 25 | "libc", 26 | "winapi", 27 | ] 28 | 29 | [[package]] 30 | name = "autocfg" 31 | version = "1.1.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 34 | 35 | [[package]] 36 | name = "bitflags" 37 | version = "1.3.2" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 40 | 41 | [[package]] 42 | name = "block-buffer" 43 | version = "0.10.3" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" 46 | dependencies = [ 47 | "generic-array", 48 | ] 49 | 50 | [[package]] 51 | name = "cfg-if" 52 | version = "1.0.0" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 55 | 56 | [[package]] 57 | name = "clap" 58 | version = "4.0.26" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "2148adefda54e14492fb9bddcc600b4344c5d1a3123bd666dcb939c6f0e0e57e" 61 | dependencies = [ 62 | "atty", 63 | "bitflags", 64 | "clap_derive", 65 | "clap_lex", 66 | "once_cell", 67 | "strsim", 68 | "termcolor", 69 | ] 70 | 71 | [[package]] 72 | name = "clap_derive" 73 | version = "4.0.21" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" 76 | dependencies = [ 77 | "heck", 78 | "proc-macro-error", 79 | "proc-macro2", 80 | "quote", 81 | "syn", 82 | ] 83 | 84 | [[package]] 85 | name = "clap_lex" 86 | version = "0.3.0" 87 | source = "registry+https://github.com/rust-lang/crates.io-index" 88 | checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" 89 | dependencies = [ 90 | "os_str_bytes", 91 | ] 92 | 93 | [[package]] 94 | name = "const-random" 95 | version = "0.1.15" 96 | source = "registry+https://github.com/rust-lang/crates.io-index" 97 | checksum = "368a7a772ead6ce7e1de82bfb04c485f3db8ec744f72925af5735e29a22cc18e" 98 | dependencies = [ 99 | "const-random-macro", 100 | "proc-macro-hack", 101 | ] 102 | 103 | [[package]] 104 | name = "const-random-macro" 105 | version = "0.1.15" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "9d7d6ab3c3a2282db210df5f02c4dab6e0a7057af0fb7ebd4070f30fe05c0ddb" 108 | dependencies = [ 109 | "getrandom", 110 | "once_cell", 111 | "proc-macro-hack", 112 | "tiny-keccak", 113 | ] 114 | 115 | [[package]] 116 | name = "cpufeatures" 117 | version = "0.2.5" 118 | source = "registry+https://github.com/rust-lang/crates.io-index" 119 | checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" 120 | dependencies = [ 121 | "libc", 122 | ] 123 | 124 | [[package]] 125 | name = "crunchy" 126 | version = "0.2.2" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" 129 | 130 | [[package]] 131 | name = "crypto-common" 132 | version = "0.1.6" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" 135 | dependencies = [ 136 | "generic-array", 137 | "typenum", 138 | ] 139 | 140 | [[package]] 141 | name = "digest" 142 | version = "0.10.6" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" 145 | dependencies = [ 146 | "block-buffer", 147 | "crypto-common", 148 | ] 149 | 150 | [[package]] 151 | name = "generic-array" 152 | version = "0.14.6" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" 155 | dependencies = [ 156 | "typenum", 157 | "version_check", 158 | ] 159 | 160 | [[package]] 161 | name = "getopts" 162 | version = "0.2.21" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" 165 | dependencies = [ 166 | "unicode-width", 167 | ] 168 | 169 | [[package]] 170 | name = "getrandom" 171 | version = "0.2.8" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" 174 | dependencies = [ 175 | "cfg-if", 176 | "libc", 177 | "wasi", 178 | ] 179 | 180 | [[package]] 181 | name = "glob" 182 | version = "0.3.0" 183 | source = "registry+https://github.com/rust-lang/crates.io-index" 184 | checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" 185 | 186 | [[package]] 187 | name = "handlebars" 188 | version = "4.3.5" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | checksum = "433e4ab33f1213cdc25b5fa45c76881240cfe79284cf2b395e8b9e312a30a2fd" 191 | dependencies = [ 192 | "log", 193 | "pest", 194 | "pest_derive", 195 | "serde", 196 | "serde_json", 197 | "thiserror", 198 | ] 199 | 200 | [[package]] 201 | name = "heck" 202 | version = "0.4.0" 203 | source = "registry+https://github.com/rust-lang/crates.io-index" 204 | checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" 205 | 206 | [[package]] 207 | name = "hermit-abi" 208 | version = "0.1.19" 209 | source = "registry+https://github.com/rust-lang/crates.io-index" 210 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 211 | dependencies = [ 212 | "libc", 213 | ] 214 | 215 | [[package]] 216 | name = "instant" 217 | version = "0.1.12" 218 | source = "registry+https://github.com/rust-lang/crates.io-index" 219 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" 220 | dependencies = [ 221 | "cfg-if", 222 | ] 223 | 224 | [[package]] 225 | name = "itoa" 226 | version = "1.0.4" 227 | source = "registry+https://github.com/rust-lang/crates.io-index" 228 | checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" 229 | 230 | [[package]] 231 | name = "libc" 232 | version = "0.2.137" 233 | source = "registry+https://github.com/rust-lang/crates.io-index" 234 | checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" 235 | 236 | [[package]] 237 | name = "log" 238 | version = "0.4.17" 239 | source = "registry+https://github.com/rust-lang/crates.io-index" 240 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 241 | dependencies = [ 242 | "cfg-if", 243 | ] 244 | 245 | [[package]] 246 | name = "memchr" 247 | version = "2.5.0" 248 | source = "registry+https://github.com/rust-lang/crates.io-index" 249 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 250 | 251 | [[package]] 252 | name = "num-traits" 253 | version = "0.2.15" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 256 | dependencies = [ 257 | "autocfg", 258 | ] 259 | 260 | [[package]] 261 | name = "once_cell" 262 | version = "1.16.0" 263 | source = "registry+https://github.com/rust-lang/crates.io-index" 264 | checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" 265 | 266 | [[package]] 267 | name = "os_str_bytes" 268 | version = "6.4.1" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" 271 | 272 | [[package]] 273 | name = "pest" 274 | version = "2.4.1" 275 | source = "registry+https://github.com/rust-lang/crates.io-index" 276 | checksum = "a528564cc62c19a7acac4d81e01f39e53e25e17b934878f4c6d25cc2836e62f8" 277 | dependencies = [ 278 | "thiserror", 279 | "ucd-trie", 280 | ] 281 | 282 | [[package]] 283 | name = "pest_derive" 284 | version = "2.4.1" 285 | source = "registry+https://github.com/rust-lang/crates.io-index" 286 | checksum = "d5fd9bc6500181952d34bd0b2b0163a54d794227b498be0b7afa7698d0a7b18f" 287 | dependencies = [ 288 | "pest", 289 | "pest_generator", 290 | ] 291 | 292 | [[package]] 293 | name = "pest_generator" 294 | version = "2.4.1" 295 | source = "registry+https://github.com/rust-lang/crates.io-index" 296 | checksum = "d2610d5ac5156217b4ff8e46ddcef7cdf44b273da2ac5bca2ecbfa86a330e7c4" 297 | dependencies = [ 298 | "pest", 299 | "pest_meta", 300 | "proc-macro2", 301 | "quote", 302 | "syn", 303 | ] 304 | 305 | [[package]] 306 | name = "pest_meta" 307 | version = "2.4.1" 308 | source = "registry+https://github.com/rust-lang/crates.io-index" 309 | checksum = "824749bf7e21dd66b36fbe26b3f45c713879cccd4a009a917ab8e045ca8246fe" 310 | dependencies = [ 311 | "once_cell", 312 | "pest", 313 | "sha1", 314 | ] 315 | 316 | [[package]] 317 | name = "proc-macro-error" 318 | version = "1.0.4" 319 | source = "registry+https://github.com/rust-lang/crates.io-index" 320 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 321 | dependencies = [ 322 | "proc-macro-error-attr", 323 | "proc-macro2", 324 | "quote", 325 | "syn", 326 | "version_check", 327 | ] 328 | 329 | [[package]] 330 | name = "proc-macro-error-attr" 331 | version = "1.0.4" 332 | source = "registry+https://github.com/rust-lang/crates.io-index" 333 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 334 | dependencies = [ 335 | "proc-macro2", 336 | "quote", 337 | "version_check", 338 | ] 339 | 340 | [[package]] 341 | name = "proc-macro-hack" 342 | version = "0.5.19" 343 | source = "registry+https://github.com/rust-lang/crates.io-index" 344 | checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" 345 | 346 | [[package]] 347 | name = "proc-macro2" 348 | version = "1.0.47" 349 | source = "registry+https://github.com/rust-lang/crates.io-index" 350 | checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 351 | dependencies = [ 352 | "unicode-ident", 353 | ] 354 | 355 | [[package]] 356 | name = "pulldown-cmark" 357 | version = "0.9.2" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "2d9cc634bc78768157b5cbfe988ffcd1dcba95cd2b2f03a88316c08c6d00ed63" 360 | dependencies = [ 361 | "bitflags", 362 | "getopts", 363 | "memchr", 364 | "unicase", 365 | ] 366 | 367 | [[package]] 368 | name = "quote" 369 | version = "1.0.21" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 372 | dependencies = [ 373 | "proc-macro2", 374 | ] 375 | 376 | [[package]] 377 | name = "rhai" 378 | version = "1.11.0" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | checksum = "0f61559c2ea5fef5af856ae95443111dc14e7c9ce73d29c257a840249c0ed298" 381 | dependencies = [ 382 | "ahash", 383 | "bitflags", 384 | "instant", 385 | "num-traits", 386 | "rhai_codegen", 387 | "serde", 388 | "serde_json", 389 | "smallvec", 390 | "smartstring", 391 | ] 392 | 393 | [[package]] 394 | name = "rhai-doc" 395 | version = "0.2.4" 396 | dependencies = [ 397 | "clap", 398 | "glob", 399 | "handlebars", 400 | "pulldown-cmark", 401 | "rhai", 402 | "serde", 403 | "toml", 404 | ] 405 | 406 | [[package]] 407 | name = "rhai_codegen" 408 | version = "1.4.2" 409 | source = "registry+https://github.com/rust-lang/crates.io-index" 410 | checksum = "36791b0b801159db25130fd46ac726d2751c070260bba3a4a0a3eeb6231bb82a" 411 | dependencies = [ 412 | "proc-macro2", 413 | "quote", 414 | "syn", 415 | ] 416 | 417 | [[package]] 418 | name = "ryu" 419 | version = "1.0.11" 420 | source = "registry+https://github.com/rust-lang/crates.io-index" 421 | checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" 422 | 423 | [[package]] 424 | name = "serde" 425 | version = "1.0.147" 426 | source = "registry+https://github.com/rust-lang/crates.io-index" 427 | checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" 428 | dependencies = [ 429 | "serde_derive", 430 | ] 431 | 432 | [[package]] 433 | name = "serde_derive" 434 | version = "1.0.147" 435 | source = "registry+https://github.com/rust-lang/crates.io-index" 436 | checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" 437 | dependencies = [ 438 | "proc-macro2", 439 | "quote", 440 | "syn", 441 | ] 442 | 443 | [[package]] 444 | name = "serde_json" 445 | version = "1.0.89" 446 | source = "registry+https://github.com/rust-lang/crates.io-index" 447 | checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" 448 | dependencies = [ 449 | "itoa", 450 | "ryu", 451 | "serde", 452 | ] 453 | 454 | [[package]] 455 | name = "sha1" 456 | version = "0.10.5" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" 459 | dependencies = [ 460 | "cfg-if", 461 | "cpufeatures", 462 | "digest", 463 | ] 464 | 465 | [[package]] 466 | name = "smallvec" 467 | version = "1.10.0" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" 470 | dependencies = [ 471 | "serde", 472 | ] 473 | 474 | [[package]] 475 | name = "smartstring" 476 | version = "1.0.1" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" 479 | dependencies = [ 480 | "autocfg", 481 | "serde", 482 | "static_assertions", 483 | "version_check", 484 | ] 485 | 486 | [[package]] 487 | name = "static_assertions" 488 | version = "1.1.0" 489 | source = "registry+https://github.com/rust-lang/crates.io-index" 490 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 491 | 492 | [[package]] 493 | name = "strsim" 494 | version = "0.10.0" 495 | source = "registry+https://github.com/rust-lang/crates.io-index" 496 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 497 | 498 | [[package]] 499 | name = "syn" 500 | version = "1.0.103" 501 | source = "registry+https://github.com/rust-lang/crates.io-index" 502 | checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" 503 | dependencies = [ 504 | "proc-macro2", 505 | "quote", 506 | "unicode-ident", 507 | ] 508 | 509 | [[package]] 510 | name = "termcolor" 511 | version = "1.1.3" 512 | source = "registry+https://github.com/rust-lang/crates.io-index" 513 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 514 | dependencies = [ 515 | "winapi-util", 516 | ] 517 | 518 | [[package]] 519 | name = "thiserror" 520 | version = "1.0.37" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" 523 | dependencies = [ 524 | "thiserror-impl", 525 | ] 526 | 527 | [[package]] 528 | name = "thiserror-impl" 529 | version = "1.0.37" 530 | source = "registry+https://github.com/rust-lang/crates.io-index" 531 | checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" 532 | dependencies = [ 533 | "proc-macro2", 534 | "quote", 535 | "syn", 536 | ] 537 | 538 | [[package]] 539 | name = "tiny-keccak" 540 | version = "2.0.2" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" 543 | dependencies = [ 544 | "crunchy", 545 | ] 546 | 547 | [[package]] 548 | name = "toml" 549 | version = "0.5.9" 550 | source = "registry+https://github.com/rust-lang/crates.io-index" 551 | checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" 552 | dependencies = [ 553 | "serde", 554 | ] 555 | 556 | [[package]] 557 | name = "typenum" 558 | version = "1.15.0" 559 | source = "registry+https://github.com/rust-lang/crates.io-index" 560 | checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" 561 | 562 | [[package]] 563 | name = "ucd-trie" 564 | version = "0.1.5" 565 | source = "registry+https://github.com/rust-lang/crates.io-index" 566 | checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" 567 | 568 | [[package]] 569 | name = "unicase" 570 | version = "2.6.0" 571 | source = "registry+https://github.com/rust-lang/crates.io-index" 572 | checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" 573 | dependencies = [ 574 | "version_check", 575 | ] 576 | 577 | [[package]] 578 | name = "unicode-ident" 579 | version = "1.0.5" 580 | source = "registry+https://github.com/rust-lang/crates.io-index" 581 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 582 | 583 | [[package]] 584 | name = "unicode-width" 585 | version = "0.1.10" 586 | source = "registry+https://github.com/rust-lang/crates.io-index" 587 | checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" 588 | 589 | [[package]] 590 | name = "version_check" 591 | version = "0.9.4" 592 | source = "registry+https://github.com/rust-lang/crates.io-index" 593 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 594 | 595 | [[package]] 596 | name = "wasi" 597 | version = "0.11.0+wasi-snapshot-preview1" 598 | source = "registry+https://github.com/rust-lang/crates.io-index" 599 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 600 | 601 | [[package]] 602 | name = "winapi" 603 | version = "0.3.9" 604 | source = "registry+https://github.com/rust-lang/crates.io-index" 605 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 606 | dependencies = [ 607 | "winapi-i686-pc-windows-gnu", 608 | "winapi-x86_64-pc-windows-gnu", 609 | ] 610 | 611 | [[package]] 612 | name = "winapi-i686-pc-windows-gnu" 613 | version = "0.4.0" 614 | source = "registry+https://github.com/rust-lang/crates.io-index" 615 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 616 | 617 | [[package]] 618 | name = "winapi-util" 619 | version = "0.1.5" 620 | source = "registry+https://github.com/rust-lang/crates.io-index" 621 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 622 | dependencies = [ 623 | "winapi", 624 | ] 625 | 626 | [[package]] 627 | name = "winapi-x86_64-pc-windows-gnu" 628 | version = "0.4.0" 629 | source = "registry+https://github.com/rust-lang/crates.io-index" 630 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 631 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rhai-doc" 3 | description = "Documentation tool for Rhai - an embedded scripting language and engine for Rust" 4 | version = "0.2.4" 5 | authors = ["semirix", "schungx"] 6 | edition = "2018" 7 | resolver = "2" 8 | homepage = "https://github.com/rhaiscript/rhai-doc" 9 | repository = "https://github.com/rhaiscript/rhai-doc" 10 | readme = "README.md" 11 | license = "MIT OR Apache-2.0" 12 | keywords = ["Rhai", "scripting", "scripting-language", "documentation", "site-generator"] 13 | categories = ["command-line-utilities", "development-tools", "parser-implementations"] 14 | exclude = ["/examples"] 15 | 16 | [dependencies] 17 | rhai = { version = "1", features = [ "metadata" ] } 18 | handlebars = "4" 19 | pulldown-cmark = { version="0.9", features = ["simd"] } 20 | glob = "0.3" 21 | serde = { version = "1.0", features = ["derive"] } 22 | toml = "0.5" 23 | clap = { version = "4", features = ["derive"] } 24 | -------------------------------------------------------------------------------- /LICENSE-APACHE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /LICENSE-MIT.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any 2 | person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the 4 | Software without restriction, including without 5 | limitation the rights to use, copy, modify, merge, 6 | publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software 8 | is furnished to do so, subject to the following 9 | conditions: 10 | 11 | The above copyright notice and this permission notice 12 | shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | `rhai-doc` - Generates HTML Documentation from Rhai Script Files 2 | ============================================================== 3 | 4 | [![License](https://img.shields.io/crates/l/rhai)](https://github.com/license/rhaiscript/rhai-doc) 5 | [![crates.io](https://img.shields.io/crates/v/rhai-doc?logo=rust)](https://crates.io/crates/rhai-doc/) 6 | [![crates.io](https://img.shields.io/crates/d/rhai-doc?logo=rust)](https://crates.io/crates/rhai-doc/) 7 | 8 | `rhai-doc` is a tool for auto-generating documentation for [Rhai] scripts. 9 | 10 | It supports writing [MarkDown] documentation in [doc-comments] of [Rhai] scripts and creating 11 | general-purpose documentation pages. 12 | 13 | See an example [here](https://rhai.rs/rhai-doc). 14 | 15 | 16 | CLI Interface 17 | ------------- 18 | 19 | ```text 20 | USAGE: 21 | rhai-doc.exe [OPTIONS] [SUBCOMMAND] 22 | 23 | OPTIONS: 24 | -a, --all Generate documentation for all functions, including private ones 25 | -c, --config Set the configuration file [default: rhai.toml] 26 | -d, --dir Set the Rhai scripts (*.rhai) directory [default: .] 27 | -D, --dest Set the destination for the documentation output [default: dist] 28 | -h, --help Print help information 29 | -p, --pages Set the directory where MarkDown (*.md) pages files are located [default: 30 | pages] 31 | -v, --verbose Use multiple to set the level of verbosity: 1 = silent, 2 (default) = 32 | full, 3 = debug 33 | -V, --version Print version information 34 | 35 | SUBCOMMANDS: 36 | help Print this message or the help of the given subcommand(s) 37 | new Generates a new configuration file 38 | ``` 39 | 40 | 41 | Installation 42 | ------------ 43 | 44 | ### Install from `crates.io` 45 | 46 | ```sh 47 | cargo install rhai-doc 48 | ``` 49 | 50 | ### Install from source 51 | 52 | ```sh 53 | cargo install --path . 54 | ``` 55 | 56 | 57 | Configuration File 58 | ------------------ 59 | 60 | To get started, you need a configuration file. 61 | 62 | It is usually named `rhai.toml`, or you can specify one via the `--config` option. 63 | 64 | To generate a skeleton `rhai.toml`, use the `new` command: 65 | 66 | ```sh 67 | rhai-doc new 68 | ``` 69 | 70 | ### Example 71 | 72 | ```toml 73 | version = "1.0" # version of this TOML file 74 | name = "My Rhai Project" # project name 75 | color = [246, 119, 2] # theme color 76 | root = "/docs/" # root URL for generated site 77 | index = "home.md" # this file becomes 'index.html` 78 | icon = "logo.svg" # project icon 79 | stylesheet = "my_stylesheet.css" # custom stylesheet 80 | code_theme = "atom-one-light" # 'highlight.js' theme 81 | code_lang = "ts" # default language for code blocks 82 | extension = "rhai" # script extension 83 | google_analytics = "G-ABCDEF1234" # Google Analytics ID 84 | 85 | [[links]] # external link for 'Blog' 86 | name = "Blog" 87 | link = "https://example.com/blog" 88 | 89 | [[links]] # external link for 'Tools' 90 | name = "Tools" 91 | link = "https://example.com/tools" 92 | ``` 93 | 94 | ### Configuration options 95 | 96 | - `version`: Version of this TOML file; `1.0` is the current version. 97 | - `name`: The name of the project, if any. It's the title that shows up on the documentation pages. 98 | - `color`: RGB values of the theme color for the generated docs, if any. 99 | - `root`: The root URL generated as part of the documentation, if any. 100 | - `index`: The main [MarkDown] file, if any, that will become `index.html`. 101 | - `icon`: The location of a custom icon file, if any. 102 | - `stylesheet`: The location of a custom stylesheet, if any. 103 | - `code_theme`: The [`highlight.js`](https://highlightjs.org/) theme for syntax highlighting in code blocks (default `default`). 104 | - `code_lang`: Default language for code blocks (default `ts`). 105 | - `extension`: The extension of the script files `rhai-doc` will look for (default `.rhai`). 106 | - `google_analytics`: Google Analytics ID, if any. 107 | - `[[links]]`: External links, if any, to other sites of relevance. 108 | - `name`: Title of external link. 109 | - `link`: URL of external link. 110 | 111 | 112 | Doc-Comments 113 | ------------ 114 | 115 | [Rhai] supports [doc-comments] in [MarkDown] format on script-defined 116 | [functions](https://rhai.rs/book/language/functions.html). 117 | 118 | ```rust 119 | /// This function calculates a **secret number**! 120 | /// 121 | /// Formula provided from this [link](https://secret_formula.com/calc_secret_number). 122 | /// 123 | /// # Scale Factor 124 | /// Uses a scale factor obtained by calling [`get_contribution_factor`]. 125 | /// 126 | /// # Parameters 127 | /// `seed` - random seed to start the calculation 128 | /// 129 | /// # Returns 130 | /// The secret number! 131 | /// 132 | /// # Exceptions 133 | /// Throws when the seed is not positive. 134 | /// 135 | /// # Example 136 | /// ``` 137 | /// let secret = calc_secret_number(42); 138 | /// ``` 139 | fn calc_secret_number(seed) { 140 | if seed <= 0 { 141 | throw "the seed must be positive!"; 142 | } 143 | 144 | let factor = get_contribution_factor(seed); 145 | 146 | // Some very complex code skipped ... 147 | // ... 148 | } 149 | 150 | /// This function is private and will not be included 151 | /// unless the `-a` flag is used. 152 | private fn get_multiply_factor() { 153 | 42 154 | } 155 | 156 | /// This function calculates a scale factor for use 157 | /// in the [`calc_secret_number`] function. 158 | fn get_contribution_factor(x) { 159 | x * get_multiply_factor() 160 | } 161 | ``` 162 | 163 | 164 | Syntax Highlighting 165 | ------------------- 166 | 167 | [`highlight.js`](https://highlightjs.org/) is used for syntax highlighting in code blocks. 168 | 169 | The default language for code blocks is `ts` (i.e. TypeScript). This default is chosen because Rhai 170 | syntax mostly resembles JavaScript/TypeScript, and highlighting works properly for strings interpolation. 171 | 172 | 173 | Inter-Script Links 174 | ------------------ 175 | 176 | Functions documentation can cross-link to each other within the same script file. 177 | 178 | A link in the format ``[`my_func`]`` is automatically expanded to link to the documentation of 179 | the target function (in this case `my_func`). 180 | 181 | 182 | MarkDown Pages 183 | -------------- 184 | 185 | By default, `rhai-doc` will generate documentation pages from [MarkDown] documents within a 186 | `pages` sub-directory under the scripts directory. 187 | 188 | Alternatively, you can specify another location via the `--pages` option. 189 | 190 | 191 | Features 192 | -------- 193 | 194 | - [x] Generate documentation from [MarkDown] [doc-comments] in [Rhai] script files. 195 | - [x] Create general-purpose documentation pages. 196 | - [ ] Text search. 197 | - [ ] Linter for undocumented functions, parameters, etc. 198 | 199 | 200 | License 201 | ------- 202 | 203 | Licensed under either of the following, at your choice: 204 | 205 | - [Apache License, Version 2.0](https://github.com/semirix/rhai-doc/blob/master/LICENSE-APACHE.txt), or 206 | - [MIT license](https://github.com/semirix/rhai-doc/blob/master/LICENSE-MIT.txt) 207 | 208 | Unless explicitly stated otherwise, any contribution intentionally submitted 209 | for inclusion in this crate, as defined in the Apache-2.0 license, 210 | shall be dual-licensed as above, without any additional terms or conditions. 211 | 212 | 213 | [MarkDown]: https://en.wikipedia.org/wiki/Markdown 214 | [Rhai]: https://rhai.rs 215 | [doc-comments]: https://rhai.rs/book/language/doc-comments.html 216 | -------------------------------------------------------------------------------- /assets/fn-block.html.hbs: -------------------------------------------------------------------------------- 1 |
2 |
{{definition}}
3 |
{{markdown}}
4 |
-------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rhaiscript/rhai-doc/083ecd79b8d82fb9bde7d9eb5328c4a4e79e0277/assets/logo.png -------------------------------------------------------------------------------- /assets/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /assets/page.html.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | {{#if stylesheet}} 20 | 21 | {{/if}} 22 | 23 | {{title}} - {{name}} 24 | 25 | 26 | 27 |
28 | 43 |
44 |
45 |
46 | 68 |
69 | {{#if markdown}} 70 |
{{markdown}}
71 | {{/if}} 72 | {{#each functions}}{{>fn-block this}}{{/each}} 73 |
74 |
75 |
76 | 77 | 78 | 79 | 86 | 87 | {{#if google_analytics}} 88 | 89 | 90 | 97 | {{/if}} 98 | 99 | 100 | -------------------------------------------------------------------------------- /assets/rhai.toml: -------------------------------------------------------------------------------- 1 | version = "1.0" # Version of this TOML file 2 | name = "My Project" # Name of the project (optional) 3 | color = [246, 119, 2] # Theme color (optional) 4 | #root = "/docs/" # Root URL (optional) 5 | #index = "home.md" # Home page (optional) 6 | #icon = "icon.png" # Project icon (optional) 7 | #stylesheet = "custom.css" # Custom stylesheet (optional) 8 | #google_analytics = "G-ABCDEF1234" # Google Analytics ID (optional) 9 | 10 | # [[links]] sections encode HTML links to the header 11 | 12 | [[links]] 13 | name = "Source" 14 | link = "https://example.com/" 15 | 16 | [[links]] 17 | name = "Google" 18 | link = "https://www.google.com" 19 | -------------------------------------------------------------------------------- /assets/styles.tpl.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Manrope:wght@200;300;400;500;600;700;800&display=swap'); 2 | 3 | /* 4 | * RESET 5 | */ 6 | html, body, div, span, applet, object, iframe, 7 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 8 | a, abbr, acronym, address, big, cite, code, 9 | del, dfn, em, img, ins, kbd, q, s, samp, 10 | small, strike, strong, sub, sup, tt, var, 11 | b, u, i, center, 12 | dl, dt, dd, ol, ul, li, 13 | fieldset, form, label, legend, 14 | table, caption, tbody, tfoot, thead, tr, th, td, 15 | article, aside, canvas, details, embed, 16 | figure, figcaption, footer, header, hgroup, 17 | menu, nav, output, ruby, section, summary, 18 | time, mark, audio, video { 19 | margin: 0; 20 | padding: 0; 21 | border: 0; 22 | font-size: 100%; 23 | font: inherit; 24 | vertical-align: baseline; 25 | } 26 | 27 | article, aside, details, figcaption, figure, 28 | footer, header, hgroup, menu, nav, section { 29 | display: block; 30 | } 31 | 32 | body { 33 | line-height: 1; 34 | background-color: #aaa; 35 | } 36 | 37 | ol, ul { 38 | list-style: none; 39 | } 40 | 41 | blockquote, q { 42 | quotes: none; 43 | } 44 | 45 | blockquote:before, blockquote:after, 46 | q:before, q:after { 47 | content: ''; 48 | content: none; 49 | } 50 | 51 | table { 52 | border-collapse: collapse; 53 | border-spacing: 0; 54 | } 55 | 56 | /* 57 | * STYLES 58 | */ 59 | html, body { 60 | width: 100%; 61 | height: 100%; 62 | font-size: 16px; 63 | font-family: Manrope, Arial, "Helvetica Neue", Helvetica, sans-serif; 64 | font-weight: 500; 65 | color: #222222; 66 | } 67 | 68 | header { 69 | display: flex; 70 | flex-direction: row; 71 | flex-shrink: 0; 72 | background-color: #ffffff; 73 | border-bottom: 1px solid rgb(212, 218, 223); 74 | box-shadow: rgba(116, 129, 141, 0.1) 0px 3px 8px 0px; 75 | height: 5rem; 76 | justify-content: flex-start; 77 | align-items: center; 78 | padding: 0 2rem; 79 | position: absolute; 80 | top: 0; 81 | left: 0; 82 | right: 0; 83 | z-index: 9; 84 | } 85 | 86 | nav { 87 | width: 100%; 88 | max-width: 1000px; 89 | margin-left: auto; 90 | margin-right: auto; 91 | padding-left: 1rem; 92 | font-size: 1.3rem; 93 | } 94 | 95 | nav .title { 96 | font-weight: bold; 97 | padding: 0.5rem 0; 98 | font-size: 2rem; 99 | } 100 | 101 | nav > ul { 102 | display: flex; 103 | flex-direction: row; 104 | } 105 | 106 | nav > ul > li { 107 | margin-right: 1rem; 108 | } 109 | 110 | main { 111 | position: absolute; 112 | top: 0; 113 | bottom: 0; 114 | left: 0; 115 | right: 0; 116 | padding-top: 5rem; 117 | } 118 | 119 | #content { 120 | flex: 1; 121 | display: flex; 122 | flex-direction: row; 123 | overflow: auto; 124 | margin-left: auto; 125 | margin-right: auto; 126 | max-width: 1000px; 127 | height: 100%; 128 | z-index: 0; 129 | } 130 | 131 | section { 132 | flex: 1; 133 | overflow: auto; 134 | background-color: rgb(240, 242, 244); 135 | } 136 | 137 | aside { 138 | min-width: 15%; 139 | max-width: 25%; 140 | background-color: rgb(245, 247, 249); 141 | border-right: 1px solid rgb(230, 236, 241); 142 | padding: 1rem 2rem; 143 | overflow: auto; 144 | } 145 | 146 | aside > ul { 147 | width: 100%; 148 | } 149 | 150 | aside > div > a.link { 151 | font-weight: bold; 152 | font-variant: small-caps; 153 | font-size: 1.1rem; 154 | } 155 | 156 | aside > ul > li > a.link { 157 | font-weight: bold; 158 | } 159 | 160 | aside > ul > ul > li { 161 | margin: 0.5rem 0 0.5rem 2.5rem; 162 | font-size: 1rem; 163 | list-style: disc; 164 | } 165 | 166 | aside > ul > ul > li code { 167 | font-size: 1rem; 168 | } 169 | 170 | button, 171 | .button, 172 | aside .link { 173 | display: block; 174 | padding: 1rem; 175 | border-radius: 0.3rem; 176 | transition: all 0.3s; 177 | } 178 | 179 | button:hover, 180 | .button:hover, 181 | aside .link:hover { 182 | background-color: {{color_alpha}}; 183 | } 184 | 185 | code { 186 | font-family: monospace; 187 | font-size: 110%; 188 | } 189 | 190 | a { 191 | text-decoration: none; 192 | transition: color 0.3s; 193 | color: #222222; 194 | } 195 | 196 | a:hover, 197 | a:hover > span, 198 | aside .link.active { 199 | color: {{color}}; 200 | } 201 | 202 | .logo { 203 | width: auto; 204 | height: 3rem; 205 | } 206 | 207 | span.light { 208 | color: #bdbdbd; 209 | font-weight: 500; 210 | transition: color 0.3s; 211 | } 212 | 213 | hr.divider { 214 | height: 3rem; 215 | margin: 0; 216 | border: 0; 217 | border-left: 1px solid rgb(230, 236, 241); 218 | } 219 | 220 | /* 221 | * COMPONENTS 222 | */ 223 | .fn-block { 224 | background-color: white; 225 | margin: 1rem; 226 | padding: 2rem; 227 | border-radius: 0.3rem; 228 | box-shadow: rgba(0, 0, 0, 0.5) 0px 1rem 1rem -1rem; 229 | } 230 | 231 | .fn-block.private { 232 | background-color: #eef; 233 | } 234 | 235 | .fn-definition { 236 | margin-bottom: 1.5rem; 237 | } 238 | 239 | .fn-definition > code { 240 | font-size: 1.5rem; 241 | border: 0; 242 | background-color: transparent !important; 243 | padding: 0.5rem 0; 244 | } 245 | 246 | .menu-header { 247 | text-transform: uppercase; 248 | margin: 1.5rem 0; 249 | color: #aaaaaa; 250 | font-weight: bold; 251 | letter-spacing: 0.1em; 252 | text-align: center; 253 | } 254 | 255 | /* 256 | * MARKDOWN 257 | */ 258 | section > div.md { 259 | padding: 2rem; 260 | background-color: white; 261 | box-sizing: border-box; 262 | min-height: 100%; 263 | } 264 | 265 | .md h1, 266 | .md h2, 267 | .md h3, 268 | .md h4, 269 | .md h5, 270 | .md h6 { 271 | font-weight: 800; 272 | margin-bottom: 1.5rem; 273 | } 274 | 275 | .md h1 { 276 | font-size: 1.75rem; 277 | } 278 | 279 | .md h2 { 280 | font-size: 1.5rem; 281 | } 282 | 283 | .md h3 { 284 | font-size: 1.25rem; 285 | } 286 | 287 | .md h4 { 288 | font-size: 1rem; 289 | } 290 | 291 | .md h5 { 292 | font-size: 0.75rem; 293 | } 294 | 295 | .md h6 { 296 | font-size: 0.5rem; 297 | } 298 | 299 | .fn-description.md h1 { 300 | font-size: 1.3rem; 301 | color: #777; 302 | } 303 | 304 | .fn-description.md h2 { 305 | font-size: 1.2rem; 306 | color: #777; 307 | } 308 | 309 | .fn-description.md h3 { 310 | font-size: 1.1rem; 311 | color: #777; 312 | } 313 | 314 | .fn-description.md h4 { 315 | font-size: 1rem; 316 | color: #777; 317 | } 318 | 319 | .fn-description.md h5 { 320 | font-size: 0.9rem; 321 | } 322 | 323 | .fn-description.md h6 { 324 | font-size: 0.8rem; 325 | } 326 | 327 | .fn-description.md hr { 328 | border: dotted 0.05rem #777; 329 | } 330 | 331 | .md pre > code { 332 | font-family: monospace; 333 | font-size: 100%; 334 | background-color: rgb(245, 247, 249) !important; 335 | border: 0.1rem solid rgb(212, 218, 223); 336 | margin-bottom: 1.5rem; 337 | } 338 | 339 | .md pre { 340 | margin-bottom: 1.5rem; 341 | } 342 | 343 | .md p { 344 | margin-bottom: 1.5rem; 345 | line-height: 1.5; 346 | } 347 | 348 | .md em { 349 | font-style: italic; 350 | } 351 | 352 | .md strong { 353 | font-weight: 800; 354 | } 355 | 356 | .md ul, 357 | .md ol { 358 | margin-left: 2rem; 359 | margin-bottom: 1.5rem; 360 | } 361 | 362 | .md ul { 363 | list-style: disc outside; 364 | } 365 | 366 | .md ol { 367 | list-style: decimal outside; 368 | } 369 | 370 | .md li { 371 | margin-bottom: 0.5rem; 372 | padding-left: 0.5rem; 373 | } 374 | 375 | .md pre > code { 376 | display: block; 377 | line-height: 1.5; 378 | padding: 0.5rem; 379 | } 380 | 381 | .md blockquote { 382 | background-color: rgb(245, 247, 249) !important; 383 | border-left: 0.3rem solid rgb(212, 218, 223); 384 | padding: 0.5rem 0.6rem; 385 | margin-bottom: 1.5rem; 386 | } 387 | 388 | .md blockquote > p { 389 | margin-bottom: 0; 390 | } 391 | 392 | .md table td, 393 | .md table th { 394 | padding: 0.2rem 0.5rem; 395 | } 396 | 397 | .md table td:first-child, 398 | .md table th:first-child { 399 | padding-left: 0.3rem; 400 | } 401 | 402 | .md table td:last-child, 403 | .md table th:last-child { 404 | padding-right: 0.3rem; 405 | } 406 | 407 | .md table thead { 408 | font-weight: bold; 409 | border-top: solid 0.15rem black; 410 | border-bottom: solid 0.1rem black; 411 | } 412 | 413 | 414 | .md table thead tr { 415 | line-height: 1.5rem; 416 | } 417 | 418 | .md table tbody tr { 419 | line-height: 1.5rem; 420 | border-bottom: solid 0.1rem rgb(212, 218, 223); 421 | } 422 | 423 | .md table tbody tr:last-child { 424 | line-height: 1.5rem; 425 | border-bottom: solid 0.15rem black; 426 | } -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | Examples 2 | ======== 3 | 4 | 5 | Install `rhai-doc` 6 | ------------------ 7 | 8 | Before trying out the examples, the `rhai-doc` tool must be installed. 9 | 10 | ```sh 11 | cargo install --path . 12 | ``` 13 | 14 | 15 | Generate Documentation Site 16 | --------------------------- 17 | 18 | To generate documentation for any example set, do the following: 19 | 20 | ```sh 21 | cd examples/basic 22 | 23 | rhai-doc 24 | ``` 25 | 26 | The documentation site will be generated in the `dist` sub-directory (unless a different directory 27 | is provided via the `-D` option). 28 | -------------------------------------------------------------------------------- /examples/basic/assets/custom.css: -------------------------------------------------------------------------------- 1 | /* Custom stylesheet */ -------------------------------------------------------------------------------- /examples/basic/assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rhaiscript/rhai-doc/083ecd79b8d82fb9bde7d9eb5328c4a4e79e0277/examples/basic/assets/icon.png -------------------------------------------------------------------------------- /examples/basic/example.rhai: -------------------------------------------------------------------------------- 1 | // This is a Rhai script containing many functions. 2 | // 3 | // Functions within the same script file can cross-link to each other via 4 | // the [`func_name`] format. 5 | 6 | /** 7 | Another test. 8 | This is a block doc-comment. 9 | */ 10 | private fn thing() {} 11 | 12 | // This is not a doc-comment so this should not show up in the documentation. 13 | fn foo() {} 14 | 15 | /// # Thing 16 | /// Test 17 | /// Oh wow! *one* **two** _three_ __four__ 18 | /// This is the last line of the paragraph. 19 | /// 20 | /// Check out this function: [`baz`] 21 | /// 22 | /// --- 23 | /// ## These are lists... 24 | /// 25 | /// - list 26 | /// - of 27 | /// - things 28 | /// 29 | /// 1. List 30 | /// 2. Of 31 | /// 3. Things 32 | fn foo(bar, baz) {} 33 | 34 | /// > This is a quote for `baz` 35 | /// > that spans two lines. 36 | /// 37 | /// These functions are great: [`thing`] and [`foo`] 38 | /// 39 | /// # Example 40 | /// ``` 41 | /// // This is a function 42 | /// fn foo(x, y) { x + y } 43 | /// 44 | /// // Call it! 45 | /// foo(1, 2); 46 | /// 47 | /// let x = 42; 48 | /// let y = [1, 2, 3, x, x + 1]; 49 | /// x += y.len.abs(); 50 | /// print(`Result: ${x}`); 51 | /// ``` 52 | fn baz(abc) {} 53 | 54 | /// [This is a link](http://example.com) 55 | /// 56 | /// ![Logo](logo.png) 57 | fn foo(x) {} 58 | -------------------------------------------------------------------------------- /examples/basic/nested/deep/example.rhai: -------------------------------------------------------------------------------- 1 | /// This is quite a deep function 2 | fn deep_func () {} -------------------------------------------------------------------------------- /examples/basic/nested/empty.rhai: -------------------------------------------------------------------------------- 1 | // This Rhai script has no public functions. 2 | // 3 | // Therefore this script file will not show up in the generated documentation 4 | // unless the `-a` flag is used. 5 | 6 | export const SECRET = 42; 7 | 8 | /// This function is private. 9 | private fn get_secret() { 10 | SECRET 11 | } 12 | -------------------------------------------------------------------------------- /examples/basic/pages/another/deep/folder/chain/anything.md: -------------------------------------------------------------------------------- 1 | Whatever 2 | ======== 3 | 4 | Whatever is here... it is not important. 5 | 6 | Notice the link of this page appears before the link to _Some Junk_ because the page files are 7 | sorted alphabetically, and the name of this file is `anything.md`. 8 | 9 | The _title_ is not used for sorting. 10 | -------------------------------------------------------------------------------- /examples/basic/pages/home.md: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | This is the home page 5 | -------------------------------------------------------------------------------- /examples/basic/pages/junk.md: -------------------------------------------------------------------------------- 1 | Some Junk 2 | ========= 3 | 4 | This is a page containing junk. 5 | 6 | A code block: 7 | 8 | ```ts 9 | const QUESTION = "Life, Universe, Everything"; 10 | 11 | let answer = 42; 12 | 13 | print(` 14 | Question: ${QUESTION}? 15 | Answer = ${answer} 16 | `); 17 | ``` 18 | 19 | And maybe a table: 20 | 21 | | Header 1 | Header 2 | Header 3 | 22 | | -------- | :------: | -------: | 23 | | Hello | `true` | 123 | 24 | | Answer | Life | 42 | 25 | -------------------------------------------------------------------------------- /examples/basic/rhai.toml: -------------------------------------------------------------------------------- 1 | version = "1.0" 2 | name = "Rhai Doc" 3 | color = [246, 119, 2] 4 | #root = "" 5 | index = "home.md" 6 | icon = "assets/icon.png" 7 | stylesheet = "assets/custom.css" 8 | code_theme = "atom-one-light" 9 | #extension = ".x" 10 | #google_analytics = "G-ABCDEF1234" 11 | 12 | [[links]] 13 | name = "Blog" 14 | link = "#" 15 | 16 | [[links]] 17 | name = "Google" 18 | link = "https://www.google.com" 19 | -------------------------------------------------------------------------------- /src/cli.rs: -------------------------------------------------------------------------------- 1 | use clap::{ArgAction, Parser, Subcommand}; 2 | use std::path::PathBuf; 3 | 4 | pub const RHAI_TOML: &str = "rhai.toml"; 5 | 6 | /// Generate HTML documentation from Rhai script files. 7 | #[derive(Debug, Parser)] 8 | #[command(name = "rhai-doc", about, version, author)] 9 | pub struct Cli { 10 | /// Logging level (use multiple to set the level of verbosity) 11 | /// 12 | /// 1 = silent, 2 (default) = full, 3 = debug 13 | #[arg(long, short, action = ArgAction::Count)] 14 | pub verbose: u8, 15 | /// Use silent mode (overrides --verbose) 16 | #[arg(long, short)] 17 | pub quiet: bool, 18 | 19 | /// Generate documentation for all functions, including private ones 20 | #[arg(long, short)] 21 | pub all: bool, 22 | 23 | /// Set the configuration file 24 | #[arg(long, short, value_name = "FILE", default_value = RHAI_TOML)] 25 | pub config: PathBuf, 26 | /// Set the Rhai scripts (*.rhai) directory 27 | #[arg(long = "dir", short, value_name = "DIR", default_value = ".")] 28 | pub directory: PathBuf, 29 | /// Set the directory where MarkDown (*.md) pages files are located 30 | #[arg(long, short, value_name = "DIR", default_value = "pages")] 31 | pub pages: PathBuf, 32 | /// Set the destination for the documentation output 33 | #[arg(long = "dest", short = 'D', value_name = "DIR", default_value = "dist")] 34 | pub destination: PathBuf, 35 | 36 | /// Sub-commands 37 | #[command(subcommand)] 38 | pub command: Option, 39 | } 40 | 41 | /// Sub-commands 42 | #[derive(Subcommand, Debug)] 43 | pub enum RhaiDocCommand { 44 | /// Generates a new configuration file 45 | New { 46 | /// Sets the configuration file to generate 47 | #[arg(long, short, value_name = "FILE", default_value = RHAI_TOML)] 48 | config: String, 49 | }, 50 | } 51 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | use crate::data::*; 2 | use serde::{Deserialize, Serialize}; 3 | 4 | #[derive(Serialize, Deserialize, Debug)] 5 | pub struct Config { 6 | pub version: String, 7 | pub name: Option, 8 | pub color: Option, 9 | pub icon: Option, 10 | pub stylesheet: Option, 11 | pub code_theme: Option, 12 | pub code_lang: Option, 13 | pub root: Option, 14 | pub index: Option, 15 | pub extension: Option, 16 | #[serde(default)] 17 | pub links: Vec, 18 | pub google_analytics: Option, 19 | } 20 | 21 | #[derive(Serialize, Deserialize, Debug, Clone)] 22 | pub struct Rgb(pub u8, pub u8, pub u8); 23 | 24 | impl Rgb { 25 | pub fn to_alpha(&self, alpha: u8) -> Rgba { 26 | Rgba(self.0, self.1, self.2, alpha) 27 | } 28 | } 29 | 30 | impl ToString for Rgb { 31 | fn to_string(&self) -> String { 32 | format!("rgb({r}, {g}, {b})", r = self.0, g = self.1, b = self.2) 33 | } 34 | } 35 | 36 | pub struct Rgba(pub u8, pub u8, pub u8, pub u8); 37 | 38 | impl ToString for Rgba { 39 | fn to_string(&self) -> String { 40 | format!( 41 | "rgba({r}, {g}, {b}, {a})", 42 | r = self.0, 43 | g = self.1, 44 | b = self.2, 45 | a = (self.3 as f32 / u8::MAX as f32) 46 | ) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/data.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | #[derive(Deserialize, Serialize, Debug, Clone)] 4 | pub struct Page { 5 | pub title: String, 6 | pub name: String, 7 | pub root: String, 8 | pub icon: String, 9 | pub stylesheet: Option, 10 | pub code_theme: String, 11 | pub code_lang: String, 12 | pub functions: Option>, 13 | pub markdown: Option, 14 | pub external_links: Vec, 15 | pub page_links: Vec, 16 | pub script_links: Vec, 17 | pub google_analytics: Option, 18 | } 19 | 20 | #[derive(Deserialize, Serialize, Debug, Clone, Hash)] 21 | pub struct Function { 22 | pub id: String, 23 | pub definition: String, 24 | pub is_private: bool, 25 | pub markdown: String, 26 | } 27 | 28 | #[derive(Deserialize, Serialize, Debug, Clone, Hash)] 29 | pub struct Link { 30 | pub name: String, 31 | pub link: String, 32 | } 33 | -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | use std::convert::From; 2 | use std::fmt; 3 | 4 | #[derive(Debug)] 5 | pub enum RhaiDocError { 6 | Internal(String), 7 | Icon(String), 8 | } 9 | 10 | impl fmt::Display for RhaiDocError { 11 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 12 | match self { 13 | RhaiDocError::Internal(message) => write!(f, "{}", message), 14 | RhaiDocError::Icon(message) => write!(f, "Icon Error: {}", message), 15 | } 16 | } 17 | } 18 | 19 | macro_rules! impl_error { 20 | { $ERROR_TYPE:ty } => { 21 | impl From<$ERROR_TYPE> for RhaiDocError { 22 | fn from(error: $ERROR_TYPE) -> Self { 23 | RhaiDocError::Internal(format!("{}", error)) 24 | } 25 | } 26 | }; 27 | } 28 | 29 | impl_error!(handlebars::TemplateError); 30 | impl_error!(glob::PatternError); 31 | impl_error!(std::str::Utf8Error); 32 | impl_error!(std::boxed::Box); 33 | impl_error!(handlebars::RenderError); 34 | impl_error!(std::io::Error); 35 | impl_error!(toml::de::Error); 36 | impl_error!(std::path::StripPrefixError); 37 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use glob::glob; 2 | use handlebars::Handlebars; 3 | use pulldown_cmark::{html, CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag}; 4 | use rhai::{Engine, FnAccess, ScriptFnMetadata, AST}; 5 | use serde::{Deserialize, Serialize}; 6 | use std::cmp::Ordering; 7 | use std::collections::BTreeMap; 8 | use std::fs::File; 9 | use std::io::prelude::{Read, Write}; 10 | use std::path::{Path, PathBuf}; 11 | 12 | mod cli; 13 | mod config; 14 | mod data; 15 | mod error; 16 | 17 | macro_rules! write_log { 18 | ($debug:expr, $fmt:expr, $(@ $args:expr),*) => { 19 | if $debug { println!($fmt, $($args.to_string_lossy()),*); } 20 | }; 21 | ($debug:expr, $($args:expr),*) => { 22 | if $debug { println!($($args),*); } 23 | }; 24 | } 25 | 26 | #[derive(Deserialize, Serialize, Debug, Clone)] 27 | pub struct LinkInfo { 28 | pub path: PathBuf, 29 | pub active: bool, 30 | pub name: String, 31 | pub link: String, 32 | pub sub_links: Vec, 33 | #[serde(skip)] 34 | pub ast: Option, 35 | } 36 | 37 | fn write_styles(config: &config::Config, destination: &PathBuf) -> Result<(), error::RhaiDocError> { 38 | let mut handlebars = Handlebars::new(); 39 | let mut styles = destination.clone(); 40 | let mut data: BTreeMap<&str, String> = BTreeMap::new(); 41 | 42 | handlebars.register_escape_fn(handlebars::no_escape); 43 | handlebars.register_template_string( 44 | "styles", 45 | std::str::from_utf8(include_bytes!("../assets/styles.tpl.css"))?, 46 | )?; 47 | 48 | styles.push("rhai-doc-styles.css"); 49 | 50 | let color = config.color.clone(); 51 | let color = color.unwrap_or_else(|| config::Rgb(246, 119, 2)); 52 | data.insert("color", color.to_string()); 53 | data.insert("color_alpha", color.to_alpha(45).to_string()); 54 | 55 | let mut file = File::create(&styles)?; 56 | file.write_all(handlebars.render("styles", &data)?.as_bytes())?; 57 | 58 | Ok(()) 59 | } 60 | 61 | fn write_icon( 62 | config: &config::Config, 63 | source: &PathBuf, 64 | destination: &PathBuf, 65 | ) -> Result { 66 | let icon_default = include_bytes!("../assets/logo.svg"); 67 | let mut source = source.clone(); 68 | let mut destination = destination.clone(); 69 | 70 | if let Some(icon) = config.icon.clone() { 71 | source.push(&icon); 72 | 73 | let mut file = match File::open(&source) { 74 | Ok(f) => f, 75 | Err(error) => { 76 | eprintln!( 77 | "Cannot load icon `{file}`: {error}", 78 | file = source.to_string_lossy(), 79 | error = error 80 | ); 81 | return Err(error.into()); 82 | } 83 | }; 84 | 85 | let mut logo = Vec::new(); 86 | 87 | destination.push("logo"); 88 | 89 | return match PathBuf::from(&icon).extension() { 90 | Some(extension) => { 91 | destination.set_extension(extension); 92 | file.read_to_end(&mut logo)?; 93 | 94 | let mut new_file = File::create(destination)?; 95 | new_file.write_all(&logo)?; 96 | 97 | Ok(format!( 98 | "logo.{extension}", 99 | extension = extension.to_string_lossy() 100 | )) 101 | } 102 | None => Err(error::RhaiDocError::Icon( 103 | "Icon must have an extension".into(), 104 | )), 105 | }; 106 | } 107 | 108 | destination.push("logo.svg"); 109 | 110 | let mut new_file = File::create(destination)?; 111 | new_file.write_all(icon_default)?; 112 | 113 | Ok("logo.svg".into()) 114 | } 115 | 116 | fn comments_to_string(comments: &[&str]) -> String { 117 | comments 118 | .iter() 119 | .flat_map(|&s| { 120 | if s.starts_with("/**") { 121 | vec![s] 122 | } else { 123 | s.split('\n').collect::>() 124 | } 125 | }) 126 | .map(|s| { 127 | if s.starts_with("///") || s.starts_with("/**") { 128 | if s.ends_with("**/") { 129 | &s[3..s.len() - 3] 130 | } else if s.ends_with("*/") { 131 | &s[3..s.len() - 2] 132 | } else { 133 | &s[3..] 134 | } 135 | } else { 136 | s 137 | } 138 | }) 139 | .collect::>() 140 | .join("\n") 141 | } 142 | 143 | fn html_from_pathbuf(path: &Path, root: &Path) -> PathBuf { 144 | let mut new_path = path 145 | .strip_prefix(root) 146 | .map_or_else(|_| PathBuf::from(path), PathBuf::from); 147 | new_path.set_extension("html"); 148 | new_path 149 | } 150 | 151 | fn gen_hash_name(function: &ScriptFnMetadata) -> String { 152 | if function.params.is_empty() { 153 | function.name.to_string() 154 | } else { 155 | format!("{}-{}", function.name, function.params.len()) 156 | } 157 | } 158 | 159 | fn new_config_file( 160 | config: String, 161 | mut path: PathBuf, 162 | quiet: bool, 163 | ) -> Result<(), error::RhaiDocError> { 164 | path.push(config); 165 | let mut config_file = match std::fs::OpenOptions::new() 166 | .write(true) 167 | .create_new(true) 168 | .open(&path) 169 | { 170 | Ok(f) => f, 171 | Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => { 172 | eprintln!( 173 | "Configuration file `{file}` already exists", 174 | file = path.to_string_lossy(), 175 | ); 176 | return Err(error.into()); 177 | } 178 | Err(error) => { 179 | eprintln!( 180 | "Cannot create configuration file `{file}`: {error}", 181 | file = path.to_string_lossy(), 182 | error = error 183 | ); 184 | return Err(error.into()); 185 | } 186 | }; 187 | write_log!(!quiet, "Writing configuration file `{}`...", @path); 188 | let toml = std::str::from_utf8(include_bytes!("../assets/rhai.toml"))?; 189 | config_file.write_all(toml.as_bytes())?; 190 | write_log!(!quiet, "Configuration file generated."); 191 | return Ok(()); 192 | } 193 | 194 | fn main() -> Result<(), error::RhaiDocError> { 195 | let app = { 196 | use clap::Parser; 197 | cli::Cli::parse() 198 | }; 199 | 200 | let (quiet, debug) = if app.quiet { 201 | (true, false) 202 | } else { 203 | match app.verbose { 204 | 1 => (true, false), 205 | 3.. => (false, true), 206 | 0 | 2 => (false, false), 207 | } 208 | }; 209 | 210 | let config_file = app.config; 211 | let skip_private = !app.all; 212 | let source = app.directory; 213 | let dir_destination = app.destination; 214 | let dir_pages = app.pages; 215 | let command = app.command; 216 | 217 | write_log!( 218 | !quiet, 219 | "{} - Rhai documentation tool (version {})", 220 | "rhai-doc", //app.name, 221 | "1.0" //app.version 222 | ); 223 | 224 | write_log!(!quiet, "Source directory: `{}`", @source); 225 | 226 | match command { 227 | Some(cli::RhaiDocCommand::New { config }) => return new_config_file(config, source, quiet), 228 | None => (), 229 | } 230 | 231 | let mut path_toml = source.clone(); 232 | path_toml.push(config_file); 233 | 234 | write_log!(!quiet, "Config file: `{}`", @path_toml); 235 | 236 | let mut config_file = match File::open(&path_toml) { 237 | Ok(f) => f, 238 | Err(error) => { 239 | eprintln!( 240 | "Cannot load `{file}`: {error}", 241 | file = path_toml.to_string_lossy(), 242 | error = error 243 | ); 244 | return Err(error.into()); 245 | } 246 | }; 247 | let mut config_file_output = String::new(); 248 | config_file.read_to_string(&mut config_file_output)?; 249 | let config: config::Config = toml::from_str(&config_file_output)?; 250 | 251 | write_log!(debug, "{:#?}", config); 252 | 253 | let mut path_glob_source = source.clone(); 254 | path_glob_source.push("**"); 255 | path_glob_source.push("*.rhai"); 256 | 257 | if let Some(extension) = &config.extension { 258 | path_glob_source.set_extension(if extension.starts_with('.') { 259 | &extension[1..] 260 | } else { 261 | extension 262 | }); 263 | } 264 | 265 | write_log!(!quiet, "Script files pattern: `{}`", @path_glob_source); 266 | 267 | let mut path_pages = source.clone(); 268 | path_pages.push(dir_pages); 269 | 270 | let index_file = config.index.as_ref().map(|index| { 271 | let mut file = path_pages.clone(); 272 | file.push(index); 273 | file 274 | }); 275 | 276 | path_pages.push("**"); 277 | path_pages.push("*.md"); 278 | 279 | write_log!(!quiet, "MarkDown pages: `{}`", @path_pages); 280 | 281 | let mut destination = source.clone(); 282 | destination.push(dir_destination); 283 | std::fs::create_dir_all(&destination)?; 284 | 285 | write_log!(!quiet, "Destination directory: `{}`", @destination); 286 | 287 | let mut page_links = Vec::new(); 288 | let mut script_links = Vec::new(); 289 | let mut handlebars = Handlebars::new(); 290 | 291 | let options = Options::all(); 292 | let engine = Engine::default(); 293 | 294 | let mut pages: Vec<(String, PathBuf, String)> = Vec::new(); 295 | 296 | handlebars.register_escape_fn(handlebars::no_escape); 297 | handlebars.register_template_string( 298 | "page", 299 | std::str::from_utf8(include_bytes!("../assets/page.html.hbs"))?, 300 | )?; 301 | handlebars.register_partial( 302 | "fn-block", 303 | std::str::from_utf8(include_bytes!("../assets/fn-block.html.hbs"))?, 304 | )?; 305 | 306 | write_log!(!quiet, "Registered handlebars templates."); 307 | 308 | // 309 | // WRITE FILES 310 | // 311 | write_styles(&config, &destination)?; 312 | let icon = write_icon(&config, &source, &destination)?; 313 | 314 | let stylesheet_filename = if let Some(stylesheet) = config.stylesheet { 315 | let mut css = source.clone(); 316 | css.push(stylesheet); 317 | 318 | if css.is_file() { 319 | write_log!(!quiet, "Custom stylesheet: `{}`", @css); 320 | 321 | let mut ss_source = source.clone(); 322 | ss_source.push(&css); 323 | let mut ss_dest = destination.clone(); 324 | let filename = css.file_name().unwrap().to_string_lossy().into_owned(); 325 | ss_dest.push(&filename); 326 | 327 | let mut file = match File::open(&ss_source) { 328 | Ok(f) => f, 329 | Err(error) => { 330 | eprintln!( 331 | "Cannot load icon `{file}`: {error}", 332 | file = ss_source.to_string_lossy(), 333 | error = error 334 | ); 335 | return Err(error.into()); 336 | } 337 | }; 338 | let mut content = Vec::::new(); 339 | file.read_to_end(&mut content)?; 340 | let mut file = File::create(&ss_dest)?; 341 | file.write_all(&content)?; 342 | Some(filename) 343 | } else { 344 | None 345 | } 346 | } else { 347 | None 348 | }; 349 | 350 | write_log!(!quiet, "Written styles and icon."); 351 | 352 | // 353 | // PAGE LINKS 354 | // 355 | write_log!(!quiet, "Scanning for MarkDown pages from `{}`...", @path_pages); 356 | 357 | let mut files_list = glob(&path_pages.to_string_lossy())? 358 | .into_iter() 359 | .filter(|p| p.is_ok()) 360 | .map(|p| p.unwrap()) 361 | .collect::>(); 362 | files_list.sort(); 363 | 364 | // Move the home page to the front 365 | let mut has_index = false; 366 | 367 | if let Some(ref index_file) = index_file { 368 | if let Some(n) = 369 | files_list.iter().enumerate().find_map( 370 | |(i, p)| { 371 | if p == index_file { 372 | Some(i) 373 | } else { 374 | None 375 | } 376 | }, 377 | ) 378 | { 379 | let file = files_list.remove(n); 380 | files_list.insert(0, file); 381 | has_index = true; 382 | } 383 | } 384 | 385 | for src_path in files_list { 386 | write_log!(!quiet, "> Generating HTML from MarkDown page `{}`...", @src_path); 387 | 388 | let mut markdown_string = String::new(); 389 | let mut dest_path = destination.clone(); 390 | let mut file_path = html_from_pathbuf(&src_path, &source); 391 | let mut markdown = File::open(&src_path)?; 392 | markdown.read_to_string(&mut markdown_string)?; 393 | 394 | dest_path.push(&file_path); 395 | let mut html_output = String::new(); 396 | let mut parser_header = Parser::new_ext(&markdown_string, options); 397 | let parser_html = Parser::new_ext(&markdown_string, options); 398 | html::push_html(&mut html_output, parser_html); 399 | 400 | // Don't create the page unless it has a heading 401 | let h1 = Tag::Heading(HeadingLevel::H1, None, Default::default()); 402 | 403 | if parser_header.next() == Some(Event::Start(h1)) { 404 | if let Some(Event::Text(text)) = parser_header.next() { 405 | let name: String = text.to_owned().to_string(); 406 | 407 | if let Some(ref index_file) = index_file { 408 | if &src_path == index_file { 409 | file_path = PathBuf::from("index.html"); 410 | dest_path = destination.clone(); 411 | dest_path.push(&file_path); 412 | } 413 | } 414 | 415 | let link = file_path 416 | .components() 417 | .map(|s| s.as_os_str().to_string_lossy()) 418 | .collect::>() 419 | .join("/") 420 | .to_string(); 421 | 422 | page_links.push(LinkInfo { 423 | path: src_path, 424 | active: false, 425 | name: name.clone(), 426 | link, 427 | sub_links: Default::default(), 428 | ast: None, 429 | }); 430 | pages.push((name, dest_path, html_output)); 431 | } 432 | } 433 | } 434 | 435 | // 436 | // SCRIPT LINKS 437 | // 438 | write_log!(!quiet, "Scanning for Rhai scripts from `{}`...", @path_glob_source); 439 | 440 | for entry in glob(&path_glob_source.to_string_lossy())? { 441 | match entry { 442 | Ok(path) if path.is_file() => { 443 | write_log!(!quiet, "> Found Rhai script `{}`", @path); 444 | 445 | let mut name = path.clone(); 446 | name.set_extension(""); 447 | 448 | let name = match name.strip_prefix(&source) { 449 | Ok(name) => name, 450 | Err(_) => &name, 451 | } 452 | .components() 453 | .map(|c| c.as_os_str().to_string_lossy()) 454 | .collect::>() 455 | .join("/"); 456 | 457 | let ast = engine.compile_file(path.clone())?; 458 | 459 | if ast 460 | .iter_functions() 461 | .filter(|f| !skip_private || f.access != FnAccess::Private) 462 | .count() 463 | == 0 464 | { 465 | write_log!(!quiet, " ... which contains no functions. Skipped."); 466 | continue; 467 | } 468 | 469 | let doc_path = html_from_pathbuf(&path, &source); 470 | 471 | let link = doc_path 472 | .components() 473 | .map(|s| s.as_os_str().to_string_lossy()) 474 | .collect::>() 475 | .join("/") 476 | .to_string(); 477 | 478 | write_log!(!quiet, " -> {}", link); 479 | 480 | script_links.push(LinkInfo { 481 | path: path.clone(), 482 | name, 483 | active: false, 484 | link, 485 | sub_links: Default::default(), 486 | ast: Some(ast), 487 | }) 488 | } 489 | Ok(_) => {} 490 | Err(error) => eprintln!( 491 | "Error loading script files `{pattern}`: {error}", 492 | pattern = path_glob_source.to_string_lossy(), 493 | error = error 494 | ), 495 | } 496 | } 497 | 498 | // 499 | // PAGES 500 | // 501 | write_log!(!quiet, "Writing HTML pages..."); 502 | 503 | for (i, (name, dest_path, markdown)) in pages.into_iter().enumerate() { 504 | write_log!(!quiet, " -> HTML page `{}`...", @dest_path); 505 | 506 | let mut links_clone = page_links.clone(); 507 | links_clone[i].active = true; 508 | 509 | let root = if let Some(ref r) = config.root { 510 | r.clone() 511 | } else { 512 | match dest_path.strip_prefix(&destination)?.ancestors().count() { 513 | 0..=1 => String::new(), 514 | levels => std::iter::repeat("../") 515 | .take(levels - 2) 516 | .collect::>() 517 | .join(""), 518 | } 519 | }; 520 | 521 | let page = data::Page { 522 | title: config.name.clone().unwrap_or_default(), 523 | name, 524 | root, 525 | icon: icon.clone(), 526 | stylesheet: stylesheet_filename.clone(), 527 | code_theme: config.code_theme.clone().unwrap_or("default".to_string()), 528 | code_lang: config.code_lang.clone().unwrap_or("ts".to_string()), 529 | functions: None, 530 | markdown: Some(markdown), 531 | external_links: config.links.clone(), 532 | page_links: links_clone, 533 | script_links: script_links.clone(), 534 | google_analytics: config.google_analytics.clone(), 535 | }; 536 | if let Some(dir) = dest_path.parent() { 537 | std::fs::create_dir_all(dir)?; 538 | } 539 | let mut file = File::create(&dest_path)?; 540 | 541 | file.write_all(handlebars.render("page", &page)?.as_bytes())?; 542 | } 543 | 544 | if !has_index { 545 | let mut dest_path = destination.clone(); 546 | dest_path.push("index.html"); 547 | 548 | write_log!(!quiet, " -> index page `{}`...", @dest_path); 549 | 550 | let page = data::Page { 551 | title: config.name.clone().unwrap_or_default(), 552 | name: "index.html".to_string(), 553 | root: config.root.clone().unwrap_or_default(), 554 | icon: icon.clone(), 555 | stylesheet: stylesheet_filename.clone(), 556 | code_theme: config.code_theme.clone().unwrap_or("default".to_string()), 557 | code_lang: config.code_lang.clone().unwrap_or("ts".to_string()), 558 | functions: None, 559 | markdown: None, 560 | external_links: config.links.clone(), 561 | page_links: page_links.clone(), 562 | script_links: script_links.clone(), 563 | google_analytics: config.google_analytics.clone(), 564 | }; 565 | if let Some(dir) = dest_path.parent() { 566 | std::fs::create_dir_all(dir)?; 567 | } 568 | let mut file = File::create(&dest_path)?; 569 | 570 | file.write_all(handlebars.render("page", &page)?.as_bytes())?; 571 | } 572 | 573 | // 574 | // SCRIPTS 575 | // 576 | write_log!(!quiet, "Writing Rhai scripts..."); 577 | 578 | for i in 0..script_links.len() { 579 | let LinkInfo { path, ast, .. } = &script_links[i]; 580 | 581 | let mut new_path = destination.clone(); 582 | let file_name = html_from_pathbuf(&path, &source); 583 | new_path.push(&file_name); 584 | 585 | write_log!(!quiet, "> `{}` -> `{}`...", @path, @new_path); 586 | 587 | let mut functions = ast 588 | .as_ref() 589 | .unwrap() 590 | .iter_functions() 591 | .filter(|f| !skip_private || f.access != FnAccess::Private) 592 | .collect::>(); 593 | 594 | functions.sort_by(|a, b| match a.name.partial_cmp(b.name).unwrap() { 595 | Ordering::Equal => a.params.len().partial_cmp(&b.params.len()).unwrap(), 596 | cmp => cmp, 597 | }); 598 | 599 | let mut links_clone = script_links.clone(); 600 | links_clone[i].active = true; 601 | links_clone[i].sub_links = functions 602 | .iter() 603 | .map(|f| data::Link { 604 | name: f.to_string(), 605 | link: gen_hash_name(f), 606 | }) 607 | .collect(); 608 | 609 | let root = if let Some(ref r) = config.root { 610 | r.clone() 611 | } else { 612 | match new_path.strip_prefix(&destination)?.ancestors().count() { 613 | 0..=1 => String::new(), 614 | levels => std::iter::repeat("../") 615 | .take(levels - 2) 616 | .collect::>() 617 | .join(""), 618 | } 619 | }; 620 | 621 | let mut page = data::Page { 622 | title: config.name.clone().unwrap_or_default(), 623 | name: file_name.to_string_lossy().to_string(), 624 | root, 625 | icon: icon.clone(), 626 | stylesheet: stylesheet_filename.clone(), 627 | code_theme: config.code_theme.clone().unwrap_or("default".to_string()), 628 | code_lang: config.code_lang.clone().unwrap_or("ts".to_string()), 629 | functions: Some(Vec::new()), 630 | markdown: None, 631 | external_links: config.links.clone(), 632 | page_links: page_links.clone(), 633 | script_links: links_clone, 634 | google_analytics: config.google_analytics.clone(), 635 | }; 636 | 637 | let mut last_link = ""; 638 | let fn_links = functions 639 | .iter() 640 | .filter(|f| { 641 | if f.name != last_link { 642 | last_link = f.name; 643 | true 644 | } else { 645 | false 646 | } 647 | }) 648 | .map(|f| format!("[`{}`]: #{}\n", f.name, gen_hash_name(f))) 649 | .collect::>() 650 | .join(""); 651 | let fn_links = fn_links.trim(); 652 | 653 | let functions = functions 654 | .into_iter() 655 | .map(|function| { 656 | if function.access == FnAccess::Private { 657 | write_log!( 658 | debug, 659 | " -> {}...", 660 | function.to_string().replace("private ", "private fn ") 661 | ); 662 | } else { 663 | write_log!(debug, " -> fn {}...", function); 664 | } 665 | 666 | let mut html_output = String::new(); 667 | let mut markdown = comments_to_string(&function.comments); 668 | if !fn_links.is_empty() { 669 | markdown.push_str("\n\n"); 670 | markdown.push_str(&fn_links); 671 | } 672 | let parser = Parser::new_ext(&markdown, options); 673 | 674 | html::push_html( 675 | &mut html_output, 676 | parser.into_iter().map(|event| match event { 677 | Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(lang))) 678 | if lang.is_empty() => 679 | { 680 | Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced("ts".into()))) 681 | } 682 | _ => event, 683 | }), 684 | ); 685 | 686 | data::Function { 687 | id: gen_hash_name(&function), 688 | definition: if function.access == FnAccess::Private { 689 | function.to_string().replace("private", "private fn") 690 | } else { 691 | format!("fn {}", function) 692 | }, 693 | is_private: function.access == FnAccess::Private, 694 | markdown: html_output, 695 | } 696 | }) 697 | .collect(); 698 | 699 | page.functions = Some(functions); 700 | 701 | if let Some(dir) = new_path.parent() { 702 | std::fs::create_dir_all(dir)?; 703 | } 704 | let mut file = File::create(&new_path)?; 705 | 706 | file.write_all(handlebars.render("page", &page)?.as_bytes())?; 707 | } 708 | 709 | write_log!( 710 | !quiet, 711 | "Done - documentation generated under `{}`", 712 | @destination 713 | ); 714 | 715 | Ok(()) 716 | } 717 | --------------------------------------------------------------------------------