Rename library to nomo
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
d691fb9198
commit
d2e0405033
28 changed files with 92 additions and 92 deletions
28
src/lib.rs
28
src/lib.rs
|
|
@ -6,7 +6,7 @@ use serde::Serialize;
|
|||
use thiserror::Error;
|
||||
|
||||
use crate::emit::Instruction;
|
||||
use crate::input::TempleInput;
|
||||
use crate::input::NomoInput;
|
||||
|
||||
pub mod ast;
|
||||
pub mod emit;
|
||||
|
|
@ -15,7 +15,7 @@ pub mod input;
|
|||
pub mod parser;
|
||||
|
||||
#[derive(Debug, Error, Display)]
|
||||
pub enum TempleError {
|
||||
pub enum NomoError {
|
||||
/// Could not parse the given template
|
||||
ParseError {
|
||||
#[from]
|
||||
|
|
@ -37,19 +37,19 @@ pub enum TempleError {
|
|||
UnknownTemplate(String),
|
||||
}
|
||||
|
||||
pub struct Temple {
|
||||
pub struct Nomo {
|
||||
templates: HashMap<String, Template>,
|
||||
}
|
||||
|
||||
impl Default for Temple {
|
||||
impl Default for Nomo {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Temple {
|
||||
pub fn new() -> Temple {
|
||||
Temple {
|
||||
impl Nomo {
|
||||
pub fn new() -> Nomo {
|
||||
Nomo {
|
||||
templates: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -57,8 +57,8 @@ impl Temple {
|
|||
pub fn add_template(
|
||||
&mut self,
|
||||
name: impl Into<String>,
|
||||
value: impl Into<TempleInput>,
|
||||
) -> Result<(), TempleError> {
|
||||
value: impl Into<NomoInput>,
|
||||
) -> Result<(), NomoError> {
|
||||
let source = value.into();
|
||||
let parse = parser::parse(source.clone())?;
|
||||
let ast = ast::parse(parse.tokens())?;
|
||||
|
|
@ -76,11 +76,11 @@ impl Temple {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render(&self, name: &str, ctx: &Context) -> Result<String, TempleError> {
|
||||
pub fn render(&self, name: &str, ctx: &Context) -> Result<String, NomoError> {
|
||||
let template = self
|
||||
.templates
|
||||
.get(name)
|
||||
.ok_or_else(|| TempleError::UnknownTemplate(name.to_string()))?;
|
||||
.ok_or_else(|| NomoError::UnknownTemplate(name.to_string()))?;
|
||||
|
||||
let res = eval::execute(&template.instructions, ctx)?;
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ impl Temple {
|
|||
}
|
||||
|
||||
struct Template {
|
||||
source: TempleInput,
|
||||
source: NomoInput,
|
||||
instructions: Vec<Instruction>,
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +186,11 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::Context;
|
||||
use crate::Temple;
|
||||
use crate::Nomo;
|
||||
|
||||
#[test]
|
||||
fn check_simple_template() {
|
||||
let mut temp = Temple::new();
|
||||
let mut temp = Nomo::new();
|
||||
|
||||
temp.add_template("base", "Hello {{= name }}").unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue