-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --init-templates
and --start-theme
Flags
#86
Conversation
Signed-off-by: Akash <[email protected]>
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
pub struct Templates; |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can call
Line 45 in 8984168
pub fn generate_static(static_folder: &Path) { |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Co-authored-by: Bruno Rocha <[email protected]>
…nto initTempCmd
@rochacbruno Your requested changes have been made! |
This PR introduces two new flags,
--init-templates
and--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.html
file as a starter template.--start-theme
: Extends the--init-templates
command 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 thetemplates
directory and base files.initialize_theme_assets
: Sets up thestatic
assets 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_templates
andinitialize_theme_assets
functions should be implemented. Specifically:base.html
file within thetemplates
folder? Should it be a full HTML skeleton, or just a simple comment indicating where customization can begin?style.css
andscript.js
in thestatic/
folder include specific starter content, or can they be empty placeholders?Related Issue : #70