MCPcopy Create free account
hub / github.com/PRQL/prql / generate_html_docs

Function generate_html_docs

prqlc/prqlc/src/cli/docs_generator.rs:4–172  ·  view source on GitHub ↗

Generate HTML documentation.

(stmts: Vec<Stmt>)

Source from the content-addressed store, hash-verified

2
3/// Generate HTML documentation.
4pub fn generate_html_docs(stmts: Vec<Stmt>) -> String {
5 let html = format!(
6 r#"<!doctype html>
7<html lang="en">
8 <head>
9 <meta charset="utf-8">
10 <meta name="viewport" content="width=device-width, initial-scale=1">
11 <meta name="keywords" content="prql">
12 <meta name="generator" content="prqlc {}">
13 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
14 <title>PRQL Docs</title>
15 </head>
16 <body>
17 <header class="bg-body-tertiary">
18 <div class="container">
19 <h1>Documentation</h1>
20 </div>
21 </header>
22 <main class="container">
23 {{{{ content }}}}
24 </main>
25 <footer class="container border-top">
26 <small class="text-body-secondary">Generated with <a href="https://prql-lang.org/" rel="external" target="_blank">prqlc</a> {}.</small>
27 </footer>
28 </body>
29</html>
30"#,
31 prqlc::compiler_version(),
32 prqlc::compiler_version()
33 );
34
35 let mut docs = String::new();
36
37 docs.push_str("<h2>Functions</h2>\n");
38 docs.push_str("<ul>\n");
39 for stmt in stmts
40 .clone()
41 .into_iter()
42 .filter(|stmt| matches!(stmt.kind, StmtKind::VarDef(_)))
43 {
44 let var_def = stmt.kind.as_var_def().unwrap();
45 docs.push_str(&format!(
46 " <li><a href=\"#fn-{}\">{}</a></li>\n",
47 var_def.name, var_def.name
48 ));
49 }
50 docs.push_str("</ul>\n\n");
51 if stmts
52 .clone()
53 .into_iter()
54 .filter(|stmt| matches!(stmt.kind, StmtKind::VarDef(_)))
55 .count()
56 == 0
57 {
58 docs.push_str("<p>None.</p>\n\n");
59 }
60
61 if stmts

Callers 1

executeMethod · 0.85

Calls 2

into_iterMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected