Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Fork, make changes and submit a PR!

### Making changes to the `docs/Actions` folder
The `Actions` folder contains the documentation for the actions that Skytable supports. However, by no means should you modify them _here_.
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).
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).

## License
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.
83 changes: 22 additions & 61 deletions docbuilder/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde-hjson = {version= "0.9.1", default-features = false}
serde_yaml = "0.8.17"
24 changes: 24 additions & 0 deletions docbuilder/out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
id: get
title: GET
---

:::note About
**Time complexity**: O(1)
**Accept type**:

- [AnyArray](protocol/data-types#any-array)

**Return type**:

- [Rcode 1](protocol/response-codes)
- [String](skyhash#strings-)
- [Binstr](skyhash#strings-)

**Syntax**:

- GET <key>

:::

Get the value of a key
124 changes: 124 additions & 0 deletions docbuilder/src/document.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
use core::cmp::Ordering;
use std::collections::HashMap;

#[derive(Debug)]
pub struct Document {
/// Name of the action
action_name: String,
/// The time complexity of the action
complexity: String,
/// The syntax for the action
syntax: Vec<String>,
/// Return(s) with example(s)
accept_ty: Vec<String>,
/// the return type for the action
return_ty: Vec<String>,
/// longform description action
description: String,
}

impl Document {
pub const fn new(
action_name: String,
complexity: String,
accept_ty: Vec<String>,
return_ty: Vec<String>,
description: String,
syntax: Vec<String>,
) -> Self {
Self {
action_name,
complexity,
syntax,
accept_ty,
return_ty,
description,
}
}
/// Returns (path, contents of markdown file)
pub fn into_md(self, linklist: &HashMap<&'static str, &'static str>) -> (String, String) {
let Self {
action_name,
complexity,
syntax,
accept_ty,
return_ty,
description,
} = self;
let path = format!("docs/actions/{}.md", action_name);
let syntax_rendered = render_list(syntax);
let returns_rendered = render_link_list(return_ty, linklist);
let accept_rendered = render_link_list(accept_ty, linklist);
let body = format!(
"\
---
id: {action_name}
title: {title}
---

:::note About
**Time complexity**: {complexity}
**Accept type**:

{accept_ty}
**Return type**:

{return_ty}
**Syntax**:

{syntax}
:::

{description}
",
action_name = action_name.to_lowercase(),
title = action_name,
complexity = complexity,
accept_ty = accept_rendered,
return_ty = returns_rendered,
syntax = syntax_rendered,
description = description
)
.to_string();
(path, body)
}
}

fn render_list(inp: Vec<String>) -> String {
inp.into_iter()
.map(|v| format!("- {}\n", v).chars().collect::<Vec<_>>())
.flatten()
.collect()
}

fn render_link_list(inp: Vec<String>, linklist: &HashMap<&'static str, &'static str>) -> String {
inp.into_iter()
.map(|v| {
println!("looking for: {}", v);
format!("- [{}]({})\n", v, linklist.get(v.as_str()).unwrap())
.chars()
.collect::<Vec<_>>()
})
.flatten()
.collect()
}

impl PartialEq for Document {
fn eq(&self, other: &Self) -> bool {
self.action_name == other.action_name
}
}

impl Eq for Document {}

impl PartialOrd for Document {
fn partial_cmp(&self, other: &Document) -> std::option::Option<std::cmp::Ordering> {
self.action_name.partial_cmp(&other.action_name)
}
}

impl Ord for Document {
fn cmp(&self, other: &Self) -> Ordering {
self.action_name.cmp(&other.action_name)
}
}
Loading