need to move repeatable code from demo website to framework #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
need to move repeatable code from demo website to framework
come up with a good strategy to move much more in lib and then we can reuse
its also ok to use macro's if that would help
we want to be able to create a website out of some html templates
rest is all default but we can overrule it
Implementation Spec for Issue #3: Move Repeatable Code to Framework
Objective
Consolidate admin templates, auth handlers, admin handlers, and common middleware from
crates/demo_website/intocrates/hero_website_lib/so that creating a new website requires only providing custom HTML templates and a minimalmain.rs. All admin UI, authentication, handler boilerplate, and middleware come from the library by default but remain overridable.Requirements
admin/, 4 underauth/) embedded in the library and served by defaultHeroWebsitetrait allows sites to: provide custom templates that override defaults, provide custom routes, configure site name/admin password/DB URLImplementation Plan
Step 1: Create
HeroWebsiteTrait and Template Mergingsrc/website.rswith theHeroWebsitetrait (db, templates, site_name, year, admin_password, blog, document_root)src/templates.rswithrust-embedfor default admin/auth templates + merge logicsrc/default_templates/Step 2: Move Admin Page Handlers to Library
src/admin/default_handlers.rswith all handlers from demo'shandlers/admin.rs, generic overHeroWebsiterender_template,admin_update_redirect,admin_deleteutilsStep 3: Move Group, Profile, Document, and Export Handlers
groups_handlers.rs,profiles_handlers.rs,documents_handlers.rs,export_handlers.rsHeroWebsite, with form structs moved tooStep 4: Move User-Facing Auth Handlers
src/auth/default_handlers.rswith login/register/logout/members handlersHeroWebsitetraitStep 5: Create Default Router Builders
default_admin_router<S>()wiring all ~40 admin routesdefault_auth_router<S>()wiring login/register/logout/members routesStep 6: Simplify the Demo Website
HeroWebsiteforAppStatehandlers/admin.rs,auth.rs,groups.rs,profiles.rs,documents.rs,export.rs,utils.rsStep 7 (Optional): Add Convenience Macros
admin_page!macro to reduce handler boilerplateAcceptance Criteria
HeroWebsite+ callingdefault_admin_router()default_auth_router()cargo buildsucceeds for both library and demo websiteTest Results
Failed Doc-tests (6)
All 6 failures are doc-test compilation errors in
hero_website_lib— the doc examples reference types/functions not in scope:src/blog/loader.rs(line 9)src/auth/router.rs(line 3)MyApptype not foundsrc/admin/mod.rs(line 53)AppStatetype not foundsrc/admin/router.rs(line 3)MyApptype not foundsrc/lib.rs(line 85)build_routerfunction not foundsrc/lib.rs(line 12)MyWebsitestruct not foundSummary
The workspace builds successfully and all 4 unit tests pass. The 6 failures are all doc-test examples that don't compile because they reference user-defined types (
MyApp,AppState,MyWebsite,build_router) without defining them, or contain non-Rust content in a code block. These doc examples needno_run,ignore, orcompile_failannotations, or should define stub types.Implementation Complete
Changes Summary
New library infrastructure (
hero_website_lib):src/website.rs--HeroWebsitetrait with blanketAdminSiteimplsrc/templates.rs-- Embedded default templates with merge logic (site templates override library defaults)src/macros.rs--require_admin_or_redirect!,require_admin_or_401!,admin_context!,render_admin_template!default_templates/admin/-- 16 embedded admin HTML templatesdefault_templates/auth/-- 4 embedded auth HTML templatesHandlers moved to library (generic over
HeroWebsite):src/admin/default_handlers.rs-- Dashboard, users, logs, visits, blog admin, RPC, all admin APIssrc/admin/groups_handlers.rs-- Group management CRUDsrc/admin/profiles_handlers.rs-- Access profile managementsrc/admin/documents_handlers.rs-- Document admin + public viewersrc/admin/export_handlers.rs-- DB export/importsrc/auth/default_handlers.rs-- Login, register, logout, membersRouter builders:
src/admin/router.rs--default_admin_router<S>()with all ~40 admin routessrc/auth/router.rs--default_auth_router<S>()with login/register/logout/memberssrc/docs/router.rs--default_documents_router<S>()with public doc viewer routesDemo website simplified:
main.rsnow implementsHeroWebsiteand merges library routers with site-specific routes onlyTest Results
How to Use
A new website just needs to:
HeroWebsitefor itsAppStatemerge_default_templates(&mut tera)when loading templatesdefault_admin_router(),default_auth_router(),default_documents_router()into its routerImplementation committed:
358cbd5Browse:
358cbd5