-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: group transformer under dedicated module and features flags…
… for dependencies
- Loading branch information
Showing
6 changed files
with
43 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::errors::Result; | ||
use crate::pipes::Pipe; | ||
use crate::sources::{EventSource, EventSourcePipe}; | ||
use handlebars::Handlebars; | ||
|
||
pub(crate) struct Processor { | ||
next: EventSourcePipe, | ||
renderer: Handlebars<'static>, | ||
} | ||
|
||
impl Processor { | ||
pub(crate) fn new(template: &str, next: EventSourcePipe) -> Result<Self> { | ||
let mut renderer = Handlebars::new(); | ||
renderer.set_dev_mode(false); | ||
renderer.set_strict_mode(true); | ||
renderer.register_escape_fn(handlebars::no_escape); | ||
handlebars_misc_helpers::register(&mut renderer); | ||
renderer.register_template_string("tpl", template)?; | ||
Ok(Self { next, renderer }) | ||
} | ||
} | ||
|
||
impl Pipe for Processor { | ||
type Input = EventSource; | ||
fn send(&mut self, input: Self::Input) -> Result<()> { | ||
let res = self.renderer.render("tpl", &input)?; | ||
let output: EventSource = serde_json::from_str(&res)?; | ||
self.next.send(output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters