diff --git a/src/main.rs b/src/main.rs index 7c6f291..d1f32b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,16 +23,29 @@ struct HelloTemplate<'a> { name: &'a str, } +struct User { + name : String, +} + +struct Owner { + name : String, +} + +struct Repository { + name : String, + owner : Owner, +} + #[derive(Template)] #[template(path = "git.html")] struct GitMainTemplate where for <'a> &'a TS : IntoIterator, for <'a> &'a ROOT : IntoIterator, { - user: String, - repo : String, + repo : Repository, browse : TS, root : ROOT, + user_opt : Option, } #[get("/")] @@ -69,17 +82,20 @@ async fn hello_auth(req : HttpRequest) -> impl Responder { } } -#[get("/git/{user}/{repo}/{commit}/{path:.*}")] -async fn git_main(web::Path((user, reponame, commitname, rootname)): web::Path<(String, String, String, String)>) -> impl Responder { +#[get("/git/{owner}/{repo}/{commit}/{path:.*}")] +async fn git_main(web::Path((owner, reponame, commitname, rootname)): web::Path<(String, String, String, String)>) -> impl Responder { let repo = GitRepo::new(); - let path : Vec<(String, String)> = rootname.split("/").map_accum("/git/".to_string() + &user + "/" + &reponame + "/" + &commitname, |str_ref, b| { + let path : Vec<(String, String)> = rootname.split("/").map_accum("/git/".to_string() + &owner + "/" + &reponame + "/" + &commitname, |str_ref, b| { let href = b + "/" + str_ref; ((str_ref.to_string(), href.clone()), href) }).collect(); let commit = GitCommit::new(commitname); let root = GitBrowseDir::new(rootname); let browse = repo.browse(&commit, &root).await; - GitMainTemplate { user, repo : reponame, browse : browse, root : path} + let owner = Owner { name : owner}; + let repo = Repository {name : reponame, owner}; + let user = User { name : "Hubert".to_string()}; + GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)} } #[post("/echo")] diff --git a/templates/base.html b/templates/base.html index 5017baf..09a7fd2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,9 +3,31 @@ - {{repo}} + + {{repo.name}} +
+
+ Home + Link 1 + Link 2 + {% match user_opt %} + {% when Some with (user) %} +
+ +
+ Link 1 + Link 2 + Link 3 +
+
+ Log out + {% when None %} + Log in + {% endmatch %} +
{% block content %}{% endblock %} +
\ No newline at end of file diff --git a/templates/git.html b/templates/git.html index c9902e2..1c8ddf1 100644 --- a/templates/git.html +++ b/templates/git.html @@ -13,7 +13,7 @@

-

{{user}}/{{repo}}

+

{{repo.owner.name}}/{{repo.name}}