0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-24 15:08:22 -05:00

add missing documentation in config.lua and application source code

This commit is contained in:
neon_arch 2023-04-30 19:24:16 +03:00
parent 137c62ed5f
commit 4a505fb1d5
6 changed files with 50 additions and 18 deletions

View File

@ -1 +1,2 @@
pub mod parser;
pub mod parser_models;

View File

@ -1,22 +1,10 @@
//! This module provides the functionality to parse the lua config and convert the config options
//! into rust readable form.
use super::parser_models::Style;
use rlua::Lua;
use serde::Serialize;
use std::fs;
#[derive(Serialize, Clone)]
pub struct Style {
pub theme: String,
pub colorscheme: String,
}
impl Style {
pub fn new(theme: String, colorscheme: String) -> Self {
Style { theme, colorscheme }
}
}
/// A named struct which stores the parsed config file options.
///
/// # Fields

View File

@ -0,0 +1,35 @@
//! This module provides public models for handling, storing and serializing parsed config file
//! options from config.lua by grouping them togather.
use serde::Serialize;
/// A named struct which stores, serializes and groups the parsed config file options of theme and
/// colorscheme names into the Style struct which derives the `Clone` and `Serialize` traits
/// where the `Clone` trait is derived for allowing the struct to be cloned and passed to the
/// server as a shared data between all routes except `/robots.txt` and the `Serialize` trait
/// has been derived for allowing the object to be serialized so that it can be passed to
/// handlebars template files.
///
/// # Fields
//
/// * `theme` - It stores the parsed theme option used to set a theme for the website.
/// * `colorscheme` - It stores the parsed colorscheme option used to set a colorscheme for the
/// theme being used.
#[derive(Serialize, Clone)]
pub struct Style {
pub theme: String,
pub colorscheme: String,
}
impl Style {
/// Constructs a new `Style` with the given arguments needed for the struct.
///
/// # Arguments
///
/// * `theme` - It takes the parsed theme option used to set a theme for the website.
/// * `colorscheme` - It takes the parsed colorscheme option used to set a colorscheme
/// for the theme being used.
pub fn new(theme: String, colorscheme: String) -> Self {
Style { theme, colorscheme }
}
}

View File

@ -32,7 +32,7 @@ use handlebars::Handlebars;
/// use websurfx::run;
///
/// let listener = TcpListener::bind("127.0.0.1:8080").expect("Failed to bind address");
/// let server = run(listener).expect("Failed to start server");
/// let server = run(listener,config).expect("Failed to start server");
/// ```
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
let mut handlebars: Handlebars = Handlebars::new();

View File

@ -106,6 +106,11 @@ impl RawSearchResult {
self.engine.push(engine)
}
/// A function which returns the engine name stored from the struct as a string.
///
/// # Returns
///
/// An engine name stored as a string from the struct.
pub fn engine(self) -> String {
self.engine.get(0).unwrap().to_string()
}

View File

@ -1,4 +1,7 @@
port = "8080"
binding_ip_addr = "127.0.0.1"
colorscheme = "catppuccin-mocha"
theme = "simple"
-- Server
port = "8080" -- port on which server should be launched
binding_ip_addr = "127.0.0.1" --ip address on the which server should be launched.
-- Website
colorscheme = "catppuccin-mocha" -- the colorscheme name which should be used for the website theme
theme = "simple" -- the theme name which should be used for the website