aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2019-12-10 16:52:14 +0100
committerKatharina Fey <kookie@spacekookie.de>2019-12-10 16:52:14 +0100
commita7851bb2a8583773fed590b34191715b7ec2d713 (patch)
treebbcc27102c549f3ea4ce4dcf2984e4fc56435a8c /src
Initial code dump of Rust and templates
Diffstat (limited to 'src')
-rw-r--r--src/main.rs70
-rw-r--r--src/repo.rs0
2 files changed, 70 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..d516d66
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,70 @@
+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<String>,
+}
+
+impl Repository {
+ /// Returns a list of commit hashes for a project
+ fn commits(&self) -> Vec<String> {
+ vec!["f6ca929", "43fb776", "1a0fa2f".into()]
+ .into_iter()
+ .map(String::from)
+ .collect()
+ }
+
+ /// Return the list of contributors
+ fn contributors(&self) -> Vec<String> {
+ vec![
+ "Katharina Fey <kookie@spacekookie.de",
+ "Robin Example <robin@example.com",
+ "Ferris <ferris@the.crab>",
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect()
+ }
+}
+
+#[derive(Template)]
+#[template(path = "repo.html")]
+struct Repo<'a> {
+ project_name: &'a str,
+ first_commit: &'a str,
+ num_commits: usize,
+ num_contributors: usize,
+}
+
+fn repo(req: HttpRequest, path: web::Path<(String)>) -> Result<HttpResponse> {
+ println!("Rendering path: {:#?}", path);
+ dbg!(req);
+
+ let repo = Repo {
+ project_name: "webgit",
+ first_commit: "f6ca929",
+ num_commits: 123,
+ num_contributors: 3,
+ }
+ .render()
+ .unwrap();
+ Ok(HttpResponse::Ok().content_type("text/html").body(repo))
+}
+
+fn main() -> std::io::Result<()> {
+ // 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()
+}
diff --git a/src/repo.rs b/src/repo.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/repo.rs