diff --git a/src/config_parser/mod.rs b/src/config_parser/mod.rs index 67c567f..11ce559 100644 --- a/src/config_parser/mod.rs +++ b/src/config_parser/mod.rs @@ -1 +1,2 @@ pub mod parser; +pub mod parser_models; diff --git a/src/config_parser/parser.rs b/src/config_parser/parser.rs index 6e9ab5b..226a760 100644 --- a/src/config_parser/parser.rs +++ b/src/config_parser/parser.rs @@ -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 diff --git a/src/config_parser/parser_models.rs b/src/config_parser/parser_models.rs new file mode 100644 index 0000000..f27e085 --- /dev/null +++ b/src/config_parser/parser_models.rs @@ -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 } + } +} diff --git a/src/lib.rs b/src/lib.rs index 25d093e..afa6a1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { let mut handlebars: Handlebars = Handlebars::new(); diff --git a/src/search_results_handler/aggregation_models.rs b/src/search_results_handler/aggregation_models.rs index bf6845f..2543b09 100644 --- a/src/search_results_handler/aggregation_models.rs +++ b/src/search_results_handler/aggregation_models.rs @@ -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() } diff --git a/websurfx/config.lua b/websurfx/config.lua index cc478b8..a841292 100644 --- a/websurfx/config.lua +++ b/websurfx/config.lua @@ -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