Skip to content

Commit 4436419

Browse files
authored
Merge pull request #21 from iancleary/bug/folder_path_relative_path_vs_bare_filename
Handle when path is just filename
2 parents c5a8160 + 0874942 commit 4436419

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ homepage = "https://github.com/iancleary/touchstone"
77
license = "MIT"
88
name = "touchstone"
99
repository = "https://github.com/iancleary/touchstone"
10-
version = "0.7.1"
10+
version = "0.7.2"
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

src/plot.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::Path;
2+
13
// The paths are relative to this .rs file
24
pub(crate) static PLOTLY_JS: &str = include_str!("assets/js/plotly-3.3.0.min.js");
35
// pub (crate) static PLOTLY_SRC_LINE: &str = "./js/plotly-3.3.0.min.js";
@@ -54,7 +56,14 @@ pub fn generate_two_port_plot_html(
5456
s12_data: &str,
5557
s22_data: &str,
5658
) -> std::io::Result<()> {
57-
let folder_path = std::path::Path::new(output_path).parent().unwrap();
59+
60+
// this only works if a relative path or full path is given.
61+
// the unwrap fails if "ntwk1.s2p" is given instead of "./ntwk1.s2p"
62+
// Attempt to get parent; if None, default to "." (current dir)
63+
let folder_path = Path::new(output_path)
64+
.parent()
65+
.map(|p| if p.as_os_str().is_empty() { Path::new(".") } else { p })
66+
.unwrap_or(Path::new("."));
5867
std::fs::create_dir_all(folder_path)?;
5968

6069
let mut html_content = include_str!("assets/template_2port.html").to_string();

0 commit comments

Comments
 (0)