Skip to content

Commit 67590bb

Browse files
finished docs generator. added rust to action.
1 parent 8b1a8b9 commit 67590bb

File tree

15 files changed

+543
-116
lines changed

15 files changed

+543
-116
lines changed

.github/workflows/build-docs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ jobs:
3333
with:
3434
fetch-depth: 0
3535

36+
- name: Setup Rust
37+
run: rustup override set 1.28.1
38+
- name: Output rust version for educational purposes
39+
run: rustup --version
40+
3641
- name: Setup Bun
3742
uses: oven-sh/setup-bun@v1
3843
with:

docs/generation/Cargo.lock

Lines changed: 0 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/generation/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ edition = "2024"
77
full_moon = { version = "2.0.0", features = [ "luau" ] }
88
logos = "0.15.0"
99
guarded = "0.0.2"
10-
unindent = "0.2.4"
11-
convert_case = "0.8.0"
12-
phf = "0.11.3"
13-
phf_macros = "0.11.3"
10+
unindent = "0.2.4"

docs/generation/src/main.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
use std::{fs, path::Path};
1+
use std::{collections::HashMap, fs, path::Path};
22

33
use full_moon::{ast::{luau::ExportedTypeFunction, Stmt}, node::Node, parse, tokenizer::{TokenKind, TokenType}};
44
use guarded::guarded_unwrap;
55

6-
use convert_case::{Case, Casing};
7-
86
mod lex_doc_comment;
97
use lex_doc_comment::DocCommentLexer;
108

119
mod parse_doc_comment;
1210
use parse_doc_comment::parse_doc_comment;
11+
use unindent::Unindent;
1312

1413
const INIT_CONTENT: &str = include_str!("../../../src/init.luau");
1514

1615
const OUTPUT_PATH_STR: &str = "../../docs/site/docs";
1716

18-
fn parse_exported_type_func(output_path: &Path, type_func: &ExportedTypeFunction) {
17+
fn parse_exported_type_func(
18+
files: &mut HashMap<String, String>,
19+
type_func: &ExportedTypeFunction
20+
) {
1921
let first_token = type_func.export_token();
2022

2123
let doc_comment = guarded_unwrap!(
@@ -37,13 +39,14 @@ fn parse_exported_type_func(output_path: &Path, type_func: &ExportedTypeFunction
3739
let mut lexer = DocCommentLexer::new(&doc_comment_string);
3840
let (parsed, category) = parse_doc_comment(&mut lexer, &type_func_name, type_func.range().unwrap());
3941

40-
let output_path_for_category = output_path.join(category);
41-
let _ = fs::create_dir_all(&output_path_for_category);
42-
43-
let _ = fs::write(output_path_for_category.join(format!("{}.md", type_func_name.to_case(Case::Snake))), parsed);
42+
files.entry(category)
43+
.and_modify(|f| f.push_str(&format!("\n\n- - -\n\n{}", parsed)))
44+
.or_insert(parsed);
4445
}
4546

4647
fn main() {
48+
let mut files: HashMap<String, String> = HashMap::new();
49+
4750
let output_path = Path::new(OUTPUT_PATH_STR);
4851

4952
if output_path.is_dir() {
@@ -56,8 +59,28 @@ fn main() {
5659

5760
for statement in ast.nodes().stmts() {
5861
match statement {
59-
Stmt::ExportedTypeFunction(type_func) => parse_exported_type_func(output_path, type_func),
62+
Stmt::ExportedTypeFunction(type_func) => {
63+
parse_exported_type_func(&mut files, type_func)
64+
}
6065
_ => continue
6166
};
6267
}
68+
69+
for (category, file_content) in files {
70+
let _ = fs::write(output_path.join(format!("{}.md", category)), file_content);
71+
}
72+
73+
let _ = fs::write(output_path.join("index.md"),
74+
"---
75+
title: Redirecting...
76+
---
77+
78+
<script setup>
79+
if (typeof window !== 'undefined') {
80+
window.location.replace('/docs/core/')
81+
}
82+
</script>
83+
84+
<p>Redirecting you to the core docs...</p>".unindent()
85+
);
6386
}

docs/generation/src/parse_doc_comment.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::lex_doc_comment::{DocCommentLexer, DocCommentTagToken};
66

77
const GITHUB_URL_PREFIX: &str = "https://github.com/typeforge-luau/typeforge/blob/main/src/init.luau";
88

9+
const GITHUB_IMAGE: &str = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1024\" height=\"1024\" viewBox=\"0 0 1024 1024\"><path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z\" transform=\"scale(64)\"/></svg>";
10+
911
fn github_url_for_range(range: (Position, Position)) -> String {
1012
format!("{}#L{}-L{}", GITHUB_URL_PREFIX, range.0.line(), range.1.line())
1113
}
@@ -26,7 +28,7 @@ pub fn parse_doc_comment(
2628
let item_tag_token = item.tag_token;
2729
match item_tag_token {
2830
None => if let Some(body) = item.body.take() {
29-
description = body.unindent() + &format!(" [View On Github]({})", github_url_for_range(type_func_range))
31+
description = body.unindent()
3032
} else {
3133
description = String::new()
3234
},
@@ -39,8 +41,13 @@ pub fn parse_doc_comment(
3941
DocCommentTagToken::ParamTag => {
4042
let (param_name, body) = body.split_once(" ").unwrap();
4143
let (param_type, param_description) = body.split_once("--").unwrap();
42-
43-
params += &format!("| {} | {} | {} |\n", param_name, param_type.trim(), param_description.trim());
44+
45+
params += &format!(
46+
"| {} | {} | {} |\n",
47+
param_name,
48+
&format!("`{}`{{luau-type}}",param_type.trim()),
49+
param_description.trim()
50+
);
4451
},
4552

4653
DocCommentTagToken::ExampleTag => {
@@ -67,7 +74,12 @@ pub fn parse_doc_comment(
6774
let (param_name, body) = body.split_once(" ").unwrap();
6875
let (param_type, param_description) = body.split_once("--").unwrap();
6976

70-
params += &format!("| {} | {} | {} |\n", param_name, param_type.trim(), param_description.trim());
77+
params += &format!(
78+
"| {} | {} | {} |\n",
79+
param_name,
80+
&format!("`{}`{{luau-type}}",param_type.trim()),
81+
param_description.trim()
82+
);
7183
},
7284

7385
DocCommentTagToken::ExampleTag => {
@@ -99,5 +111,14 @@ pub fn parse_doc_comment(
99111
parsed += &format!("\n\n## Examples\n{}", examples.trim_end())
100112
}
101113

102-
(format!("# {}\n{}", type_func_name, parsed), category.to_lowercase())
114+
(format!(
115+
"# {}{}\n{}",
116+
type_func_name,
117+
&format!(
118+
"<a href=\"{}\" target=\"_blank\" rel=\"noreferrer noopener\"><Badge type=\"info\">{}</Badge></a>",
119+
github_url_for_range(type_func_range),
120+
GITHUB_IMAGE
121+
),
122+
parsed
123+
), category.to_lowercase())
103124
}

0 commit comments

Comments
 (0)