TemplatePlugin

Trait TemplatePlugin 

Source
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§

Source

fn capabilities(&self) -> PluginCapabilities

Get plugin capabilities (permissions and limits)

Source

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

Source

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 context
  • config - Plugin configuration
§Returns

Map of function names to function metadata

Source

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 context
  • function_name - Name of the function being called
  • args - Function arguments
  • config - Plugin configuration
§Returns

Function execution result

Source

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 context
  • data_source - Name of the requested data source
  • config - Plugin configuration
§Returns

Data source content

Source

fn validate_config( &self, config: &TemplatePluginConfig, ) -> Result<(), PluginError>

Validate plugin configuration

Source

fn available_data_sources(&self) -> Vec<String>

Get list of available data sources

Source

fn cleanup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Cleanup plugin resources

Implementors§