neon_arch commited on
Commit
c1a5b70
β€’
1 Parent(s): 38ba4bd

πŸ’‘ chore: add documentation to the code (#302)

Browse files
src/templates/mod.rs CHANGED
@@ -1,4 +1,5 @@
1
- //!
 
2
 
3
  mod partials;
4
  pub mod views;
 
1
+ //! This module provides other modules to handle both the view and its partials for the `websurfx`
2
+ //! search engine frontend.
3
 
4
  mod partials;
5
  pub mod views;
src/templates/partials/bar.rs CHANGED
@@ -1,8 +1,17 @@
1
- //!
2
 
3
- use maud::{html, Markup,PreEscaped};
4
 
 
 
5
  ///
 
 
 
 
 
 
 
6
  pub fn bar(query: &str) -> Markup {
7
  html!(
8
  (PreEscaped("<div class=\"search_bar\">"))
 
1
+ //! A module that handles `bar` partial for the `search_bar` partial and the home/index/main page in the `websurfx` frontend.
2
 
3
+ use maud::{html, Markup, PreEscaped};
4
 
5
+ /// A functions that handles the html code for the bar for the `search_bar` partial and the
6
+ /// home/index/main page in the search engine frontend.
7
  ///
8
+ /// # Arguments
9
+ ///
10
+ /// * `query` - It takes the current search query provided by user as an argument.
11
+ ///
12
+ /// # Returns
13
+ ///
14
+ /// It returns the compiled html code for the search bar as a result.
15
  pub fn bar(query: &str) -> Markup {
16
  html!(
17
  (PreEscaped("<div class=\"search_bar\">"))
src/templates/partials/footer.rs CHANGED
@@ -1,8 +1,13 @@
1
- //!
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
 
 
5
  ///
 
 
 
6
  pub fn footer() -> Markup {
7
  html!(
8
  footer{
 
1
+ //! A module that handles the footer for all the pages in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
5
+ /// A functions that handles the html code for the footer for all the pages in the search engine
6
+ /// frontend.
7
  ///
8
+ /// # Returns
9
+ ///
10
+ /// It returns the compiled html code for the footer as a result.
11
  pub fn footer() -> Markup {
12
  html!(
13
  footer{
src/templates/partials/header.rs CHANGED
@@ -1,9 +1,18 @@
1
- //!
2
 
3
  use crate::templates::partials::navbar::navbar;
4
  use maud::{html, Markup, PreEscaped, DOCTYPE};
5
 
 
6
  ///
 
 
 
 
 
 
 
 
7
  pub fn header(colorscheme: &str, theme: &str) -> Markup {
8
  html!(
9
  (DOCTYPE)
 
1
+ //! A module that handles the header for all the pages in the `websurfx` frontend.
2
 
3
  use crate::templates::partials::navbar::navbar;
4
  use maud::{html, Markup, PreEscaped, DOCTYPE};
5
 
6
+ /// A function that handles the html code for the header for all the pages in the search engine frontend.
7
  ///
8
+ /// # Arguments
9
+ ///
10
+ /// * `colorscheme` - It takes the colorscheme name as an argument.
11
+ /// * `theme` - It takes the theme name as an argument.
12
+ ///
13
+ /// # Returns
14
+ ///
15
+ /// It returns the compiled html markup code for the header as a result.
16
  pub fn header(colorscheme: &str, theme: &str) -> Markup {
17
  html!(
18
  (DOCTYPE)
src/templates/partials/mod.rs CHANGED
@@ -1,8 +1,8 @@
1
- //!
2
 
 
3
  pub mod footer;
4
  pub mod header;
5
  pub mod navbar;
6
- pub mod bar;
7
- pub mod settings_tabs;
8
  pub mod search_bar;
 
 
1
+ //! This module provides other modules to handle the partials for the views in the `websurfx` frontend.
2
 
3
+ pub mod bar;
4
  pub mod footer;
5
  pub mod header;
6
  pub mod navbar;
 
 
7
  pub mod search_bar;
8
+ pub mod settings_tabs;
src/templates/partials/navbar.rs CHANGED
@@ -1,8 +1,12 @@
1
- //!
2
 
3
  use maud::{html, Markup};
4
 
 
5
  ///
 
 
 
6
  pub fn navbar() -> Markup {
7
  html!(
8
  nav{
 
1
+ //! A module that handles `navbar` partial for the header partial in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup};
4
 
5
+ /// A functions that handles the html code for the header partial.
6
  ///
7
+ /// # Returns
8
+ ///
9
+ /// It returns the compiled html code for the navbar as a result.
10
  pub fn navbar() -> Markup {
11
  html!(
12
  nav{
src/templates/partials/search_bar.rs CHANGED
@@ -1,12 +1,24 @@
1
- //!
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
5
  use crate::{models::aggregation_models::EngineErrorInfo, templates::partials::bar::bar};
6
 
 
7
  const SAFE_SEARCH_LEVELS_NAME: [&str; 3] = ["None", "Low", "Moderate"];
8
 
 
9
  ///
 
 
 
 
 
 
 
 
 
 
10
  pub fn search_bar(
11
  engine_errors_info: &[EngineErrorInfo],
12
  safe_search_level: u8,
 
1
+ //! A module that handles `search bar` partial for the search page in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
5
  use crate::{models::aggregation_models::EngineErrorInfo, templates::partials::bar::bar};
6
 
7
+ /// A constant holding the named safe search level options for the corresponding values 0, 1 and 2.
8
  const SAFE_SEARCH_LEVELS_NAME: [&str; 3] = ["None", "Low", "Moderate"];
9
 
10
+ /// A functions that handles the html code for the search bar for the search page.
11
  ///
12
+ /// # Arguments
13
+ ///
14
+ /// * `engine_errors_info` - It takes the engine errors list containing errors for each upstream
15
+ /// search engine which failed to provide results as an argument.
16
+ /// * `safe_search_level` - It takes the safe search level with values from 0-2 as an argument.
17
+ /// * `query` - It takes the current search query provided by user as an argument.
18
+ ///
19
+ /// # Returns
20
+ ///
21
+ /// It returns the compiled html code for the search bar as a result.
22
  pub fn search_bar(
23
  engine_errors_info: &[EngineErrorInfo],
24
  safe_search_level: u8,
src/templates/partials/settings_tabs/cookies.rs CHANGED
@@ -1,8 +1,12 @@
1
- //!
2
 
3
  use maud::{html, Markup};
4
 
 
5
  ///
 
 
 
6
  pub fn cookies() -> Markup {
7
  html!(
8
  div class="cookies tab"{
 
1
+ //! A module that handles the engines tab for setting page view in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup};
4
 
5
+ /// A functions that handles the html code for the cookies tab for the settings page for the search page.
6
  ///
7
+ /// # Returns
8
+ ///
9
+ /// It returns the compiled html markup code for the cookies tab.
10
  pub fn cookies() -> Markup {
11
  html!(
12
  div class="cookies tab"{
src/templates/partials/settings_tabs/engines.rs CHANGED
@@ -1,8 +1,16 @@
1
- //!
2
 
3
  use maud::{html, Markup};
4
 
 
5
  ///
 
 
 
 
 
 
 
6
  pub fn engines(engine_names: &[&String]) -> Markup {
7
  html!(
8
  div class="engines tab"{
 
1
+ //! A module that handles the engines tab for setting page view in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup};
4
 
5
+ /// A functions that handles the html code for the engines tab for the settings page for the search page.
6
  ///
7
+ /// # Arguments
8
+ ///
9
+ /// * `engine_names` - It takes the list of all available engine names as an argument.
10
+ ///
11
+ /// # Returns
12
+ ///
13
+ /// It returns the compiled html markup code for the engines tab.
14
  pub fn engines(engine_names: &[&String]) -> Markup {
15
  html!(
16
  div class="engines tab"{
src/templates/partials/settings_tabs/general.rs CHANGED
@@ -1,10 +1,15 @@
1
- //!
2
 
3
  use maud::{html, Markup};
4
 
5
- const SAFE_SEARCH_LEVELS: [(u8, &'static str); 3] = [(0, "None"), (1, "Low"), (2, "Moderate")];
 
6
 
 
7
  ///
 
 
 
8
  pub fn general() -> Markup {
9
  html!(
10
  div class="general tab active"{
 
1
+ //! A module that handles the general tab for setting page view in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup};
4
 
5
+ /// A constant holding the named safe search level options for the corresponding values 0, 1 and 2.
6
+ const SAFE_SEARCH_LEVELS: [(u8, &str); 3] = [(0, "None"), (1, "Low"), (2, "Moderate")];
7
 
8
+ /// A functions that handles the html code for the general tab for the settings page for the search page.
9
  ///
10
+ /// # Returns
11
+ ///
12
+ /// It returns the compiled html markup code for the general tab.
13
  pub fn general() -> Markup {
14
  html!(
15
  div class="general tab active"{
src/templates/partials/settings_tabs/mod.rs CHANGED
@@ -1,6 +1,7 @@
1
- //!
 
2
 
3
- pub mod general;
4
- pub mod engines;
5
  pub mod cookies;
 
 
6
  pub mod user_interface;
 
1
+ //! This module provides other modules to handle the partials for the tabs for the settings page
2
+ //! view in the `websurfx` frontend.
3
 
 
 
4
  pub mod cookies;
5
+ pub mod engines;
6
+ pub mod general;
7
  pub mod user_interface;
src/templates/partials/settings_tabs/user_interface.rs CHANGED
@@ -1,9 +1,21 @@
1
- //!
2
 
3
  use crate::handler::paths::{file_path, FileType};
4
  use maud::{html, Markup};
5
  use std::fs::read_dir;
6
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  fn style_option_list(
8
  style_type: &str,
9
  ) -> Result<Vec<(String, String)>, Box<dyn std::error::Error + '_>> {
@@ -14,13 +26,18 @@ fn style_option_list(
14
  style_type,
15
  ))? {
16
  let style_name = file?.file_name().to_str().unwrap().replace(".css", "");
17
- style_option_names.push((style_name.clone(), style_name.replace("-", " ")));
18
  }
19
 
20
  Ok(style_option_names)
21
  }
22
 
 
 
 
23
  ///
 
 
24
  pub fn user_interface() -> Result<Markup, Box<dyn std::error::Error>> {
25
  Ok(html!(
26
  div class="user_interface tab"{
 
1
+ //! A module that handles the user interface tab for setting page view in the `websurfx` frontend.
2
 
3
  use crate::handler::paths::{file_path, FileType};
4
  use maud::{html, Markup};
5
  use std::fs::read_dir;
6
 
7
+ /// A helper function that helps in building the list of all available colorscheme/theme names
8
+ /// present in the colorschemes and themes folder respectively.
9
+ ///
10
+ /// # Arguments
11
+ ///
12
+ /// * `style_type` - It takes the style type of the values `theme` and `colorscheme` as an
13
+ /// argument.
14
+ ///
15
+ /// # Error
16
+ ///
17
+ /// Returns a list of colorscheme/theme names as a vector of tuple strings on success otherwise
18
+ /// returns a standard error message.
19
  fn style_option_list(
20
  style_type: &str,
21
  ) -> Result<Vec<(String, String)>, Box<dyn std::error::Error + '_>> {
 
26
  style_type,
27
  ))? {
28
  let style_name = file?.file_name().to_str().unwrap().replace(".css", "");
29
+ style_option_names.push((style_name.clone(), style_name.replace('-', " ")));
30
  }
31
 
32
  Ok(style_option_names)
33
  }
34
 
35
+ /// A functions that handles the html code for the user interface tab for the settings page for the search page.
36
+ ///
37
+ /// # Error
38
  ///
39
+ /// It returns the compiled html markup code for the user interface tab on success otherwise
40
+ /// returns a standard error message.
41
  pub fn user_interface() -> Result<Markup, Box<dyn std::error::Error>> {
42
  Ok(html!(
43
  div class="user_interface tab"{
src/templates/views/about.rs CHANGED
@@ -1,10 +1,19 @@
1
- //!
2
 
3
  use maud::{html, Markup};
4
 
5
  use crate::templates::partials::{footer::footer, header::header};
6
 
 
7
  ///
 
 
 
 
 
 
 
 
8
  pub fn about(colorscheme: &str, theme: &str) -> Markup {
9
  html!(
10
  (header(colorscheme, theme))
 
1
+ //! A module that handles the view for the about page in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup};
4
 
5
  use crate::templates::partials::{footer::footer, header::header};
6
 
7
+ /// A function that handles the html code for the about page view in the search engine frontend.
8
  ///
9
+ /// # Arguments
10
+ ///
11
+ /// * `colorscheme` - It takes the colorscheme name as an argument.
12
+ /// * `theme` - It takes the theme name as an argument.
13
+ ///
14
+ /// # Returns
15
+ ///
16
+ /// It returns the compiled html markup code as a result.
17
  pub fn about(colorscheme: &str, theme: &str) -> Markup {
18
  html!(
19
  (header(colorscheme, theme))
src/templates/views/index.rs CHANGED
@@ -1,16 +1,25 @@
1
- //!
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
5
  use crate::templates::partials::{bar::bar, footer::footer, header::header};
6
 
 
7
  ///
8
- pub fn index(colorscheme: &str, theme: &str, query: &str) -> Markup {
 
 
 
 
 
 
 
 
9
  html!(
10
  (header(colorscheme, theme))
11
  main class="search-container"{
12
  img src="../images/websurfx_logo.png" alt="Websurfx meta-search engine logo";
13
- (bar(query))
14
  (PreEscaped("</div>"))
15
  }
16
  script src="static/index.js"{}
 
1
+ //! A module that handles the view for the index/home/main page in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
5
  use crate::templates::partials::{bar::bar, footer::footer, header::header};
6
 
7
+ /// A function that handles the html code for the index/html/main page view in the search engine frontend.
8
  ///
9
+ /// # Arguments
10
+ ///
11
+ /// * `colorscheme` - It takes the colorscheme name as an argument.
12
+ /// * `theme` - It takes the theme name as an argument.
13
+ ///
14
+ /// # Returns
15
+ ///
16
+ /// It returns the compiled html markup code as a result.
17
+ pub fn index(colorscheme: &str, theme: &str) -> Markup {
18
  html!(
19
  (header(colorscheme, theme))
20
  main class="search-container"{
21
  img src="../images/websurfx_logo.png" alt="Websurfx meta-search engine logo";
22
+ (bar(&String::default()))
23
  (PreEscaped("</div>"))
24
  }
25
  script src="static/index.js"{}
src/templates/views/mod.rs CHANGED
@@ -1,7 +1,8 @@
1
- //!
 
2
 
3
  pub mod about;
4
  pub mod index;
5
  pub mod not_found;
6
- pub mod settings;
7
  pub mod search;
 
 
1
+ //! This module provides other modules to handle view for each individual page in the
2
+ //! `websurfx` frontend.
3
 
4
  pub mod about;
5
  pub mod index;
6
  pub mod not_found;
 
7
  pub mod search;
8
+ pub mod settings;
src/templates/views/not_found.rs CHANGED
@@ -1,15 +1,24 @@
1
- //!
2
 
3
  use crate::templates::partials::{footer::footer, header::header};
4
  use maud::{html, Markup};
5
 
 
6
  ///
 
 
 
 
 
 
 
 
7
  pub fn not_found(colorscheme: &str, theme: &str) -> Markup {
8
  html!(
9
  (header(colorscheme, theme))
10
  main class="error_container"{
11
  img src="images/robot-404.svg" alt="Image of broken robot.";
12
- div class="error_content"{
13
  h1{"Aw! snap"}
14
  h2{"404 Page Not Found!"}
15
  p{"Go to "{a href="/"{"search page"}}}
 
1
+ //! A module that handles the view for the 404 page in the `websurfx` frontend.
2
 
3
  use crate::templates::partials::{footer::footer, header::header};
4
  use maud::{html, Markup};
5
 
6
+ /// A function that handles the html code for the 404 page view in the search engine frontend.
7
  ///
8
+ /// # Arguments
9
+ ///
10
+ /// * `colorscheme` - It takes the colorscheme name as an argument.
11
+ /// * `theme` - It takes the theme name as an argument.
12
+ ///
13
+ /// # Returns
14
+ ///
15
+ /// It returns the compiled html markup code as a result.
16
  pub fn not_found(colorscheme: &str, theme: &str) -> Markup {
17
  html!(
18
  (header(colorscheme, theme))
19
  main class="error_container"{
20
  img src="images/robot-404.svg" alt="Image of broken robot.";
21
+ .error_content{
22
  h1{"Aw! snap"}
23
  h2{"404 Page Not Found!"}
24
  p{"Go to "{a href="/"{"search page"}}}
src/templates/views/search.rs CHANGED
@@ -1,4 +1,4 @@
1
- //!
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
@@ -7,7 +7,18 @@ use crate::{
7
  templates::partials::{footer::footer, header::header, search_bar::search_bar},
8
  };
9
 
 
10
  ///
 
 
 
 
 
 
 
 
 
 
11
  pub fn search(
12
  colorscheme: &str,
13
  theme: &str,
 
1
+ //! A module that handles the view for the search page in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup, PreEscaped};
4
 
 
7
  templates::partials::{footer::footer, header::header, search_bar::search_bar},
8
  };
9
 
10
+ /// A function that handles the html code for the search page view in the search engine frontend.
11
  ///
12
+ /// # Arguments
13
+ ///
14
+ /// * `colorscheme` - It takes the colorscheme name as an argument.
15
+ /// * `theme` - It takes the theme name as an argument.
16
+ /// * `query` - It takes the current search query provided by the user as an argument.
17
+ /// * `search_results` - It takes the aggregated search results as an argument.
18
+ ///
19
+ /// # Returns
20
+ ///
21
+ /// It returns the compiled html markup code as a result.
22
  pub fn search(
23
  colorscheme: &str,
24
  theme: &str,
src/templates/views/settings.rs CHANGED
@@ -1,4 +1,4 @@
1
- //!
2
 
3
  use maud::{html, Markup};
4
 
@@ -10,7 +10,18 @@ use crate::templates::partials::{
10
  },
11
  };
12
 
 
13
  ///
 
 
 
 
 
 
 
 
 
 
14
  pub fn settings(
15
  colorscheme: &str,
16
  theme: &str,
 
1
+ //! A module that handles the view for the settings page in the `websurfx` frontend.
2
 
3
  use maud::{html, Markup};
4
 
 
10
  },
11
  };
12
 
13
+ /// A function that handles the html code for the settings page view in the search engine frontend.
14
  ///
15
+ /// # Arguments
16
+ ///
17
+ /// * `colorscheme` - It takes the colorscheme name as an argument.
18
+ /// * `theme` - It takes the theme name as an argument.
19
+ /// * `engine_names` - It takes a list of engine names as an argument.
20
+ ///
21
+ /// # Error
22
+ ///
23
+ /// This function returns a compiled html markup code on success otherwise returns a standard error
24
+ /// message.
25
  pub fn settings(
26
  colorscheme: &str,
27
  theme: &str,