neon_arch
commited on
Commit
·
4a505fb
1
Parent(s):
137c62e
add missing documentation in config.lua and application source code
Browse files- src/config_parser/mod.rs +1 -0
- src/config_parser/parser.rs +1 -13
- src/config_parser/parser_models.rs +35 -0
- src/lib.rs +1 -1
- src/search_results_handler/aggregation_models.rs +5 -0
- websurfx/config.lua +7 -4
src/config_parser/mod.rs
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
pub mod parser;
|
|
|
|
|
|
| 1 |
pub mod parser;
|
| 2 |
+
pub mod parser_models;
|
src/config_parser/parser.rs
CHANGED
|
@@ -1,22 +1,10 @@
|
|
| 1 |
//! This module provides the functionality to parse the lua config and convert the config options
|
| 2 |
//! into rust readable form.
|
| 3 |
|
|
|
|
| 4 |
use rlua::Lua;
|
| 5 |
-
use serde::Serialize;
|
| 6 |
use std::fs;
|
| 7 |
|
| 8 |
-
#[derive(Serialize, Clone)]
|
| 9 |
-
pub struct Style {
|
| 10 |
-
pub theme: String,
|
| 11 |
-
pub colorscheme: String,
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
impl Style {
|
| 15 |
-
pub fn new(theme: String, colorscheme: String) -> Self {
|
| 16 |
-
Style { theme, colorscheme }
|
| 17 |
-
}
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
/// A named struct which stores the parsed config file options.
|
| 21 |
///
|
| 22 |
/// # Fields
|
|
|
|
| 1 |
//! This module provides the functionality to parse the lua config and convert the config options
|
| 2 |
//! into rust readable form.
|
| 3 |
|
| 4 |
+
use super::parser_models::Style;
|
| 5 |
use rlua::Lua;
|
|
|
|
| 6 |
use std::fs;
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
/// A named struct which stores the parsed config file options.
|
| 9 |
///
|
| 10 |
/// # Fields
|
src/config_parser/parser_models.rs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//! This module provides public models for handling, storing and serializing parsed config file
|
| 2 |
+
//! options from config.lua by grouping them togather.
|
| 3 |
+
|
| 4 |
+
use serde::Serialize;
|
| 5 |
+
|
| 6 |
+
/// A named struct which stores, serializes and groups the parsed config file options of theme and
|
| 7 |
+
/// colorscheme names into the Style struct which derives the `Clone` and `Serialize` traits
|
| 8 |
+
/// where the `Clone` trait is derived for allowing the struct to be cloned and passed to the
|
| 9 |
+
/// server as a shared data between all routes except `/robots.txt` and the `Serialize` trait
|
| 10 |
+
/// has been derived for allowing the object to be serialized so that it can be passed to
|
| 11 |
+
/// handlebars template files.
|
| 12 |
+
///
|
| 13 |
+
/// # Fields
|
| 14 |
+
//
|
| 15 |
+
/// * `theme` - It stores the parsed theme option used to set a theme for the website.
|
| 16 |
+
/// * `colorscheme` - It stores the parsed colorscheme option used to set a colorscheme for the
|
| 17 |
+
/// theme being used.
|
| 18 |
+
#[derive(Serialize, Clone)]
|
| 19 |
+
pub struct Style {
|
| 20 |
+
pub theme: String,
|
| 21 |
+
pub colorscheme: String,
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
impl Style {
|
| 25 |
+
/// Constructs a new `Style` with the given arguments needed for the struct.
|
| 26 |
+
///
|
| 27 |
+
/// # Arguments
|
| 28 |
+
///
|
| 29 |
+
/// * `theme` - It takes the parsed theme option used to set a theme for the website.
|
| 30 |
+
/// * `colorscheme` - It takes the parsed colorscheme option used to set a colorscheme
|
| 31 |
+
/// for the theme being used.
|
| 32 |
+
pub fn new(theme: String, colorscheme: String) -> Self {
|
| 33 |
+
Style { theme, colorscheme }
|
| 34 |
+
}
|
| 35 |
+
}
|
src/lib.rs
CHANGED
|
@@ -32,7 +32,7 @@ use handlebars::Handlebars;
|
|
| 32 |
/// use websurfx::run;
|
| 33 |
///
|
| 34 |
/// let listener = TcpListener::bind("127.0.0.1:8080").expect("Failed to bind address");
|
| 35 |
-
/// let server = run(listener).expect("Failed to start server");
|
| 36 |
/// ```
|
| 37 |
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
|
| 38 |
let mut handlebars: Handlebars = Handlebars::new();
|
|
|
|
| 32 |
/// use websurfx::run;
|
| 33 |
///
|
| 34 |
/// let listener = TcpListener::bind("127.0.0.1:8080").expect("Failed to bind address");
|
| 35 |
+
/// let server = run(listener,config).expect("Failed to start server");
|
| 36 |
/// ```
|
| 37 |
pub fn run(listener: TcpListener, config: Config) -> std::io::Result<Server> {
|
| 38 |
let mut handlebars: Handlebars = Handlebars::new();
|
src/search_results_handler/aggregation_models.rs
CHANGED
|
@@ -106,6 +106,11 @@ impl RawSearchResult {
|
|
| 106 |
self.engine.push(engine)
|
| 107 |
}
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
pub fn engine(self) -> String {
|
| 110 |
self.engine.get(0).unwrap().to_string()
|
| 111 |
}
|
|
|
|
| 106 |
self.engine.push(engine)
|
| 107 |
}
|
| 108 |
|
| 109 |
+
/// A function which returns the engine name stored from the struct as a string.
|
| 110 |
+
///
|
| 111 |
+
/// # Returns
|
| 112 |
+
///
|
| 113 |
+
/// An engine name stored as a string from the struct.
|
| 114 |
pub fn engine(self) -> String {
|
| 115 |
self.engine.get(0).unwrap().to_string()
|
| 116 |
}
|
websurfx/config.lua
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- Server
|
| 2 |
+
port = "8080" -- port on which server should be launched
|
| 3 |
+
binding_ip_addr = "127.0.0.1" --ip address on the which server should be launched.
|
| 4 |
+
|
| 5 |
+
-- Website
|
| 6 |
+
colorscheme = "catppuccin-mocha" -- the colorscheme name which should be used for the website theme
|
| 7 |
+
theme = "simple" -- the theme name which should be used for the website
|