Skip to content
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

Merged
merged 5 commits into from
Oct 27, 2024

Conversation

SkySingh04
Copy link
Contributor

@SkySingh04 SkySingh04 commented Oct 26, 2024

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 a templates/ folder in the output directory, adding a base.html file as a starter template.
  • --start-theme: Extends the --init-templates command by additionally creating a static/ 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 the templates directory and base files.
  • initialize_theme_assets: Sets up the static 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 and initialize_theme_assets functions should be implemented. Specifically:

  1. Template Content: What content should be included in the base.html file within the templates folder? Should it be a full HTML skeleton, or just a simple comment indicating where customization can begin?
  2. Static Assets: Should style.css and script.js in the static/ folder include specific starter content, or can they be empty placeholders?

Related Issue : #70

@SkySingh04
Copy link
Contributor Author

@rochacbruno Could you please review this and answer my doubts?

src/templates.rs Outdated
Comment on lines 13 to 16
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);
}
Copy link
Owner

@rochacbruno rochacbruno Oct 26, 2024

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

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
}

Copy link
Contributor Author

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
Comment on lines 27 to 36
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);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can call

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.

Copy link
Contributor Author

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

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@SkySingh04
Copy link
Contributor Author

@rochacbruno Your requested changes have been made!

@rochacbruno rochacbruno merged commit 83229f0 into rochacbruno:main Oct 27, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants