render: updates for integration with frontends
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2025 Emma Tebibyte <emma@tebibyte.media>
|
* Copyright (c) 2025–2026 Emma Tebibyte <emma@tebibyte.media>
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* This file is part of Mintee.
|
* This file is part of Mintee.
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
* terms of the GNU Affero General Public License as published by the Free
|
* terms of the GNU Affero General Public License as published by the Free
|
||||||
* Software Foundation, either version 3 of the License, or (at your option)
|
* Software Foundation, either version 3 of the License, or (at your option)
|
||||||
* any later version.
|
* any later version.
|
||||||
*
|
*
|
||||||
* Mintee is distributed in the hope that it will be useful, but WITHOUT ANY
|
* Mintee is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||||
@@ -26,27 +26,22 @@ use std::{
|
|||||||
|
|
||||||
use tera::{ Context, Tera };
|
use tera::{ Context, Tera };
|
||||||
|
|
||||||
|
/* TODO: silt needs to export the HTTP error types */
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum PageError {
|
||||||
|
NotFound,
|
||||||
|
}
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum PageKind {
|
pub enum PageKind {
|
||||||
Code,
|
Code,
|
||||||
Dashboard,
|
Dashboard,
|
||||||
Tickets,
|
Tickets,
|
||||||
|
Project,
|
||||||
|
RawCode,
|
||||||
|
Repo,
|
||||||
User,
|
User,
|
||||||
}
|
Invalid(PageError),
|
||||||
|
|
||||||
impl PageKind {
|
|
||||||
pub fn render_page(&self, ctx: Context) -> Result<String, Box<dyn Error>> {
|
|
||||||
let page_dir = self.to_string();
|
|
||||||
let template = String::from_utf8(Path::new(&page_dir)
|
|
||||||
.to_path_buf()
|
|
||||||
.as_mut_os_string()
|
|
||||||
.as_encoded_bytes()
|
|
||||||
.to_vec()
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let tera = Tera::new(&page_dir)?;
|
|
||||||
Ok(tera.render(&template, &ctx)?)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for PageKind {
|
impl Display for PageKind {
|
||||||
@@ -57,9 +52,36 @@ impl Display for PageKind {
|
|||||||
Code => "repo/code.html",
|
Code => "repo/code.html",
|
||||||
Dashboard => "dashboard.html",
|
Dashboard => "dashboard.html",
|
||||||
Tickets => "repo/tickets.html",
|
Tickets => "repo/tickets.html",
|
||||||
|
Repo => "repo/code.html",
|
||||||
User => "user.html",
|
User => "user.html",
|
||||||
|
_ => "",
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "./assets/templates/{}", path)
|
write!(f, "./assets/templates/{}", path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Page {
|
||||||
|
kind: PageKind,
|
||||||
|
path: String,
|
||||||
|
branch: Option<String>,
|
||||||
|
commit: Option<String>,
|
||||||
|
tag: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
impl Page {
|
||||||
|
pub fn render(&self) -> Result<String, Box<dyn Error>> {
|
||||||
|
let template_dir = self.kind.to_string();
|
||||||
|
let template = String::from_utf8(Path::new(&template_dir)
|
||||||
|
.to_path_buf()
|
||||||
|
.as_mut_os_string()
|
||||||
|
.as_encoded_bytes()
|
||||||
|
.to_vec()
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let tera = Tera::new(&page_dir)?;
|
||||||
|
Ok(tera.render(&template, &ctx)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use gix::open;
|
use gix::open;
|
||||||
use tera::{ Context, Tera };
|
use tera::Tera;
|
||||||
|
|
||||||
use mintee::backend::git::repo_to_context;
|
use mintee::backend::git::repo_to_context;
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let tera = Tera::new(templates.as_str())?;
|
let tera = Tera::new(templates.as_str())?;
|
||||||
let ctx = repo_to_context(open(current_dir()?)?)?;
|
let ctx = repo_to_context(open(current_dir()?)?)?;
|
||||||
|
|
||||||
println!("{}", tera.render("code.html", &ctx)?);
|
println!("{}", tera.render("repo.html", &ctx)?);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user