feat(tera_factory): Implement hot reload example for Tera templates with Rhai
This commit adds a comprehensive hot reload example that demonstrates how to use the rhai_system for dynamic template rendering with Tera. Key improvements include: - Refactor the example to use external script files instead of hardcoded Rhai code - Implement proper module imports using the BasePathModuleResolver approach - Fix template rendering by using keyword arguments in Tera function calls - Add support for hot reloading both main and utility scripts - Remove unnecessary output file generation to keep the example clean - Fix compatibility issues with Rhai functions (avoiding to_string with parameters) This example showcases how changes to Rhai scripts are automatically detected and applied to rendered templates without restarting the application, providing a smooth development experience.
This commit is contained in:
21
tera_factory/examples/basic/scripts/math.rhai
Normal file
21
tera_factory/examples/basic/scripts/math.rhai
Normal file
@@ -0,0 +1,21 @@
|
||||
// Basic math functions for Tera templates
|
||||
|
||||
// Add two numbers together
|
||||
fn sum(a, b) {
|
||||
a + b
|
||||
}
|
||||
|
||||
// Multiply two numbers
|
||||
fn multiply(a, b) {
|
||||
a * b
|
||||
}
|
||||
|
||||
// Format a number with a prefix and suffix
|
||||
fn format_number(number, prefix, suffix) {
|
||||
prefix + number.to_string() + suffix
|
||||
}
|
||||
|
||||
// Format a greeting with a name
|
||||
fn greet(name) {
|
||||
"Hey, " + name + "!"
|
||||
}
|
Reference in New Issue
Block a user