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:
57
tera_factory/examples/hot_reload/templates/index.html.tera
Normal file
57
tera_factory/examples/hot_reload/templates/index.html.tera
Normal file
@@ -0,0 +1,57 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Rhai + Tera Hot Reload Example</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.product {
|
||||
border: 1px solid #ddd;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.date {
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
}
|
||||
.greeting {
|
||||
font-size: 24px;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
.reload-time {
|
||||
background-color: #f8f8f8;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="greeting">{{ greet(name=name) }}</div>
|
||||
|
||||
<p>Today's date: <span class="date">{{ format_date(date_str=current_date) }}</span></p>
|
||||
|
||||
<h2>Featured Products</h2>
|
||||
{% for product in products %}
|
||||
<div class="product">
|
||||
{{ format_product(name=product.name, price=product.price, discount=product.discount) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<h2>Categories</h2>
|
||||
{{ format_list_items(items=categories) | safe }}
|
||||
|
||||
<div class="reload-time">
|
||||
Page generated at: {{ current_time }}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user