Add --init-templates and --start-theme Flags #86
Add --init-templates and --start-theme Flags #86rochacbruno merged 5 commits intorochacbruno:mainfrom
--init-templates and --start-theme Flags #86Conversation
Signed-off-by: Akash <akashsingh2210670@gmail.com>
|
@rochacbruno Could you please review this and answer my doubts? |
src/templates.rs
Outdated
| let base_template_path = templates_path.join("base.html"); | ||
| if let Err(e) = fs::write(base_template_path, "<!-- Base HTML template -->") { | ||
| error!("Failed to create base template: {}", e); | ||
| } |
There was a problem hiding this comment.
output_folder should actually be the input_folder in this case,
here we are writing templates, the output_folder is where we write the rendered files.
We want to write all the embedded templates with its contents.
Here you can use
Line 16 in 8984168
Something like
for name in Templates::iter() {
let template = Templates::get(name.as_ref()).unwrap();
let template_str = std::str::from_utf8(template.data.as_ref()).unwrap();
# here you write to `templates_path.join(&name)` the contents of template_str
}There was a problem hiding this comment.
Instead of writing to output_folder, initialize_templates now writes to input_folder. The function creates the templates directory within input_folder and iterates through all embedded templates using Templates::iter()
src/templates.rs
Outdated
| let css_path = static_path.join("style.css"); | ||
| let js_path = static_path.join("script.js"); | ||
|
|
||
| if let Err(e) = fs::write(css_path, "/* Add your styles here */") { | ||
| error!("Failed to create CSS file: {}", e); | ||
| } | ||
|
|
||
| if let Err(e) = fs::write(js_path, "// Add your scripts here") { | ||
| error!("Failed to create JavaScript file: {}", e); | ||
| } |
There was a problem hiding this comment.
Here you can call
Line 45 in 8984168
But passing the input_folder.join("static"), if it does not exists yet
The output will be the embedded template, then user can customize before generating the site.
There was a problem hiding this comment.
The initialize_theme_assets function creates a static folder in input_folder (if it doesn’t already exist) and then calls generate_static(&static_path). This utilizes the generate_static function to populate static with embedded assets, eliminating the need for placeholder files
Co-authored-by: Bruno Rocha <rochacbruno@users.noreply.github.com>
Co-authored-by: Bruno Rocha <rochacbruno@users.noreply.github.com>
…nto initTempCmd
|
@rochacbruno Your requested changes have been made! |
This PR introduces two new flags,
--init-templatesand--start-theme, to the Marmite CLI, allowing users to initialize project templates and themes more easily. The new flags add the following functionality:--init-templates: Creates atemplates/folder in the output directory, adding abase.htmlfile as a starter template.--start-theme: Extends the--init-templatescommand by additionally creating astatic/folder with placeholder files (style.css,script.js) referenced by the templates.To support these new flags, two functions were added:
initialize_templates: Sets up thetemplatesdirectory and base files.initialize_theme_assets: Sets up thestaticassets directory and initial CSS/JS files.Both functions are currently in a new module,
initializer.rs, but they contain only placeholder code for now.Questions
Before proceeding with the complete implementation, we would like some input on how the
initialize_templatesandinitialize_theme_assetsfunctions should be implemented. Specifically:base.htmlfile within thetemplatesfolder? Should it be a full HTML skeleton, or just a simple comment indicating where customization can begin?style.cssandscript.jsin thestatic/folder include specific starter content, or can they be empty placeholders?Related Issue : #70