-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert
.html
files into String
to execute as binary
Update docstrings and README.md
- Loading branch information
1 parent
ea466bd
commit 10f67a8
Showing
11 changed files
with
114 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,16 @@ | ||
use std::path::Path; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
/// Read the content of each file and return it as a String. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `filename` - Filename that has to be read. | ||
/// | ||
/// # Returns | ||
/// | ||
/// String representation of the file content. | ||
fn get_content(filename: &str) -> String { | ||
let filepath = Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.join("src") | ||
.join("templates") | ||
.join(format!("{}.html", filename)) | ||
.to_string_lossy() | ||
.to_string(); | ||
std::fs::read_to_string(filepath).unwrap_or_else(|_| String::new()) | ||
} | ||
use crate::templates; | ||
|
||
/// Reads all the HTML files in templates directory and loads the content into a Jinja Environment | ||
/// | ||
/// # Rendered files | ||
/// - Index page template that is served as HTML response for the root endpoint. | ||
/// - Landing page template that is served as HTML response while streaming videos. | ||
/// - Listing page template that is served as HTML response after successful authentication. | ||
/// - Logout page template that is served as HTML response when the user decides to end the session. | ||
/// - Session page template that is served as HTML response when invalid/expired session tokens are received. | ||
/// - Unauthorized page template that is served as HTML response after failed authentication. | ||
/// Loads all the HTML content into a Jinja Environment | ||
pub fn environment() -> Arc<Mutex<minijinja::Environment<'static>>> { | ||
let mut env = minijinja::Environment::new(); | ||
for html in ["index", "landing", "listing", "logout", "session", "unauthorized"] { | ||
let content = get_content(html); | ||
env.add_template_owned(html, content).unwrap(); | ||
} | ||
env.add_template_owned("index", templates::index::get_content()).unwrap(); | ||
env.add_template_owned("landing", templates::landing::get_content()).unwrap(); | ||
env.add_template_owned("listing", templates::listing::get_content()).unwrap(); | ||
env.add_template_owned("logout", templates::logout::get_content()).unwrap(); | ||
env.add_template_owned("session", templates::session::get_content()).unwrap(); | ||
env.add_template_owned("unauthorized", templates::unauthorized::get_content()).unwrap(); | ||
let mutex = Mutex::new(env.to_owned()); | ||
Arc::new(mutex) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// Index page template that is served as HTML response for the root endpoint. | ||
pub mod index; | ||
/// Landing page template that is served as HTML response while streaming videos. | ||
pub mod landing; | ||
/// Listing page template that is served as HTML response after successful authentication. | ||
pub mod listing; | ||
/// Logout page template that is served as HTML response when the user decides to end the session. | ||
pub mod logout; | ||
/// Session page template that is served as HTML response when invalid/expired session tokens are received. | ||
pub mod session; | ||
/// Unauthorized page template that is served as HTML response after failed authentication. | ||
pub mod unauthorized; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters