templo_engine

Crates.iotemplo_engine
lib.rstemplo_engine
version0.2.0
sourcesrc
created_at2021-11-06 18:23:39.457989
updated_at2021-12-14 21:26:35.407446
descriptionThis crate is a template engine for Templo tool to insert arguments inside of text files.
homepagehttps://github.com/pultzlucas/templo-engine
repositoryhttps://github.com/pultzlucas/templo-engine
max_upload_size
id477758
size28,528
Lucas Lopes Pultz (pultzlucas)

documentation

README

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}')
Commit count: 41

cargo fmt