sqruff_lib/
templaters.rs

1use std::sync::Arc;
2
3use sqruff_lib_core::errors::SQLFluffUserError;
4use sqruff_lib_core::templaters::TemplatedFile;
5
6use crate::Formatter;
7use crate::core::config::FluffConfig;
8use crate::templaters::placeholder::PlaceholderTemplater;
9use crate::templaters::raw::RawTemplater;
10
11#[cfg(feature = "python")]
12use crate::templaters::jinja::JinjaTemplater;
13#[cfg(feature = "python")]
14use crate::templaters::python::PythonTemplater;
15
16#[cfg(feature = "python")]
17pub mod dbt;
18#[cfg(feature = "python")]
19pub mod jinja;
20pub mod placeholder;
21#[cfg(feature = "python")]
22pub mod python;
23#[cfg(feature = "python")]
24pub mod python_shared;
25pub mod raw;
26
27pub static RAW_TEMPLATER: RawTemplater = RawTemplater;
28pub static PLACEHOLDER_TEMPLATER: PlaceholderTemplater = PlaceholderTemplater;
29#[cfg(feature = "python")]
30pub static PYTHON_TEMPLATER: PythonTemplater = PythonTemplater;
31#[cfg(feature = "python")]
32pub static JINJA_TEMPLATER: JinjaTemplater = JinjaTemplater;
33#[cfg(feature = "python")]
34pub static DBT_TEMPLATER: dbt::DBTTemplater = dbt::DBTTemplater;
35
36// templaters returns all the templaters that are available in the library
37#[cfg(feature = "python")]
38pub static TEMPLATERS: [&'static dyn Templater; 5] = [
39    &RAW_TEMPLATER,
40    &PLACEHOLDER_TEMPLATER,
41    &PYTHON_TEMPLATER,
42    &JINJA_TEMPLATER,
43    &DBT_TEMPLATER,
44];
45
46#[cfg(not(feature = "python"))]
47pub static TEMPLATERS: [&'static dyn Templater; 2] = [&RAW_TEMPLATER, &PLACEHOLDER_TEMPLATER];
48
49pub trait Templater: Send + Sync {
50    /// The name of the templater.
51    fn name(&self) -> &'static str;
52
53    /// Can process in parrallel.
54    fn can_process_in_parallel(&self) -> bool;
55
56    /// Description of the templater.
57    fn description(&self) -> &'static str;
58
59    /// Process a string and return a TemplatedFile.
60    fn process(
61        &self,
62        in_str: &str,
63        f_name: &str,
64        config: &FluffConfig,
65        formatter: &Option<Arc<dyn Formatter>>,
66    ) -> Result<TemplatedFile, SQLFluffUserError>;
67}