Move consts to dir in docs (#5753)
* updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * add consts to dir Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * add consts to dir Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
2
.github/workflows/generate-website-docs.yml
vendored
2
.github/workflows/generate-website-docs.yml
vendored
@ -41,10 +41,12 @@ jobs:
|
|||||||
rm -rf documentation/content/pages/docs/kcl/*.md
|
rm -rf documentation/content/pages/docs/kcl/*.md
|
||||||
rm -rf documentation/content/pages/docs/kcl/types
|
rm -rf documentation/content/pages/docs/kcl/types
|
||||||
rm -rf documentation/content/pages/docs/kcl/settings
|
rm -rf documentation/content/pages/docs/kcl/settings
|
||||||
|
rm -rf documentation/content/pages/docs/kcl/consts
|
||||||
# move new
|
# move new
|
||||||
mv -f docs/kcl/*.md documentation/content/pages/docs/kcl/
|
mv -f docs/kcl/*.md documentation/content/pages/docs/kcl/
|
||||||
mv -f docs/kcl/types documentation/content/pages/docs/kcl/
|
mv -f docs/kcl/types documentation/content/pages/docs/kcl/
|
||||||
mv -f docs/kcl/settings documentation/content/pages/docs/kcl/
|
mv -f docs/kcl/settings documentation/content/pages/docs/kcl/
|
||||||
|
mv -f docs/kcl/consts documentation/content/pages/docs/kcl/
|
||||||
- name: move kcl-samples
|
- name: move kcl-samples
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
25
docs/kcl/consts.md
Normal file
25
docs/kcl/consts.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
title: "KCL Constants"
|
||||||
|
excerpt: "Documentation for the KCL constants."
|
||||||
|
layout: manual
|
||||||
|
---
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
|
||||||
|
### `std`
|
||||||
|
|
||||||
|
- [`HALF_TURN`](/docs/kcl/consts/std-HALF_TURN)
|
||||||
|
- [`QUARTER_TURN`](/docs/kcl/consts/std-QUARTER_TURN)
|
||||||
|
- [`THREE_QUARTER_TURN`](/docs/kcl/consts/std-THREE_QUARTER_TURN)
|
||||||
|
- [`XY`](/docs/kcl/consts/std-XY)
|
||||||
|
- [`XZ`](/docs/kcl/consts/std-XZ)
|
||||||
|
- [`YZ`](/docs/kcl/consts/std-YZ)
|
||||||
|
- [`ZERO`](/docs/kcl/consts/std-ZERO)
|
||||||
|
|
||||||
|
### `std::math`
|
||||||
|
|
||||||
|
- [`E`](/docs/kcl/consts/std-math-E)
|
||||||
|
- [`PI`](/docs/kcl/consts/std-math-PI)
|
||||||
|
- [`TAU`](/docs/kcl/consts/std-math-TAU)
|
||||||
|
|
@ -12,25 +12,26 @@ layout: manual
|
|||||||
* [`Modules`](kcl/modules)
|
* [`Modules`](kcl/modules)
|
||||||
* [`Settings`](kcl/settings)
|
* [`Settings`](kcl/settings)
|
||||||
* [`Known Issues`](kcl/known-issues)
|
* [`Known Issues`](kcl/known-issues)
|
||||||
|
* [`Constants`](kcl/consts)
|
||||||
|
|
||||||
### Standard library
|
### Standard library
|
||||||
|
|
||||||
* **Primitive types**
|
* **Primitive types**
|
||||||
* [`bool`](kcl/bool)
|
* [`bool`](kcl/types/bool)
|
||||||
* [`number`](kcl/number)
|
* [`number`](kcl/types/number)
|
||||||
* [`string`](kcl/string)
|
* [`string`](kcl/types/string)
|
||||||
* [`tag`](kcl/tag)
|
* [`tag`](kcl/types/tag)
|
||||||
* **std**
|
* **std**
|
||||||
* [`HALF_TURN`](kcl/const_std-HALF_TURN)
|
* [`HALF_TURN`](kcl/consts/std-HALF_TURN)
|
||||||
* [`Plane`](kcl/Plane)
|
* [`Plane`](kcl/types/Plane)
|
||||||
* [`QUARTER_TURN`](kcl/const_std-QUARTER_TURN)
|
* [`QUARTER_TURN`](kcl/consts/std-QUARTER_TURN)
|
||||||
* [`Sketch`](kcl/Sketch)
|
* [`Sketch`](kcl/types/Sketch)
|
||||||
* [`Solid`](kcl/Solid)
|
* [`Solid`](kcl/types/Solid)
|
||||||
* [`THREE_QUARTER_TURN`](kcl/const_std-THREE_QUARTER_TURN)
|
* [`THREE_QUARTER_TURN`](kcl/consts/std-THREE_QUARTER_TURN)
|
||||||
* [`XY`](kcl/const_std-XY)
|
* [`XY`](kcl/consts/std-XY)
|
||||||
* [`XZ`](kcl/const_std-XZ)
|
* [`XZ`](kcl/consts/std-XZ)
|
||||||
* [`YZ`](kcl/const_std-YZ)
|
* [`YZ`](kcl/consts/std-YZ)
|
||||||
* [`ZERO`](kcl/const_std-ZERO)
|
* [`ZERO`](kcl/consts/std-ZERO)
|
||||||
* [`abs`](kcl/abs)
|
* [`abs`](kcl/abs)
|
||||||
* [`acos`](kcl/acos)
|
* [`acos`](kcl/acos)
|
||||||
* [`angleToMatchLengthX`](kcl/angleToMatchLengthX)
|
* [`angleToMatchLengthX`](kcl/angleToMatchLengthX)
|
||||||
@ -134,9 +135,9 @@ layout: manual
|
|||||||
* [`yLine`](kcl/yLine)
|
* [`yLine`](kcl/yLine)
|
||||||
* [`yd`](kcl/yd)
|
* [`yd`](kcl/yd)
|
||||||
* **std::math**
|
* **std::math**
|
||||||
* [`E`](kcl/const_std-math-E)
|
* [`E`](kcl/consts/std-math-E)
|
||||||
* [`PI`](kcl/const_std-math-PI)
|
* [`PI`](kcl/consts/std-math-PI)
|
||||||
* [`TAU`](kcl/const_std-math-TAU)
|
* [`TAU`](kcl/consts/std-math-TAU)
|
||||||
* [`cos`](kcl/std-math-cos)
|
* [`cos`](kcl/std-math-cos)
|
||||||
* [`sin`](kcl/std-math-sin)
|
* [`sin`](kcl/std-math-sin)
|
||||||
* [`tan`](kcl/std-math-tan)
|
* [`tan`](kcl/std-math-tan)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# This way we don't start and stop too many engine instances, putting pressure on our cloud.
|
# This way we don't start and stop too many engine instances, putting pressure on our cloud.
|
||||||
uses-engine = { max-threads = 4 }
|
uses-engine = { max-threads = 4 }
|
||||||
# If a test must run after the engine tests, we want to make sure the engine tests are done first.
|
# If a test must run after the engine tests, we want to make sure the engine tests are done first.
|
||||||
after-engine = { depends-on = ["uses-engine"], max-threads = 12 }
|
after-engine = { max-threads = 12 }
|
||||||
|
|
||||||
[profile.default]
|
[profile.default]
|
||||||
slow-timeout = { period = "30s", terminate-after = 1 }
|
slow-timeout = { period = "30s", terminate-after = 1 }
|
||||||
|
@ -21,7 +21,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const TYPES_DIR: &str = "../../docs/kcl/types";
|
const TYPES_DIR: &str = "../../docs/kcl/types";
|
||||||
const LANG_TOPICS: [&str; 4] = ["Types", "Modules", "Settings", "Known Issues"];
|
const LANG_TOPICS: [&str; 5] = ["Types", "Modules", "Settings", "Known Issues", "Constants"];
|
||||||
// These types are declared in std.
|
// These types are declared in std.
|
||||||
const DECLARED_TYPES: [&str; 7] = ["number", "string", "tag", "bool", "Sketch", "Solid", "Plane"];
|
const DECLARED_TYPES: [&str; 7] = ["number", "string", "tag", "bool", "Sketch", "Solid", "Plane"];
|
||||||
|
|
||||||
@ -298,6 +298,7 @@ fn init_handlebars() -> Result<handlebars::Handlebars<'static>> {
|
|||||||
hbs.register_template_string("propertyType", include_str!("templates/propertyType.hbs"))?;
|
hbs.register_template_string("propertyType", include_str!("templates/propertyType.hbs"))?;
|
||||||
hbs.register_template_string("schema", include_str!("templates/schema.hbs"))?;
|
hbs.register_template_string("schema", include_str!("templates/schema.hbs"))?;
|
||||||
hbs.register_template_string("index", include_str!("templates/index.hbs"))?;
|
hbs.register_template_string("index", include_str!("templates/index.hbs"))?;
|
||||||
|
hbs.register_template_string("consts-index", include_str!("templates/consts-index.hbs"))?;
|
||||||
hbs.register_template_string("function", include_str!("templates/function.hbs"))?;
|
hbs.register_template_string("function", include_str!("templates/function.hbs"))?;
|
||||||
hbs.register_template_string("const", include_str!("templates/const.hbs"))?;
|
hbs.register_template_string("const", include_str!("templates/const.hbs"))?;
|
||||||
hbs.register_template_string("type", include_str!("templates/type.hbs"))?;
|
hbs.register_template_string("type", include_str!("templates/type.hbs"))?;
|
||||||
@ -312,6 +313,9 @@ fn generate_index(combined: &IndexMap<String, Box<dyn StdLibFn>>, kcl_lib: &[Doc
|
|||||||
let mut functions = HashMap::new();
|
let mut functions = HashMap::new();
|
||||||
functions.insert("std".to_owned(), Vec::new());
|
functions.insert("std".to_owned(), Vec::new());
|
||||||
|
|
||||||
|
let mut constants = HashMap::new();
|
||||||
|
constants.insert("std".to_owned(), Vec::new());
|
||||||
|
|
||||||
for key in combined.keys() {
|
for key in combined.keys() {
|
||||||
let internal_fn = combined
|
let internal_fn = combined
|
||||||
.get(key)
|
.get(key)
|
||||||
@ -337,6 +341,13 @@ fn generate_index(combined: &IndexMap<String, Box<dyn StdLibFn>>, kcl_lib: &[Doc
|
|||||||
DocData::Const(c) => (c.name.clone(), d.file_name()),
|
DocData::Const(c) => (c.name.clone(), d.file_name()),
|
||||||
DocData::Ty(t) => (t.name.clone(), d.file_name()),
|
DocData::Ty(t) => (t.name.clone(), d.file_name()),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if let DocData::Const(c) = d {
|
||||||
|
constants
|
||||||
|
.entry(d.mod_name())
|
||||||
|
.or_default()
|
||||||
|
.push((c.name.clone(), d.file_name()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO we should sub-divide into types, constants, and functions.
|
// TODO we should sub-divide into types, constants, and functions.
|
||||||
@ -362,7 +373,7 @@ fn generate_index(combined: &IndexMap<String, Box<dyn StdLibFn>>, kcl_lib: &[Doc
|
|||||||
.map(|name| {
|
.map(|name| {
|
||||||
json!({
|
json!({
|
||||||
"name": name,
|
"name": name,
|
||||||
"file_name": name.to_lowercase().replace(' ', "-"),
|
"file_name": name.to_lowercase().replace(' ', "-").replace("constants", "consts"),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -375,6 +386,31 @@ fn generate_index(combined: &IndexMap<String, Box<dyn StdLibFn>>, kcl_lib: &[Doc
|
|||||||
|
|
||||||
expectorate::assert_contents("../../docs/kcl/index.md", &output);
|
expectorate::assert_contents("../../docs/kcl/index.md", &output);
|
||||||
|
|
||||||
|
// Generate the index for the constants.
|
||||||
|
let mut sorted_consts: Vec<_> = constants
|
||||||
|
.into_iter()
|
||||||
|
.map(|(m, mut consts)| {
|
||||||
|
consts.sort();
|
||||||
|
let val = json!({
|
||||||
|
"name": m,
|
||||||
|
"consts": consts.into_iter().map(|(n, f)| json!({
|
||||||
|
"name": n,
|
||||||
|
"file_name": f,
|
||||||
|
})).collect::<Vec<_>>(),
|
||||||
|
});
|
||||||
|
(m, val)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
sorted_consts.sort_by(|t1, t2| t1.0.cmp(&t2.0));
|
||||||
|
let data: Vec<_> = sorted_consts.into_iter().map(|(_, val)| val).collect();
|
||||||
|
let data = json!({
|
||||||
|
"consts": data,
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = hbs.render("consts-index", &data)?;
|
||||||
|
|
||||||
|
expectorate::assert_contents("../../docs/kcl/consts.md", &output);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +441,7 @@ fn generate_example(index: usize, src: &str, props: &ExampleProperties, file_nam
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_type_from_kcl(ty: &TyData, file_name: String) -> Result<()> {
|
fn generate_type_from_kcl(ty: &TyData, file_name: String, example_name: String) -> Result<()> {
|
||||||
if ty.properties.doc_hidden {
|
if ty.properties.doc_hidden {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -416,7 +452,7 @@ fn generate_type_from_kcl(ty: &TyData, file_name: String) -> Result<()> {
|
|||||||
.examples
|
.examples
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(index, example)| generate_example(index, &example.0, &example.1, &file_name))
|
.filter_map(|(index, example)| generate_example(index, &example.0, &example.1, &example_name))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let data = json!({
|
let data = json!({
|
||||||
@ -428,7 +464,7 @@ fn generate_type_from_kcl(ty: &TyData, file_name: String) -> Result<()> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let output = hbs.render("kclType", &data)?;
|
let output = hbs.render("kclType", &data)?;
|
||||||
expectorate::assert_contents(format!("../../docs/kcl/types/{}.md", file_name), &output);
|
expectorate::assert_contents(format!("../../docs/kcl/{}.md", file_name), &output);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -480,7 +516,7 @@ fn generate_function_from_kcl(function: &FnData, file_name: String) -> Result<()
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_const_from_kcl(cnst: &ConstData, file_name: String) -> Result<()> {
|
fn generate_const_from_kcl(cnst: &ConstData, file_name: String, example_name: String) -> Result<()> {
|
||||||
if cnst.properties.doc_hidden {
|
if cnst.properties.doc_hidden {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -490,7 +526,7 @@ fn generate_const_from_kcl(cnst: &ConstData, file_name: String) -> Result<()> {
|
|||||||
.examples
|
.examples
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(index, example)| generate_example(index, &example.0, &example.1, &file_name))
|
.filter_map(|(index, example)| generate_example(index, &example.0, &example.1, &example_name))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let data = json!({
|
let data = json!({
|
||||||
@ -1028,8 +1064,8 @@ fn test_generate_stdlib_markdown_docs() {
|
|||||||
for d in &kcl_std {
|
for d in &kcl_std {
|
||||||
match d {
|
match d {
|
||||||
DocData::Fn(f) => generate_function_from_kcl(f, d.file_name()).unwrap(),
|
DocData::Fn(f) => generate_function_from_kcl(f, d.file_name()).unwrap(),
|
||||||
DocData::Const(c) => generate_const_from_kcl(c, d.file_name()).unwrap(),
|
DocData::Const(c) => generate_const_from_kcl(c, d.file_name(), d.example_name()).unwrap(),
|
||||||
DocData::Ty(t) => generate_type_from_kcl(t, d.file_name()).unwrap(),
|
DocData::Ty(t) => generate_type_from_kcl(t, d.file_name(), d.example_name()).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1061,7 +1097,8 @@ fn test_generate_stdlib_json_schema() {
|
|||||||
async fn test_code_in_topics() {
|
async fn test_code_in_topics() {
|
||||||
let mut join_set = JoinSet::new();
|
let mut join_set = JoinSet::new();
|
||||||
for name in LANG_TOPICS {
|
for name in LANG_TOPICS {
|
||||||
let filename = format!("../../docs/kcl/{}.md", name.to_lowercase().replace(' ', "-"));
|
let filename =
|
||||||
|
format!("../../docs/kcl/{}.md", name.to_lowercase().replace(' ', "-")).replace("constants", "consts");
|
||||||
let mut file = File::open(&filename).unwrap();
|
let mut file = File::open(&filename).unwrap();
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
file.read_to_string(&mut text).unwrap();
|
file.read_to_string(&mut text).unwrap();
|
||||||
|
@ -116,10 +116,18 @@ impl DocData {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn file_name(&self) -> String {
|
pub fn file_name(&self) -> String {
|
||||||
|
match self {
|
||||||
|
DocData::Fn(f) => f.qual_name.replace("::", "-"),
|
||||||
|
DocData::Const(c) => format!("consts/{}", c.qual_name.replace("::", "-")),
|
||||||
|
DocData::Ty(t) => format!("types/{}", t.name.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn example_name(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
DocData::Fn(f) => f.qual_name.replace("::", "-"),
|
DocData::Fn(f) => f.qual_name.replace("::", "-"),
|
||||||
DocData::Const(c) => format!("const_{}", c.qual_name.replace("::", "-")),
|
DocData::Const(c) => format!("const_{}", c.qual_name.replace("::", "-")),
|
||||||
// TODO might want to change this
|
|
||||||
DocData::Ty(t) => t.name.clone(),
|
DocData::Ty(t) => t.name.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -872,7 +880,7 @@ mod test {
|
|||||||
Ok(img) => img,
|
Ok(img) => img,
|
||||||
};
|
};
|
||||||
twenty_twenty::assert_image(
|
twenty_twenty::assert_image(
|
||||||
format!("tests/outputs/serial_test_example_{}{i}.png", d.file_name()),
|
format!("tests/outputs/serial_test_example_{}{i}.png", d.example_name()),
|
||||||
&result,
|
&result,
|
||||||
0.99,
|
0.99,
|
||||||
);
|
);
|
||||||
|
17
rust/kcl-lib/src/docs/templates/consts-index.hbs
vendored
Normal file
17
rust/kcl-lib/src/docs/templates/consts-index.hbs
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: "KCL Constants"
|
||||||
|
excerpt: "Documentation for the KCL constants."
|
||||||
|
layout: manual
|
||||||
|
---
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
{{#each consts}}
|
||||||
|
|
||||||
|
### `{{name}}`
|
||||||
|
|
||||||
|
{{#each consts}}
|
||||||
|
- [`{{name}}`](/docs/kcl/{{file_name}})
|
||||||
|
{{/each}}
|
||||||
|
{{/each}}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
source: kcl/src/simulation_tests.rs
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
description: Result of parsing array_elem_pop.kcl
|
description: Result of parsing array_elem_pop.kcl
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
source: kcl/src/simulation_tests.rs
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
description: Result of parsing array_elem_pop_empty_fail.kcl
|
description: Result of parsing array_elem_pop_empty_fail.kcl
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
source: kcl/src/simulation_tests.rs
|
source: kcl-lib/src/simulation_tests.rs
|
||||||
description: Error from executing array_elem_pop_empty_fail.kcl
|
description: Error from executing array_elem_pop_empty_fail.kcl
|
||||||
---
|
---
|
||||||
KCL Semantic error
|
KCL Semantic error
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user