-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88b6a13
commit 98b894b
Showing
7 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,8 @@ desktop.ini | |
/build | ||
|
||
tags | ||
|
||
# Rust workspace build target | ||
/target | ||
/testing/extract-tutorial-code/target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[workspace] | ||
members = [ | ||
"testing/extract-tutorial-code", | ||
] | ||
|
||
exclude = [ | ||
"testing/crowdfunding-esdt", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by `extract-tutorial-code` | ||
/mandos | ||
/src/lib.rs | ||
/Cargo.toml | ||
|
||
/target/ | ||
*/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "extract-tutorial-code" | ||
version = "0.0.0" | ||
authors = ["Andrei Marinica <[email protected]>"] | ||
edition = "2018" | ||
|
||
[[bin]] | ||
name = "test-gen" | ||
path = "src/extract_code.rs" | ||
|
||
[dependencies] | ||
waltz = "0.4.1" | ||
pulldown-cmark = { version = "0.1", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::{fs, fs::File, io::Write, path::Path}; | ||
|
||
use waltz::CodeBlock; | ||
|
||
fn extract_code_blocks_from_file<P: AsRef<Path>>(path: P) -> Vec<CodeBlock> { | ||
let contents = fs::read_to_string(path.as_ref()) | ||
.unwrap_or_else(|e| panic!("not found: {} {:?}", e, path.as_ref())); | ||
let markdown = pulldown_cmark::Parser::new(contents.as_str()); | ||
waltz::extract_code_blocks(markdown).unwrap() | ||
} | ||
|
||
fn extract_crowdfunding_tutorial_code_blocks() -> Vec<CodeBlock> { | ||
let mut code_blocks_1 = | ||
extract_code_blocks_from_file("../../docs/developers/tutorials/crowdfunding-p1.md"); | ||
let code_blocks_2 = | ||
extract_code_blocks_from_file("../../docs/developers/tutorials/crowdfunding-p2.md"); | ||
code_blocks_1.extend(code_blocks_2.into_iter()); | ||
code_blocks_1 | ||
} | ||
|
||
fn write_code_block<P: AsRef<Path>>(path: P, code_block: &CodeBlock) { | ||
let mut file = File::create(path).unwrap(); | ||
file.write_all(code_block.content().as_bytes()).unwrap(); | ||
} | ||
|
||
fn main() { | ||
fs::create_dir_all("../crowdfunding-esdt/mandos").unwrap(); | ||
|
||
let code_blocks = extract_crowdfunding_tutorial_code_blocks(); | ||
for code_block in &code_blocks { | ||
if let Some(filename) = code_block.filename() { | ||
println!("{}", filename.as_str()); | ||
match filename.as_str() { | ||
"Cargo.toml" => write_code_block("../crowdfunding-esdt/Cargo.toml", code_block), | ||
"final.rs" => write_code_block("../crowdfunding-esdt/src/lib.rs", code_block), | ||
"crowdfunding-init.scen.json" => write_code_block( | ||
"../crowdfunding-esdt/mandos/crowdfunding-init.scen.json", | ||
code_block, | ||
), | ||
"crowdfunding-fund.scen.json" => write_code_block( | ||
"../crowdfunding-esdt/mandos/crowdfunding-fund.scen.json", | ||
code_block, | ||
), | ||
"crowdfunding-fund-too-late.scen.json" => write_code_block( | ||
"../crowdfunding-esdt/mandos/crowdfunding-fund-too-late.scen.json", | ||
code_block, | ||
), | ||
_ => {} | ||
} | ||
} | ||
} | ||
} |