Skip to content

Commit

Permalink
feat(shokunin): decoupling models and cli modules
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Sep 8, 2023
1 parent 01866e5 commit e51b770
Show file tree
Hide file tree
Showing 27 changed files with 47 additions and 38 deletions.
2 changes: 1 addition & 1 deletion benches/bench_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate criterion;
use std::path::Path;

use criterion::{black_box, Criterion};
use ssg::data::{ManifestData, TxtData, CnameData, HumansData, SiteMapData};
use ssg::models::data::{ManifestData, TxtData, CnameData, HumansData, SiteMapData};
use ssg::modules::json::{manifest, txt, cname, human, sitemap};

pub fn bench_json(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{
data::{FileData, RssData, PageData},
macro_log_info,
macro_cleanup_directories, macro_create_directories,
macro_metadata_option,macro_set_rss_data_fields,
models::data::{FileData, RssData, PageData},
modules::{
cname::create_cname_data,
html::generate_html,
Expand Down
18 changes: 7 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,32 +116,28 @@
#![crate_type = "lib"]

use crate::utilities::serve::start;
use cli::print_banner;
use term::cli::print_banner;
use compiler::compile;
use std::{error::Error, path::Path};

/// The `cli` module contains functions for the command-line interface.
pub mod cli;
pub mod term;

/// The `compiler` module contains functions for the compilation process.
pub mod compiler;

/// The `data` module contains the structs.
pub mod data;

/// The `loggers` module contains functions for logging.
pub mod loggers;

/// The `macros` module contains functions for generating macros.
pub mod macros;

/// The `models` module contains the structs.
pub mod models;

/// The `modules` module contains the application modules.
pub mod modules;

/// The `parser` module contains functions for parsing command-line
/// arguments and options.
pub mod process;

/// The `utilities` module contains utility functions.
pub mod utilities;

Expand All @@ -167,8 +163,8 @@ pub fn run() -> Result<(), Box<dyn Error>> {
print_banner();

// Build the CLI and parse the arguments
let matches = cli::build()?;
process::args(&matches)?;
let matches = term::cli::build()?;
term::process::args(&matches)?;

if let Some(site_name) = matches.get_one::<String>("new") {
// Start the server using the specified server address and site name.
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

/// The `data` module contains the structs.
pub mod data;
2 changes: 1 addition & 1 deletion src/modules/cname.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::data::CnameData;
use crate::models::data::CnameData;
use std::collections::HashMap;

/// Function to create CnameData
Expand Down
2 changes: 1 addition & 1 deletion src/modules/human.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::data::HumansData;
use crate::models::data::HumansData;
use std::collections::HashMap;

/// Function to create HumansData
Expand Down
2 changes: 1 addition & 1 deletion src/modules/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};
use serde_json::{json, Map};

use crate::data::{
use crate::models::data::{
CnameData, HumansData, ManifestData,
SiteMapData, TxtData
};
Expand Down
2 changes: 1 addition & 1 deletion src/modules/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{data::{IconData, ManifestData}, macro_metadata_option};
use crate::{models::data::{IconData, ManifestData}, macro_metadata_option};
use std::collections::HashMap;

/// Function to create ManifestData
Expand Down
4 changes: 2 additions & 2 deletions src/modules/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::{
data:: MetaTagGroups,
models::data:: MetaTagGroups,
modules::{
frontmatter::extract,
keywords::extract_keywords,
Expand Down Expand Up @@ -33,7 +33,7 @@ use std::collections::HashMap;
/// # Examples
///
/// ```rust
/// use ssg::data::FileData;
/// use ssg::models::data::FileData;
/// use ssg::modules::metadata::extract_and_prepare_metadata;
///
/// let file_content = "---\n\n# Front Matter (YAML)\n\nauthor: \"Jane Doe\"\ncategory: \"Rust\"\ndescription: \"A blog about Rust programming.\"\nlayout: \"post\"\npermalink: \"https://example.com/blog/rust\"\ntags: \"rust,programming\"\ntitle: \"Rust\"\n\n---\n\n# Content\n\nThis is a blog about Rust programming.\n";
Expand Down
2 changes: 1 addition & 1 deletion src/modules/metatags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::collections::HashMap;
use crate::data::{MetaTag, MetaTagGroups};
use crate::models::data::{MetaTag, MetaTagGroups};
use crate::{macro_generate_tags_from_list, macro_generate_tags_from_fields};

// Type alias for better readability
Expand Down
2 changes: 1 addition & 1 deletion src/modules/navigation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::data::FileData;
use crate::models::data::FileData;
use crate::utilities::directory::to_title_case;
use std::path::Path;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/rss.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::data::RssData;
use crate::models::data::RssData;
use crate::macro_write_element;
use quick_xml::{
events::{BytesDecl, BytesEnd, BytesStart, Event},
Expand Down
2 changes: 1 addition & 1 deletion src/modules/sitemap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::data::SiteMapData;
use crate::models::data::SiteMapData;
use std::collections::HashMap;

/// Function to create SiteMapData
Expand Down
6 changes: 3 additions & 3 deletions src/modules/tags.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::data::{FileData, TagsData, PageData};
use crate::models::data::{FileData, TagsData, PageData};
use crate::utilities::directory::to_title_case;
use std::{io::{Read, Write}, collections::HashMap, path::Path, fs};

Expand All @@ -19,7 +19,7 @@ use std::{io::{Read, Write}, collections::HashMap, path::Path, fs};
/// # Example
///
/// ```rust
/// use ssg::data::FileData;
/// use ssg::models::data::FileData;
/// use ssg::modules::tags::generate_tags;
/// use std::collections::HashMap;
///
Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn create_tags_data(
///
/// ```rust
/// use std::collections::HashMap;
/// use ssg::data::PageData;
/// use ssg::models::data::PageData;
/// use ssg::modules::tags::generate_tags_html;
///
/// let mut global_tags_data = HashMap::new();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/txt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::data::TxtData;
use crate::models::data::TxtData;
use std::collections::HashMap;

/// Function to create TxtData
Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs → src/term/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use clap::{Arg, ArgMatches, Command, Error};
/// # Examples
///
/// ```
/// use ssg::cli;
/// let cmd = cli::build().unwrap();
/// use ssg::term::cli::build;
/// let cmd = build().unwrap();
///
/// ```
pub fn build() -> Result<ArgMatches, Error> {
Expand Down Expand Up @@ -103,7 +103,7 @@ pub fn build() -> Result<ArgMatches, Error> {
/// # Examples
///
/// ```
/// use ssg::cli::print_banner;
/// use ssg::term::cli::print_banner;
///
/// print_banner();
/// ```
Expand Down
8 changes: 8 additions & 0 deletions src/term/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

/// The `cli` module contains functions for the command-line interface.
pub mod cli;

/// The `parser` module contains functions for parsing command-line arguments and options.
pub mod process;
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utilities/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2023 Shokunin Static Site Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::data::FileData;
use crate::models::data::FileData;
use quick_xml::escape::escape;
use std::{fs, io, path::Path};

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT


use crate::data::FileData;
use crate::models::data::FileData;
use crate::utilities::minification::minify_html;
use std::error::Error;
use std::fs;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod tests {
use std::error::Error;

use ssg::{
data::RssData,
models::data::RssData,
modules::{frontmatter::extract, html::generate_html, rss::generate_rss},
};

Expand Down
2 changes: 1 addition & 1 deletion tests/test_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]
mod tests {

use ssg::data::{
use ssg::models::data::{
CnameData, FileData, IconData, ManifestData, SiteMapData,
TxtData,
};
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod tests {
// Import necessary dependencies
use serde_json::{json, Value};
use ssg::{
data::{CnameData, ManifestData, TxtData},
models::data::{CnameData, ManifestData, TxtData},
modules::json::{cname, manifest, txt},
};

Expand Down
2 changes: 1 addition & 1 deletion tests/test_navigation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use ssg::{data::FileData, modules::navigation::generate_navigation};
use ssg::{models::data::FileData, modules::navigation::generate_navigation};

#[test]
fn test_generate_navigation() {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_process.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]
mod tests {
use clap::{Arg, Command};
use ssg::process::args;
use ssg::term::process::args;

#[test]
fn test_args_required_args_missing() {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod tests {
use std::io::Cursor;

use quick_xml::Writer;
use ssg::{data::RssData, modules::rss::generate_rss};
use ssg::{models::data::RssData, modules::rss::generate_rss};

// Test the default constructor of RssData
#[test]
Expand Down

0 comments on commit e51b770

Please sign in to comment.