#template #engine #templo

templo_engine

This crate is a template engine for Templo tool to insert arguments inside of text files

3 unstable releases

0.2.0 Dec 14, 2021
0.1.5 Nov 7, 2021

#326 in Template engine

MIT license

28KB
643 lines

Templo Engine

Template engine for insert and modify variables inside of text files.

example

The input text can have some placeholders represented by "{> arg <}". These placeholders will be used to insert the arguments passed to the engine. The engine provides some native functions to manipulate the argument value as well.

input.py

class {> upper_first(class_name) <}:
    def __init__(self):
    self.name = '{> class_name <}'

obj = {> upper_first(class_name) <}()

print(f'The class name is {obj.name}')

execution

use templo_engine::*;

// Getting the input text
let input_text = std::fs::read_to_string("./input.py").unwrap();

// The arguments
let arguments = vec![
    EngineArg {
        key: String::from("class_name"),
        value: String::from("dog"),
        value_type: EngineArgType::String,
    }
];

// Inserting the arguments on text
let engine = Engine::new(arguments);
let text = engine.compile(input_text);

// writing the output file
std::fs::write("./output.py", text.unwrap()).unwrap();

output.py

class Dog:
    def __init__(self):
    self.name = 'dog'

obj = Dog()

print(f'The class name is {obj.name}')

Dependencies

~2.2–3MB
~55K SLoC