From 81ae20b5a0bca84166076d91b8b32a19d2d451ae Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Sat, 28 Dec 2019 23:58:14 +0100 Subject: Refactoring basic project structure --- src/main.rs | 89 +++++++++++-------------------------------------------------- 1 file changed, 15 insertions(+), 74 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 44588b2..77288a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,78 +1,19 @@ -use actix_files as fs; -use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Result}; -use askama::Template; - -/// Represents a repository on disk -struct Repository { - /// We need to be able to query libgit2 later - fs_path: String, - /// The project name (last path element) - name: String, - /// The rope path excluding the name - path: Vec, -} - -impl Repository { - /// Returns a list of commit hashes for a project - fn commits(&self) -> Vec { - vec!["f6ca929", "43fb776", "1a0fa2f".into()] - .into_iter() - .map(String::from) - .collect() - } - - /// Return the list of contributors - fn contributors(&self) -> Vec { - vec![ - "Katharina Fey ", - ] - .into_iter() - .map(String::from) - .collect() - } -} - -#[derive(Template)] -#[template(path = "repo.html")] -struct Repo<'a> { - project_owner: &'a str, - project_summary: &'a str, - project_name: &'a str, - project_logo: &'a str, - project_logo_alt_text: &'a str, - first_commit: &'a str, - num_commits: usize, - num_contributors: usize, -} - -fn repo(req: HttpRequest, path: web::Path<(String)>) -> Result { - println!("Rendering path: {:#?}", path); - dbg!(req); - - let repo = Repo { - project_owner: "spacekookie", - project_summary: "A lightweight web frontend for git repositories", - project_name: "webgit", - project_logo: "rust.png", - project_logo_alt_text: "Rust logo", - first_commit: "f6ca929", - num_commits: 123, - num_contributors: 3, - } - .render() - .unwrap(); - Ok(HttpResponse::Ok().content_type("text/html").body(repo)) -} +mod pages; +mod repo; fn main() -> std::io::Result<()> { + // use actix_files as fs; + // use actix_web::{web, App, HttpServer}; + // start http server - HttpServer::new(move || { - App::new() - .service(fs::Files::new("/static", "static")) - .service(web::resource("/{repo}").route(web::get().to(repo))) - }) - .bind("127.0.0.1:8080")? - .run() + // HttpServer::new(move || { + // App::new() + // .service(fs::Files::new("/static", "static")) + // .service(web::resource("/{repo}").route(web::get().to(pages::repo::render))) + // }) + // .bind("127.0.0.1:8080")? + // .run()?; + + //let r = repo::Repo::new("./test"); + Ok(()) } -- cgit v1.2.3