From 6d132487be9b32a92ac4b6a84053cba9f098064c Mon Sep 17 00:00:00 2001 From: Piotr Magiera Date: Wed, 17 Jul 2024 15:46:28 +0200 Subject: [PATCH] Add book.toml generation commit-id:b5f6227b --- Cargo.lock | 1 + extensions/scarb-doc/Cargo.toml | 2 +- extensions/scarb-doc/src/docs_generation.rs | 1 + .../scarb-doc/src/docs_generation/markdown.rs | 1 + .../src/docs_generation/markdown/book_toml.rs | 29 +++++++++++++++++++ extensions/scarb-doc/src/lib.rs | 1 + 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 extensions/scarb-doc/src/docs_generation.rs create mode 100644 extensions/scarb-doc/src/docs_generation/markdown.rs create mode 100644 extensions/scarb-doc/src/docs_generation/markdown/book_toml.rs diff --git a/Cargo.lock b/Cargo.lock index 8d478e20d..d26bd7135 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4738,6 +4738,7 @@ dependencies = [ "cairo-lang-starknet", "cairo-lang-syntax", "cairo-lang-utils", + "camino", "clap", "expect-test", "indoc", diff --git a/extensions/scarb-doc/Cargo.toml b/extensions/scarb-doc/Cargo.toml index fd468fd74..d99bf10f3 100644 --- a/extensions/scarb-doc/Cargo.toml +++ b/extensions/scarb-doc/Cargo.toml @@ -22,6 +22,7 @@ cairo-lang-starknet.workspace = true cairo-lang-syntax.workspace = true cairo-lang-utils.workspace = true expect-test.workspace = true +indoc.workspace = true itertools.workspace = true scarb-metadata = { path = "../../scarb-metadata" } scarb-ui = { path = "../../utils/scarb-ui" } @@ -32,5 +33,4 @@ smol_str.workspace = true [dev-dependencies] assert_fs.workspace = true -indoc.workspace = true scarb-test-support = { path = "../../utils/scarb-test-support" } diff --git a/extensions/scarb-doc/src/docs_generation.rs b/extensions/scarb-doc/src/docs_generation.rs new file mode 100644 index 000000000..577affa97 --- /dev/null +++ b/extensions/scarb-doc/src/docs_generation.rs @@ -0,0 +1 @@ +mod markdown; diff --git a/extensions/scarb-doc/src/docs_generation/markdown.rs b/extensions/scarb-doc/src/docs_generation/markdown.rs new file mode 100644 index 000000000..a4e89b61d --- /dev/null +++ b/extensions/scarb-doc/src/docs_generation/markdown.rs @@ -0,0 +1 @@ +mod book_toml; diff --git a/extensions/scarb-doc/src/docs_generation/markdown/book_toml.rs b/extensions/scarb-doc/src/docs_generation/markdown/book_toml.rs new file mode 100644 index 000000000..d860d627d --- /dev/null +++ b/extensions/scarb-doc/src/docs_generation/markdown/book_toml.rs @@ -0,0 +1,29 @@ +use indoc::formatdoc; + +use crate::AdditionalMetadata; + +#[allow(dead_code)] +pub(super) fn generate_book_toml_content(package_metadata: &AdditionalMetadata) -> String { + formatdoc! { + r#" + [book] + authors = {:?} + language = "en" + multilingual = false + src = "src" + title = "{} - Cairo" + + [output.html] + no-section-label = true + + [output.html.playground] + runnable = false + + [output.html.fold] + enable = true + level = 0 + "#, + package_metadata.authors.clone().unwrap_or_else(|| vec!["".to_string()]), + package_metadata.name + } +} diff --git a/extensions/scarb-doc/src/lib.rs b/extensions/scarb-doc/src/lib.rs index bcc39b0f0..9a3661a1a 100644 --- a/extensions/scarb-doc/src/lib.rs +++ b/extensions/scarb-doc/src/lib.rs @@ -9,6 +9,7 @@ use crate::metadata::compilation::get_project_config; use types::Crate; pub mod db; +pub mod docs_generation; pub mod metadata; pub mod types; pub mod versioned_json_output;