aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2019-12-28 23:58:14 +0100
committerKatharina Fey <kookie@spacekookie.de>2019-12-28 23:58:14 +0100
commit81ae20b5a0bca84166076d91b8b32a19d2d451ae (patch)
tree54de2fed2f08ff7f65eb709686f72d76bd34ad66 /src
parentbaf496acf0640fecdc01864989f2142a9757ba14 (diff)
Refactoring basic project structure
Diffstat (limited to 'src')
-rw-r--r--src/main.rs89
-rw-r--r--src/pages/mod.rs6
-rw-r--r--src/pages/repo.rs36
-rw-r--r--src/repo.rs45
4 files changed, 102 insertions, 74 deletions
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<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_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<HttpResponse> {
- 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(())
}
diff --git a/src/pages/mod.rs b/src/pages/mod.rs
new file mode 100644
index 0000000..9de9d47
--- /dev/null
+++ b/src/pages/mod.rs
@@ -0,0 +1,6 @@
+//! All the pages in webgit
+//!
+//! A page is defined by it's template type as well as it's route,
+//! which is exported from the module and then called by the router
+
+pub mod repo;
diff --git a/src/pages/repo.rs b/src/pages/repo.rs
new file mode 100644
index 0000000..aa66839
--- /dev/null
+++ b/src/pages/repo.rs
@@ -0,0 +1,36 @@
+//! The view that renders a repository
+
+use actix_web::{web, HttpRequest, HttpResponse, Result};
+use askama::Template;
+
+#[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,
+}
+
+pub fn render(req: HttpRequest, path: web::Path<(String)>) -> Result<HttpResponse> {
+ 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))
+}
diff --git a/src/repo.rs b/src/repo.rs
index e69de29..0056575 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -0,0 +1,45 @@
+use git2::Repository;
+
+
+// /// 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>,
+// }
+
+/// A structure that represents an existing bare repo on disk
+pub struct Repo {
+ pub inner: Repository,
+}
+
+impl Repo {
+ pub fn new(path: &'static str) -> Self {
+ Self {
+ inner: Repository::open_bare(path).unwrap(),
+ }
+ }
+
+ /// Returns a list of commit hashes for a project
+ pub 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()
+ }
+}