sofie_engine/rendering/
mod.rs1#[cfg(feature = "gates")]
2mod gates;
3#[cfg(all(feature = "gates", feature = "parse"))]
4mod parse;
5#[cfg(feature = "gates")]
6mod withheld;
7
8use sofie_core::Show;
9
10#[cfg(feature = "gates")]
11pub use self::gates::Gates;
12#[cfg(feature = "gates")]
13pub(crate) use self::gates::{Asks, Gate, GatesRef};
14#[cfg(all(feature = "gates", feature = "parse"))]
15pub(crate) use self::parse::parse_gate;
16#[cfg(feature = "gates")]
17pub(crate) use self::withheld::GatedPaths;
18#[cfg(feature = "gates")]
19pub use self::withheld::Withheld;
20#[cfg(all(feature = "gates", feature = "analysis"))]
21pub use self::withheld::{Withholdable, withholdable};
22use crate::language::Language;
23use crate::template::{mark_out_of_band, render_part, render_whole};
24use crate::{RenderError, Submitted, Template, TemplateError};
25
26#[derive(Clone, Copy)]
28pub struct Rendering<'t> {
29 template: &'t Template,
30 language: Language<'t>,
31}
32
33impl<'t> Rendering<'t> {
34 #[must_use]
35 pub fn new(template: &'t Template) -> Self {
36 Self {
37 template,
38 language: Language::plain(),
39 }
40 }
41
42 #[cfg(feature = "i18n")]
43 #[must_use]
44 pub fn language(mut self, language: crate::Language<'t>) -> Self {
45 #[cfg(feature = "gates")]
46 let language = language.with_gates(self.language.gates());
47 self.language = language;
48 self
49 }
50
51 #[cfg(feature = "gates")]
52 #[must_use]
53 pub fn gates(mut self, gates: &'t dyn Gates) -> Self {
54 self.language = self.language.with_gates(Some(gates));
55 self
56 }
57
58 #[cfg(feature = "gates")]
61 #[must_use]
62 pub fn withheld(&self) -> Withheld<'t> {
63 self.template
64 .precomputed
65 .gated_paths
66 .withheld(self.language.gates())
67 }
68
69 #[cfg(feature = "clients")]
72 #[must_use]
73 pub fn client_view(&self) -> crate::ClientView {
74 crate::client_view::client_parts(self.template).view(self.language)
75 }
76
77 #[cfg(all(feature = "clients", feature = "listing"))]
79 pub fn translate_listing_errors(&self, data: &mut serde_json::Value) {
80 crate::client_view::client_parts(self.template)
81 .translate_listing_errors(data, self.language);
82 }
83
84 pub fn render(&self, data: &(impl Show + ?Sized)) -> Result<String, TemplateError> {
85 render_whole(self.template, data.show(), None, self.language)
86 }
87
88 pub fn render_submitted(
89 &self,
90 data: &(impl Show + ?Sized),
91 submitted: &Submitted<'_>,
92 ) -> Result<String, TemplateError> {
93 render_whole(self.template, data.show(), Some(submitted), self.language)
94 }
95
96 pub fn render_fragment(
97 &self,
98 data: &(impl Show + ?Sized),
99 id: &str,
100 ) -> Result<String, RenderError> {
101 render_part(self.template, data.show(), id, self.language)
102 }
103
104 pub fn render_out_of_band(
105 &self,
106 data: &(impl Show + ?Sized),
107 id: &str,
108 ) -> Result<String, RenderError> {
109 self.render_fragment(data, id).map(mark_out_of_band)
110 }
111}