Skip to content

Commit

Permalink
#38: in mode 'doc' extract into 'target/doc/'
Browse files Browse the repository at this point in the history
  • Loading branch information
frehberg committed Apr 6, 2023
1 parent 71f65e7 commit 41d4044
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::iter;
use syn::{Attribute, Ident, MetaNameValue};
use std::fs;
use std::io::Cursor;
use std::io::prelude::*;
use std::path::Path;

// embedded JS code being inserted as html script elmenets
Expand Down Expand Up @@ -131,14 +130,22 @@ impl quote::ToTokens for Attrs {
}

fn place_mermaid_js() -> std::io::Result<()> {
let docs_dir = Path::new("./target/doc");
let static_files_mermaid_dir = docs_dir.join(MERMAID_JS_LOCAL_DIR);
if static_files_mermaid_dir.exists() {
Ok(())
let target_dir = std::env::var("CARGO_TARGET_DIR")
.unwrap_or("./target".to_string());
let docs_dir = Path::new(&target_dir).join("doc");
// extract mermaid module iff rustdoc folder exists already
if docs_dir.exists() {
let static_files_mermaid_dir = docs_dir.join(MERMAID_JS_LOCAL_DIR);
if static_files_mermaid_dir.exists() {
Ok(())
} else {
fs::create_dir_all(&static_files_mermaid_dir).unwrap();
let mut zip = zip::ZipArchive::new(Cursor::new(MERMAID_JS_CODE)).unwrap();
zip.extract(static_files_mermaid_dir)?;
Ok(())
}
} else {
fs::create_dir_all(&static_files_mermaid_dir).unwrap();
let mut zip = zip::ZipArchive::new(Cursor::new(MERMAID_JS_CODE)).unwrap();
zip.extract(static_files_mermaid_dir)?;
// no rustdocs rendering
Ok(())
}
}
Expand Down

0 comments on commit 41d4044

Please sign in to comment.