16个版本

0.4.4 2023年3月19日
0.4.2 2021年11月10日
0.3.0-alpha42021年7月23日
0.1.1 2021年1月17日
0.1.0 2019年11月12日

模板引擎中排名#142

Download history 218/week @ 2024-03-09 6/week @ 2024-03-16 17/week @ 2024-03-30

每月下载量90
用于 2 crates

AGPL-3.0-or-later

26KB
495

shtola

Shtola是一个通用的文件处理库。它允许您构建自己的应用程序,这些应用程序可以作为静态网站生成器!以下是一个示例

use shtola::{Plugin, RefIR, ShFile, Shtola};
use std::time::SystemTime;

fn plugin() -> Plugin {
	Box::new(|mut ir: RefIR| {
		// Let's create our file in the IR (intermediate representation) file hash map!
		let current_time = SystemTime::now();
		ir.files.insert(
			"current_time.txt".into(),
			ShFile {
				content: format!("{:?}", current_time).into(),
				..ShFile::default()
			},
		);
	})
}

fn main() {
	let mut s = Shtola::new();
	s.source("fixtures/empty");
	s.destination("fixtures/dest_systemtime");
	s.register(plugin());
	s.build().expect("Build failed!");
	// Now we have a "current_time.txt" file in our destination directory that
	// contains the current system time!
}

安装

将Shtola的最新版本添加到您的Cargo.toml

文档

请参阅https://docs.rs/shtola


lib.rs:

使用Shtola,您可以轻松构建自己的静态网站生成器。Shtola本身所做的只是读取文件和元数据,通过一系列用户提供的插件处理它们,然后将结果写回磁盘。

以下是一个演示Shtola基本管道功能的示例

use shtola::Shtola;

let mut m = Shtola::new();
m.source("../fixtures/simple");
m.destination("../fixtures/dest/doctest_example");
m.clean(true);
m.build().unwrap();

“插件”只是一个接收RefMutIR(中间表示)结构的盒函数。插件可以自由地修改IR

use shtola::{Plugin, ShFile, RefIR};

fn plugin() -> Plugin {
  Box::new(|mut ir: RefIR| {
    ir.files.insert("myFile".into(), ShFile::empty());
  })
}

依赖关系

~5–17MB
~197K SLoC