Skip to content

Use html-builder for HTML generation in admin templates #6

@dannywillems

Description

@dannywillems

Description

Replace raw HTML strings with the typed html-builder library for safer, more maintainable HTML generation.

Current State

The admin templates use raw HTML strings with format! macros:

fn render_base(title: &str, content: &str) -> String {
    format!(r#"<!DOCTYPE html>
<html lang="en">
<head>...</head>
<body>{content}</body>
</html>"#)
}

Desired State

Use https://github.com/leakIX/html-builder for type-safe HTML:

use html_builder::*;

fn render_base(title: &str, content: &str) -> String {
    html()
        .lang("en")
        .child(head().child(title_tag().text(title)))
        .child(body().child(content))
        .render()
}

Files to Update

  • crates/oxide-admin/src/templates/base.rs
  • crates/oxide-admin/src/templates/list.rs
  • crates/oxide-admin/src/templates/detail.rs
  • crates/oxide-admin/examples/blog_admin.rs

Benefits

  • Type-safe HTML generation
  • No XSS vulnerabilities from string interpolation
  • Better refactoring support
  • Cleaner code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions