summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-08-01 14:21:14 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-08-01 14:21:15 +0200
commit674e8ec8eeef2436745aa085f92b98d66b82f160 (patch)
tree5af34b5993b67587fd39311fa8bf567dbc60cd19
parent137ec35a5be2df3d9e0f6566752c03d622c5e91e (diff)
Fix imports, module pathes, etc
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/main.rs13
-rw-r--r--src/model/stat.rs3
-rw-r--r--src/routes/branch.rs8
-rw-r--r--src/routes/mod.rs4
-rw-r--r--src/routes/repo.rs8
-rw-r--r--src/routes/tree.rs22
-rw-r--r--src/view/blob.rs4
-rw-r--r--src/view/branch.rs4
-rw-r--r--src/view/data.rs5
-rw-r--r--src/view/mod.rs20
-rw-r--r--src/view/repos.rs2
-rw-r--r--src/view/tree.rs4
12 files changed, 49 insertions, 48 deletions
diff --git a/src/main.rs b/src/main.rs
index 97d7c7b..e2e0254 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,12 +13,11 @@ use actix_web::middleware::Logger;
use resiter::Map;
mod cli;
-mod highlight;
-mod repository;
+mod controller;
+mod helpers;
+mod model;
mod routes;
-mod state;
mod view;
-mod tree;
#[actix_web::main]
async fn main() {
@@ -39,19 +38,19 @@ async fn app() -> Result<()> {
.values_of("repo")
.unwrap() // safe by clap, we have at least one
.into_iter()
- .map(crate::state::RepoState::open_repo)
+ .map(crate::model::state::RepoState::open_repo)
.map_ok(|repostate| {
(repostate.name().clone(), Arc::new(Mutex::new(repostate)))
})
.collect::<Result<_>>()?;
- let handlebars = crate::templates::setup_handlebars()?;
+ let handlebars = crate::view::setup_handlebars()?;
let theme_path = cli.value_of("theme").unwrap(); // safe
let theme = syntect::highlighting::ThemeSet::get_theme(theme_path)
.context("Loading theme")?;
- let app_state = crate::state::AppState::builder()
+ let app_state = crate::model::state::AppState::builder()
.default_branch_name(default_branch_name.to_string()) // fixme: No alloc
.repos(repos)
.handlebars(handlebars)
diff --git a/src/model/stat.rs b/src/model/stat.rs
index 29be7d5..87e6961 100644
--- a/src/model/stat.rs
+++ b/src/model/stat.rs
@@ -11,7 +11,8 @@ use cached::proc_macro::cached;
use either::Either;
use git2::Tree;
-use crate::state::RepoState;
+use crate::model::state::RepoState;
+
#[derive(Clone)]
pub struct RepositoryStat {
pub branches: Vec<String>,
diff --git a/src/routes/branch.rs b/src/routes/branch.rs
index 2932758..73ac1fd 100644
--- a/src/routes/branch.rs
+++ b/src/routes/branch.rs
@@ -3,10 +3,10 @@ use std::sync::Arc;
use actix_web::HttpResponse;
use actix_web::web;
-use crate::repository::get_repository_stat;
+use crate::model::stat::get_repository_stat;
use crate::routes::error::RepositoryError;
-pub async fn branch<'a>(web::Path((repo_name, branch_name)): web::Path<(String, String)>, data: web::Data<Arc<crate::state::AppState<'a>>>) -> Result<HttpResponse, RepositoryError> {
+pub async fn branch<'a>(web::Path((repo_name, branch_name)): web::Path<(String, String)>, data: web::Data<Arc<crate::model::state::AppState<'a>>>) -> Result<HttpResponse, RepositoryError> {
let repo_state = data.repos()
.get(&repo_name)
.ok_or_else(|| RepositoryError::RepoNotFound)?;
@@ -24,11 +24,11 @@ pub async fn branch<'a>(web::Path((repo_name, branch_name)): web::Path<(String,
.peel_to_tree()
.map_err(|_| crate::routes::error::RepositoryError::Str("Peeling to tree errored".to_string()))?;
- let tree_elements = crate::tree::load_tree_elements(&repo, &tree)
+ let tree_elements = crate::controller::sidebar::load_tree_elements(&repo, &tree)
.map_err(|_| crate::routes::error::RepositoryError::Str("Loading tree errored".to_string()))?;
log::info!("Rendering: {} for branch {}", repo_name, branch_name);
- crate::templates::branch::render(data.handlebars(), crate::templates::branch::Data {
+ crate::view::branch::render(data.handlebars(), crate::view::branch::Data {
name: &repo_name,
branch_names: &repo_stat.branches,
tag_names: &repo_stat.tags,
diff --git a/src/routes/mod.rs b/src/routes/mod.rs
index 0945a6c..10f0607 100644
--- a/src/routes/mod.rs
+++ b/src/routes/mod.rs
@@ -17,13 +17,13 @@ pub use tree::*;
use crate::routes::error::RepositoryError;
-pub async fn landing_page<'a>(data: web::Data<Arc<crate::state::AppState<'a>>>) -> impl Responder {
+pub async fn landing_page<'a>(data: web::Data<Arc<crate::model::state::AppState<'a>>>) -> impl Responder {
let repo_names = data.repos()
.keys()
.map(String::as_ref)
.collect::<Vec<_>>();
- crate::templates::repos::render(data.handlebars(), crate::templates::repos::Data {
+ crate::view::repos::render(data.handlebars(), crate::view::repos::Data {
repo_names: &repo_names
})
.map(|body| HttpResponse::Ok().body(body))
diff --git a/src/routes/repo.rs b/src/routes/repo.rs
index 6fa5896..52a0b50 100644
--- a/src/routes/repo.rs
+++ b/src/routes/repo.rs
@@ -3,10 +3,10 @@ use std::sync::Arc;
use actix_web::HttpResponse;
use actix_web::web;
-use crate::repository::get_repository_stat;
+use crate::model::stat::get_repository_stat;
use crate::routes::error::RepositoryError;
-pub async fn repo_index<'a>(web::Path(repo_name): web::Path<String>, data: web::Data<Arc<crate::state::AppState<'a>>>) -> Result<HttpResponse, RepositoryError> {
+pub async fn repo_index<'a>(web::Path(repo_name): web::Path<String>, data: web::Data<Arc<crate::model::state::AppState<'a>>>) -> Result<HttpResponse, RepositoryError> {
let repo_state = data.repos()
.get(&repo_name)
.ok_or_else(|| RepositoryError::RepoNotFound)?;
@@ -24,12 +24,12 @@ pub async fn repo_index<'a>(web::Path(repo_name): web::Path<String>, data: web::
.peel_to_tree()
.map_err(|_| crate::routes::error::RepositoryError::Str("Peeling to tree errored".to_string()))?;
- let tree_elements = crate::tree::load_tree_elements(&repo, &tree)
+ let tree_elements = crate::controller::sidebar::load_tree_elements(&repo, &tree)
.map_err(|_| crate::routes::error::RepositoryError::Str("Loading tree errored".to_string()))?;
log::info!("Rendering: {} for branch {}", repo_name, default_branch_name);
- crate::templates::branch::render(data.handlebars(), crate::templates::branch::Data {
+ crate::view::branch::render(data.handlebars(), crate::view::branch::Data {
name: &repo_name,
branch_names: &repo_stat.branches,
tag_names: &repo_stat.tags,
diff --git a/src/routes/tree.rs b/src/routes/tree.rs
index f327eff..c3dfacb 100644
--- a/src/routes/tree.rs
+++ b/src/routes/tree.rs
@@ -3,10 +3,10 @@ use std::sync::Arc;
use actix_web::HttpResponse;
use actix_web::web;
-use crate::repository::get_repository_stat;
+use crate::model::stat::get_repository_stat;
use crate::routes::error::RepositoryError;
-pub async fn tree<'a>(web::Path((repo_name, branch_name, tree_path)): web::Path<(String, String, String)>, data: web::Data<Arc<crate::state::AppState<'a>>>) -> Result<HttpResponse, RepositoryError> {
+pub async fn tree<'a>(web::Path((repo_name, branch_name, tree_path)): web::Path<(String, String, String)>, data: web::Data<Arc<crate::model::state::AppState<'a>>>) -> Result<HttpResponse, RepositoryError> {
log::debug!("Handler for tree: {}/{}/{}", repo_name, branch_name, tree_path);
let repo_state = data.repos()
.get(&repo_name)
@@ -27,7 +27,7 @@ pub async fn tree<'a>(web::Path((repo_name, branch_name, tree_path)): web::Path<
.peel_to_tree()
.map_err(|e| crate::routes::error::RepositoryError::Str(e.to_string()))?;
- let tree_object = crate::tree::load_tree_at(repo_lock.repo(), &root, &tree_path)
+ let tree_object = crate::controller::tree::load_tree_at(repo_lock.repo(), &root, &tree_path)
.map_err(|e| RepositoryError::Str(e.to_string()))?;
let tree_object = match tree_object {
@@ -38,22 +38,22 @@ pub async fn tree<'a>(web::Path((repo_name, branch_name, tree_path)): web::Path<
Some(to) => to,
};
- let tree_elements = crate::tree::load_tree_elements(repo_lock.repo(), &root)
+ let tree_elements = crate::controller::sidebar::load_tree_elements(repo_lock.repo(), &root)
.map_err(|_| crate::routes::error::RepositoryError::Str("Loading tree errored".to_string()))?;
match tree_object.content {
- crate::tree::TreeObjectContent::File { size, content, is_binary } => {
+ crate::controller::tree::TreeObjectContent::File { size, content, is_binary } => {
log::debug!("Rendering File with");
- let content = crate::highlight::highlight(&content, data.theme())
+ let content = crate::helpers::highlight::highlight(&content, data.theme())
.map_err(|e| RepositoryError::Str(e.to_string()))?;
let content = content.value
.lines()
.map(String::from)
.enumerate()
- .map(crate::templates::blob::Line::from)
+ .map(crate::view::blob::Line::from)
.collect();
- crate::templates::blob::render(data.handlebars(), crate::templates::blob::Data {
+ crate::view::blob::render(data.handlebars(), crate::view::blob::Data {
name: &repo_name,
branch_names: &repo_stat.branches,
tag_names: &repo_stat.tags,
@@ -68,18 +68,18 @@ pub async fn tree<'a>(web::Path((repo_name, branch_name, tree_path)): web::Path<
.map_err(RepositoryError::from)
},
- crate::tree::TreeObjectContent::Dir { content } => {
+ crate::controller::tree::TreeObjectContent::Dir { content } => {
log::debug!("Rendering directory with: {:?}", content);
let content = content.into_iter()
.map(|tree_object_meta| {
- crate::templates::tree::TreeElement {
+ crate::view::tree::TreeElement {
is_dir: tree_object_meta.is_dir,
name: tree_object_meta.name,
}
})
.collect();
- crate::templates::tree::render(data.handlebars(), crate::templates::tree::Data {
+ crate::view::tree::render(data.handlebars(), crate::view::tree::Data {
name: &repo_name,
branch_names: &repo_stat.branches,
tag_names: &repo_stat.tags,
diff --git a/src/view/blob.rs b/src/view/blob.rs
index c63f9e6..553e3ce 100644
--- a/src/view/blob.rs
+++ b/src/view/blob.rs
@@ -7,7 +7,7 @@ pub struct Data<'a> {
pub tag_names: &'a [String],
pub branch_name: &'a str,
- pub tree_elements: &'a [crate::tree::TreeElement],
+ pub tree_elements: &'a [crate::controller::sidebar::TreeElement],
pub size: usize,
pub is_binary: bool,
@@ -29,6 +29,6 @@ impl From<(usize, String)> for Line {
pub fn render<'a, 'r>(hb: &handlebars::Handlebars<'r>, data: Data<'a>) -> Result<String, handlebars::RenderError> {
log::debug!("Rendering repo {}, branch {}", data.name, data.branch_name);
log::trace!("Rendering with tree data: {:#?}", data);
- hb.render(self::NAME, &super::RenderData { parent: "base", data })
+ hb.render(self::NAME, &super::data::RenderData { parent: "base", data })
}
diff --git a/src/view/branch.rs b/src/view/branch.rs
index ccfe8e1..1913a40 100644
--- a/src/view/branch.rs
+++ b/src/view/branch.rs
@@ -7,12 +7,12 @@ pub struct Data<'a> {
pub tag_names: &'a [String],
pub branch_name: &'a str,
- pub tree_elements: &'a [crate::tree::TreeElement],
+ pub tree_elements: &'a [crate::controller::sidebar::TreeElement],
}
pub fn render<'a, 'r>(hb: &handlebars::Handlebars<'r>, data: Data<'a>) -> Result<String, handlebars::RenderError> {
log::debug!("Rendering repo {}, branch {}", data.name, data.branch_name);
log::trace!("Rendering with tree data: {:#?}", data.tree_elements);
- hb.render(self::NAME, &super::RenderData { parent: "base", data })
+ hb.render(self::NAME, &super::data::RenderData { parent: "base", data })
}
diff --git a/src/view/data.rs b/src/view/data.rs
index 9aea4d1..72e9272 100644
--- a/src/view/data.rs
+++ b/src/view/data.rs
@@ -1,8 +1,7 @@
/// Helper struct for having a required parent in the rendered data
#[derive(serde::Serialize)]
pub struct RenderData<T: serde::Serialize> {
- parent: &'static str,
-
- data: T,
+ pub parent: &'static str,
+ pub data: T,
}
diff --git a/src/view/mod.rs b/src/view/mod.rs
index 3084867..8efbc3e 100644
--- a/src/view/mod.rs
+++ b/src/view/mod.rs
@@ -1,23 +1,25 @@
pub mod blob;
+pub mod base;
pub mod branch;
pub mod data;
pub mod partials;
pub mod repos;
+pub mod tree;
pub fn setup_handlebars<'r>() -> anyhow::Result<handlebars::Handlebars<'r>> {
let mut hb = handlebars::Handlebars::new();
hb.set_strict_mode(true);
- hb.register_partial(crate::templates::partials::branchlist::NAME, std::include_str!("../templates/partials/branchlist.template"))?;
- hb.register_partial(crate::templates::partials::sidebar::NAME, std::include_str!("../templates/partials/sidebar.template"))?;
- hb.register_partial(crate::templates::partials::taglist::NAME, std::include_str!("../templates/partials/taglist.template"))?;
- hb.register_partial(crate::templates::partials::tree::NAME, std::include_str!("../templates/partials/tree.template"))?;
+ hb.register_partial(self::partials::branchlist::NAME, std::include_str!("../../templates/partials/branchlist.template"))?;
+ hb.register_partial(self::partials::sidebar::NAME, std::include_str!("../../templates/partials/sidebar.template"))?;
+ hb.register_partial(self::partials::taglist::NAME, std::include_str!("../../templates/partials/taglist.template"))?;
+ hb.register_partial(self::partials::tree::NAME, std::include_str!("../../templates/partials/tree.template"))?;
- hb.register_template_string(crate::templates::base::NAME, std::include_str!("../templates/base.template"))?;
- hb.register_template_string(crate::templates::repos::NAME, std::include_str!("../templates/repos.template"))?;
- hb.register_template_string(crate::templates::branch::NAME, std::include_str!("../templates/branch.template"))?;
- hb.register_template_string(crate::templates::blob::NAME, std::include_str!("../templates/blob.template"))?;
- hb.register_template_string(crate::templates::tree::NAME, std::include_str!("../templates/tree.template"))?;
+ hb.register_template_string(self::base::NAME, std::include_str!("../../templates/base.template"))?;
+ hb.register_template_string(self::repos::NAME, std::include_str!("../../templates/repos.template"))?;
+ hb.register_template_string(self::branch::NAME, std::include_str!("../../templates/branch.template"))?;
+ hb.register_template_string(self::blob::NAME, std::include_str!("../../templates/blob.template"))?;
+ hb.register_template_string(self::tree::NAME, std::include_str!("../../templates/tree.template"))?;
Ok(hb)
}
diff --git a/src/view/repos.rs b/src/view/repos.rs
index 555811c..235a73f 100644
--- a/src/view/repos.rs
+++ b/src/view/repos.rs
@@ -7,6 +7,6 @@ pub struct Data<'a> {
pub fn render<'a, 'r>(hb: &handlebars::Handlebars<'r>, data: Data<'a>) -> Result<String, handlebars::RenderError> {
log::debug!("Rendering repos: {:?}", data.repo_names.join(", "));
- hb.render(self::NAME, &super::RenderData { parent: "base", data })
+ hb.render(self::NAME, &super::data::RenderData { parent: "base", data })
}
diff --git a/src/view/tree.rs b/src/view/tree.rs
index 2e87d90..a40703e 100644
--- a/src/view/tree.rs
+++ b/src/view/tree.rs
@@ -7,7 +7,7 @@ pub struct Data<'a> {
pub tag_names: &'a [String],
pub branch_name: &'a str,
- pub tree_elements: &'a [crate::tree::TreeElement],
+ pub tree_elements: &'a [crate::controller::sidebar::TreeElement],
pub content: Vec<TreeElement>,
}
@@ -21,6 +21,6 @@ pub struct TreeElement {
pub fn render<'a, 'r>(hb: &handlebars::Handlebars<'r>, data: Data<'a>) -> Result<String, handlebars::RenderError> {
log::debug!("Rendering repo {}, branch {}", data.name, data.branch_name);
log::trace!("Rendering with tree data: {:#?}", data);
- hb.render(self::NAME, &super::RenderData { parent: "base", data })
+ hb.render(self::NAME, &super::data::RenderData { parent: "base", data })
}