Skip to content

Commit

Permalink
test: add cli & main unit testting.
Browse files Browse the repository at this point in the history
  • Loading branch information
auula committed Jul 1, 2024
1 parent aa1849b commit f0d97d2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
# Typikon

**Typikon lets you use markdown to write your online books.**
Typikon lets you use markdown to write your online books.

---

![https://img.shields.io/badge/Typikon-Rust%20CLI-brightgreen](https://img.shields.io/badge/📖%20Typikon-Rust%20🦀️-yellow)
[![codecov](https://codecov.io/github/auula/typikon/branch/main/graph/badge.svg?token=FaR2OdNYeB)](https://codecov.io/github/auula/typikon)
[![License](https://img.shields.io/badge/license-Apache-db5149.svg)](https://github.com/auula/typikon/blob/master/LICENSE)
![https://img.shields.io/github/repo-size/auula/typikon](https://img.shields.io/github/repo-size/auula/typikon)
[![action](https://github.com/auula/typikon/actions/workflows/rust.yml/badge.svg?event=push)](https://github.com/auula/typikon/actions/workflows/rust.yml)
[![Twitter URL](https://img.shields.io/twitter/follow/auula_?style=social)](https://twitter.com/auula_)


---

A static website rendering tool similar to mdbook and hugo, but it focuses only on rendering markdown into an online book, and is easier to use than the other tools.
## Introduce

Typikon name derived from [Typikon](https://en.wikipedia.org/wiki/Typikon) Book, the a static website rendering tool similar to mdbook and hugo, but it focuses only on rendering markdown into an online book, and is easier to use than the other tools.

---

## Preview

<div style="display: flex; justify-content: space-around;">
<img src="https://img.ibyte.me/a0mt96.png" alt="Alt text" style="width: 400px; height: 300px;">
<img src="https://img.ibyte.me/e68k6e.png" alt="Alt text" style="width: 400px; height: 300px;">
</div>

---
6 changes: 2 additions & 4 deletions src/book/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use super::{get_settings, Root, Settings};
#[derive(Debug)]
pub struct Builder {
root: Root,
pub templates: Template,
pub engine: Tera,
settings: Settings,
pub templates: Vec<Template>,
}

impl Builder {
Expand Down Expand Up @@ -62,13 +62,11 @@ impl Builder {
pub fn create_directory() -> io::Result<()> {
unimplemented!()
}


}

pub fn new_builder() -> Result<Builder, Box<dyn std::error::Error>> {
let root = book::get_root()?;
let templates = html::Template::empty();
let templates = html::get_templates().unwrap();
let settings = book::get_settings()?;
let engine = Tera::new(format!("theme/{}/**/*.html", &settings.settings.theme).as_str())?;
// 返回 Builder 实例
Expand Down
4 changes: 4 additions & 0 deletions src/html/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ impl Template {
pub fn render_to_html(_tmpl: Vec<Template>) {
unimplemented!()
}

pub fn get_templates() -> Option<Vec<Template>> {
Some(vec![])
}
28 changes: 28 additions & 0 deletions tests/main_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use typikon::{cli::Command, utils::Logger};

#[test]
fn test_handle_init_command() {
// Mock args and log

let mut log = Logger::console_log();

// Test handle_init_command
for cmd in &[
"build".to_string(),
"init".to_string(),
"theme".to_string(),
"help".to_string(),
] {
match Command::from_str(&cmd) {
Command::Build => typikon::cli::handle_build_command(&["build".to_string()], &mut log),
Command::Theme => {
typikon::cli::handle_build_command(&["--get=xxxxxxx.git".to_string()], &mut log)
}
Command::Init => {
typikon::cli::handle_build_command(&["--path=/xxxxx".to_string()], &mut log)
}
Command::Help => typikon::cli::handle_build_command(&["theme".to_string()], &mut log),
Command::Unknown(_) => typikon::cli::out_banner_string(),
}
}
}

0 comments on commit f0d97d2

Please sign in to comment.