Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 1.15 KB

README.md

File metadata and controls

58 lines (42 loc) · 1.15 KB

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}')