-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #70 --------- Signed-off-by: Akash <[email protected]> Co-authored-by: Bruno Rocha <[email protected]>
- Loading branch information
1 parent
8984168
commit 83229f0
Showing
3 changed files
with
70 additions
and
3 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
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,42 @@ | ||
use log::error; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use crate::embedded::{Templates, generate_static}; | ||
|
||
/// Creates the `templates/` folder and writes embedded templates to it. | ||
pub fn initialize_templates(input_folder: &PathBuf) { | ||
let templates_path = input_folder.join("templates"); | ||
if let Err(e) = fs::create_dir_all(&templates_path) { | ||
error!("Failed to create templates directory: {}", e); | ||
return; | ||
} | ||
|
||
for name in Templates::iter() { | ||
if let Some(template) = Templates::get(name.as_ref()) { | ||
if let Ok(template_str) = std::str::from_utf8(template.data.as_ref()) { | ||
let template_path = templates_path.join(name.as_ref()); | ||
if let Err(e) = fs::write(&template_path, template_str) { | ||
error!("Failed to write template '{}': {}", name.as_ref(), e); | ||
} | ||
} else { | ||
error!("Failed to parse template '{}' as UTF-8", name.as_ref()); | ||
} | ||
} else { | ||
error!("Template '{}' not found in embedded resources", name.as_ref()); | ||
} | ||
} | ||
} | ||
|
||
/// Uses `generate_static` to populate the `static/` folder with embedded content. | ||
pub fn initialize_theme_assets(input_folder: &PathBuf) { | ||
let static_path = input_folder.join("static"); | ||
|
||
if !static_path.exists() { | ||
if let Err(e) = fs::create_dir_all(&static_path) { | ||
error!("Failed to create static assets directory: {}", e); | ||
return; | ||
} | ||
} | ||
|
||
generate_static(&static_path); | ||
} |