Skip to content

Commit fcd69bc

Browse files
authored
Merge pull request #11 from skytable/docs/newbuilder
Implement new actiondoc builder
2 parents 3421b40 + dd021c0 commit fcd69bc

File tree

6 files changed

+302
-155
lines changed

6 files changed

+302
-155
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Fork, make changes and submit a PR!
66

77
### Making changes to the `docs/Actions` folder
88
The `Actions` folder contains the documentation for the actions that Skytable supports. However, by no means should you modify them _here_.
9-
You should instead update [this file](https://github.com/skytable/skytable/blob/next/actions.jsonc). The documentation for the actions or the _actiondoc_ as we call it is built automatically from this file by using the `docbuilder` (our custom tool for generating documentation).
9+
You should instead update [this file](https://github.com/skytable/skytable/blob/next/actiondoc.yml). The documentation for the actions or the _actiondoc_ as we call it is built automatically from this file by using the `docbuilder` (our custom tool for generating documentation).
1010

1111
## License
1212
The documentation is licensed under the [CC-BY-SA-4.0](./LICENSE-CC) license while the `docbuilder` is licensed under the [GPL-3.0](./LICENSE-GPL3) license.

docbuilder/Cargo.lock

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

docbuilder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
serde-hjson = {version= "0.9.1", default-features = false}
10+
serde_yaml = "0.8.17"

docbuilder/out.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
id: get
3+
title: GET
4+
---
5+
6+
:::note About
7+
**Time complexity**: O(1)
8+
**Accept type**:
9+
10+
- [AnyArray](protocol/data-types#any-array)
11+
12+
**Return type**:
13+
14+
- [Rcode 1](protocol/response-codes)
15+
- [String](skyhash#strings-)
16+
- [Binstr](skyhash#strings-)
17+
18+
**Syntax**:
19+
20+
- GET <key>
21+
22+
:::
23+
24+
Get the value of a key

docbuilder/src/document.rs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
use core::cmp::Ordering;
2+
use std::collections::HashMap;
3+
4+
#[derive(Debug)]
5+
pub struct Document {
6+
/// Name of the action
7+
action_name: String,
8+
/// The time complexity of the action
9+
complexity: String,
10+
/// The syntax for the action
11+
syntax: Vec<String>,
12+
/// Return(s) with example(s)
13+
accept_ty: Vec<String>,
14+
/// the return type for the action
15+
return_ty: Vec<String>,
16+
/// longform description action
17+
description: String,
18+
}
19+
20+
impl Document {
21+
pub const fn new(
22+
action_name: String,
23+
complexity: String,
24+
accept_ty: Vec<String>,
25+
return_ty: Vec<String>,
26+
description: String,
27+
syntax: Vec<String>,
28+
) -> Self {
29+
Self {
30+
action_name,
31+
complexity,
32+
syntax,
33+
accept_ty,
34+
return_ty,
35+
description,
36+
}
37+
}
38+
/// Returns (path, contents of markdown file)
39+
pub fn into_md(self, linklist: &HashMap<&'static str, &'static str>) -> (String, String) {
40+
let Self {
41+
action_name,
42+
complexity,
43+
syntax,
44+
accept_ty,
45+
return_ty,
46+
description,
47+
} = self;
48+
let path = format!("docs/actions/{}.md", action_name);
49+
let syntax_rendered = render_list(syntax);
50+
let returns_rendered = render_link_list(return_ty, linklist);
51+
let accept_rendered = render_link_list(accept_ty, linklist);
52+
let body = format!(
53+
"\
54+
---
55+
id: {action_name}
56+
title: {title}
57+
---
58+
59+
:::note About
60+
**Time complexity**: {complexity}
61+
**Accept type**:
62+
63+
{accept_ty}
64+
**Return type**:
65+
66+
{return_ty}
67+
**Syntax**:
68+
69+
{syntax}
70+
:::
71+
72+
{description}
73+
",
74+
action_name = action_name.to_lowercase(),
75+
title = action_name,
76+
complexity = complexity,
77+
accept_ty = accept_rendered,
78+
return_ty = returns_rendered,
79+
syntax = syntax_rendered,
80+
description = description
81+
)
82+
.to_string();
83+
(path, body)
84+
}
85+
}
86+
87+
fn render_list(inp: Vec<String>) -> String {
88+
inp.into_iter()
89+
.map(|v| format!("- {}\n", v).chars().collect::<Vec<_>>())
90+
.flatten()
91+
.collect()
92+
}
93+
94+
fn render_link_list(inp: Vec<String>, linklist: &HashMap<&'static str, &'static str>) -> String {
95+
inp.into_iter()
96+
.map(|v| {
97+
println!("looking for: {}", v);
98+
format!("- [{}]({})\n", v, linklist.get(v.as_str()).unwrap())
99+
.chars()
100+
.collect::<Vec<_>>()
101+
})
102+
.flatten()
103+
.collect()
104+
}
105+
106+
impl PartialEq for Document {
107+
fn eq(&self, other: &Self) -> bool {
108+
self.action_name == other.action_name
109+
}
110+
}
111+
112+
impl Eq for Document {}
113+
114+
impl PartialOrd for Document {
115+
fn partial_cmp(&self, other: &Document) -> std::option::Option<std::cmp::Ordering> {
116+
self.action_name.partial_cmp(&other.action_name)
117+
}
118+
}
119+
120+
impl Ord for Document {
121+
fn cmp(&self, other: &Self) -> Ordering {
122+
self.action_name.cmp(&other.action_name)
123+
}
124+
}

0 commit comments

Comments
 (0)