pub trait TemplatePlugin: Send + Sync {
// Required methods
fn capabilities(&self) -> PluginCapabilities;
fn initialize<'life0, 'life1, 'async_trait>(
&'life0 self,
config: &'life1 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn register_functions<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
config: &'life2 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<HashMap<String, TemplateFunction>>, PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn execute_function<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
function_name: &'life2 str,
args: &'life3 [Value],
config: &'life4 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<Value>, PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait;
fn get_data_source<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
data_source: &'life2 str,
config: &'life3 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<Value>, PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait;
fn validate_config(
&self,
config: &TemplatePluginConfig,
) -> Result<(), PluginError>;
fn available_data_sources(&self) -> Vec<String>;
fn cleanup<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
Template plugin trait
Implement this trait to create custom template functions and data generators. Template plugins are called during template expansion to provide custom functions, filters, and data sources.
Required Methods§
Sourcefn capabilities(&self) -> PluginCapabilities
fn capabilities(&self) -> PluginCapabilities
Get plugin capabilities (permissions and limits)
Sourcefn initialize<'life0, 'life1, 'async_trait>(
&'life0 self,
config: &'life1 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn initialize<'life0, 'life1, 'async_trait>(
&'life0 self,
config: &'life1 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Initialize the plugin with configuration
Sourcefn register_functions<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
config: &'life2 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<HashMap<String, TemplateFunction>>, PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn register_functions<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
config: &'life2 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<HashMap<String, TemplateFunction>>, PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Register template functions
This method is called during plugin initialization to register custom template functions. The plugin should return a map of function names to function metadata.
§Arguments
context
- Plugin execution contextconfig
- Plugin configuration
§Returns
Map of function names to function metadata
Sourcefn execute_function<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
function_name: &'life2 str,
args: &'life3 [Value],
config: &'life4 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<Value>, PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
fn execute_function<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
function_name: &'life2 str,
args: &'life3 [Value],
config: &'life4 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<Value>, PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: 'async_trait,
Execute a template function
This method is called when a registered template function is invoked during template expansion.
§Arguments
context
- Plugin execution contextfunction_name
- Name of the function being calledargs
- Function argumentsconfig
- Plugin configuration
§Returns
Function execution result
Sourcefn get_data_source<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
data_source: &'life2 str,
config: &'life3 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<Value>, PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn get_data_source<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
context: &'life1 PluginContext,
data_source: &'life2 str,
config: &'life3 TemplatePluginConfig,
) -> Pin<Box<dyn Future<Output = Result<PluginResult<Value>, PluginError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Provide data sources
This method can be called to retrieve data that can be used in templates. The plugin can provide dynamic data sources that are refreshed periodically.
§Arguments
context
- Plugin execution contextdata_source
- Name of the requested data sourceconfig
- Plugin configuration
§Returns
Data source content
Sourcefn validate_config(
&self,
config: &TemplatePluginConfig,
) -> Result<(), PluginError>
fn validate_config( &self, config: &TemplatePluginConfig, ) -> Result<(), PluginError>
Validate plugin configuration
Sourcefn available_data_sources(&self) -> Vec<String>
fn available_data_sources(&self) -> Vec<String>
Get list of available data sources