Debian Codegraph @

src/partial.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
3
4 use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::valuerust-analyzer cargo serde_json 1.0.114 value/::Valuerust-analyzer cargo serde_json 1.0.114 value/Value# as Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#;
5
6 use craterust-analyzer cargo handlebars 5.1.2 crate/::blockrust-analyzer cargo handlebars 5.1.2 block/::BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#;
7 use craterust-analyzer cargo handlebars 5.1.2 crate/::contextrust-analyzer cargo handlebars 5.1.2 context/::{merge_jsonrust-analyzer cargo handlebars 5.1.2 context/merge_json()., Contextrust-analyzer cargo handlebars 5.1.2 context/Context#};
8 use craterust-analyzer cargo handlebars 5.1.2 crate/::errorrust-analyzer cargo handlebars 5.1.2 error/::RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#;
9 use craterust-analyzer cargo handlebars 5.1.2 crate/::jsonrust-analyzer cargo handlebars 5.1.2 json/::pathrust-analyzer cargo handlebars 5.1.2 json/path/::Pathrust-analyzer cargo handlebars 5.1.2 json/path/Path#;
10 use craterust-analyzer cargo handlebars 5.1.2 crate/::outputrust-analyzer cargo handlebars 5.1.2 output/::Outputrust-analyzer cargo handlebars 5.1.2 output/Output#;
11 use craterust-analyzer cargo handlebars 5.1.2 crate/::registryrust-analyzer cargo handlebars 5.1.2 registry/::Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#;
12 use craterust-analyzer cargo handlebars 5.1.2 crate/::renderrust-analyzer cargo handlebars 5.1.2 render/::{Decoratorrust-analyzer cargo handlebars 5.1.2 render/Decorator#, Evaluablerust-analyzer cargo handlebars 5.1.2 render/Evaluable#, RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#, Renderablerust-analyzer cargo handlebars 5.1.2 render/Renderable#};
13 use craterust-analyzer cargo handlebars 5.1.2 crate/::templaterust-analyzer cargo handlebars 5.1.2 template/::Templaterust-analyzer cargo handlebars 5.1.2 template/Template#;
14 use craterust-analyzer cargo handlebars 5.1.2 crate/::RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#;
15
16 pub(craterust-analyzer cargo handlebars 5.1.2 crate/) const PARTIAL_BLOCKrust-analyzer cargo handlebars 5.1.2 partial/PARTIAL_BLOCK.: &str = "@partial-block";
17
18 fn find_partialrust-analyzer cargo handlebars 5.1.2 partial/find_partial().<'reg: 'rc, 'rc: 'a, 'a>(
19 rc: &'a RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'reg, 'rc>,
20 r: &'reg Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg>,
21 d: &Decoratorrust-analyzer cargo handlebars 5.1.2 render/Decorator#<'rc>,
22 name: &str,
23 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, Templaterust-analyzer cargo handlebars 5.1.2 template/Template#>>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
24 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(partial) = rc.get_partialrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]get_partial().(name) {
25 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(partial)));
26 }
27
28 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tpl) = r.get_or_load_template_optionalrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_or_load_template_optional().(name) {
29 return tpl.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#::Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#);
30 }
31
32 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(tpl) = d.templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]template().() {
33 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(tpl)));
34 }
35
36 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
37 }
38
39 pub fn expand_partialrust-analyzer cargo handlebars 5.1.2 partial/expand_partial().<'reg: 'rc, 'rc>(
40 d: &Decoratorrust-analyzer cargo handlebars 5.1.2 render/Decorator#<'rc>,
41 r: &'reg Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg>,
42 ctx: &'rc Contextrust-analyzer cargo handlebars 5.1.2 context/Context#,
43 rc: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'reg, 'rc>,
44 out: &mut dyn Outputrust-analyzer cargo handlebars 5.1.2 output/Output#,
45 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
46 // try eval inline partials first
47 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = d.templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]template().() {
48 t.evalrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Evaluable]eval().(r, ctx, rc)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
49 }
50
51 let tname = d.namerust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]name().();
52 if rc.is_current_templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]is_current_template().(tname) {
53 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::CannotIncludeSelfrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#CannotIncludeSelf#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
54 }
55
56 let partial = find_partialrust-analyzer cargo handlebars 5.1.2 partial/find_partial().(rc, r, d, tname)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
57
58 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = partial {
59 // clone to avoid lifetime issue
60 // FIXME refactor this to avoid
61 let mut local_rc = rc.clonerust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`][Clone]clone().();
62
63 // if tname == PARTIAL_BLOCK
64 let is_partial_block = tname rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().PARTIAL_BLOCKrust-analyzer cargo handlebars 5.1.2 partial/PARTIAL_BLOCK.;
65
66 // add partial block depth there are consecutive partial
67 // blocks in the stack.
68 if is_partial_block {
69 local_rc.inc_partial_block_depthrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]inc_partial_block_depth().();
70 } else {
71 // depth cannot be lower than 0, which is guaranted in the
72 // `dec_partial_block_depth` method
73 local_rc.dec_partial_block_depthrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]dec_partial_block_depth().();
74 }
75
76 let mut block_created = false;
77
78 // create context if param given
79 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base_path) = d.paramrust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]param().(0).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|p| p.context_pathrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]context_path().()) {
80 // path given, update base_path
81 let mut block_inner = BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]new().();
82 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().block_inner.base_path_mutrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path_mut().() = base_path.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
83
84 // because block is moved here, we need another bool variable to track
85 // its status for later cleanup
86 block_created = true;
87 // clear blocks to prevent block params from parent
88 // template to be leaked into partials
89 // see `test_partial_context_issue_495` for the case.
90 local_rc.clear_blocksrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]clear_blocks().();
91 local_rc.push_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]push_block().(block_inner);
92 }
93
94 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().d.hashrust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]hash().().is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]is_empty().() {
95 // hash given, update base_value
96 let hash_ctx = d
97 .hashrust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]hash().()
98 .iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]iter().()
99 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(k, v)| (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().k, v.valuerust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]value().()))
100 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&str, &Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#>>();
101
102 // create block if we didn't (no param provided for partial expression)
103 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().block_created {
104 let block_inner = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(block) = local_rc.blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]block().() {
105 // reuse current block information, including base_path and
106 // base_value if any
107 block.clonerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`][Clone]clone().()
108 } else {
109 BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]new().()
110 };
111
112 local_rc.clear_blocksrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]clear_blocks().();
113 local_rc.push_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]push_block().(block_inner);
114 }
115
116 // evaluate context within current block, this includes block
117 // context provided by partial expression parameter
118 let merged_context = merge_jsonrust-analyzer cargo handlebars 5.1.2 context/merge_json().(
119 local_rc.evaluate2rust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]evaluate2().(ctx, &Pathrust-analyzer cargo handlebars 5.1.2 json/path/Path#::currentrust-analyzer cargo handlebars 5.1.2 json/path/impl#[Path]current().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..as_jsonrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`ScopedJson<'rc>`]as_json().(),
120 &hash_ctx,
121 );
122
123 // update the base value, there must be a block for this so it's
124 // also safe to unwrap.
125 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(block) = local_rc.block_mutrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]block_mut().() {
126 block.set_base_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_base_value().(merged_context);
127 }
128 }
129
130 // @partial-block
131 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pb) = d.templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]template().() {
132 local_rc.push_partial_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]push_partial_block().(pb);
133 }
134
135 // indent
136 local_rc.set_indent_stringrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]set_indent_string().(d.indentrust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]indent().());
137
138 let result = t.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(r, ctx, &mut local_rc, out);
139
140 // cleanup
141 if block_created {
142 local_rc.pop_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]pop_block().();
143 }
144
145 if d.templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`Decorator<'rc>`]template().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
146 local_rc.pop_partial_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]pop_partial_block().();
147 }
148
149 result
150 } else {
151 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::PartialNotFoundrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#PartialNotFound#(tname.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
152 }
153 }
154
155 #[cfg(test)]
156 mod testrust-analyzer cargo handlebars 5.1.2 partial/test/ {
157 use craterust-analyzer cargo handlebars 5.1.2 crate/::contextrust-analyzer cargo handlebars 5.1.2 context/::Contextrust-analyzer cargo handlebars 5.1.2 context/Context#;
158 use craterust-analyzer cargo handlebars 5.1.2 crate/::errorrust-analyzer cargo handlebars 5.1.2 error/::RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#;
159 use craterust-analyzer cargo handlebars 5.1.2 crate/::outputrust-analyzer cargo handlebars 5.1.2 output/::Outputrust-analyzer cargo handlebars 5.1.2 output/Output#;
160 use craterust-analyzer cargo handlebars 5.1.2 crate/::registryrust-analyzer cargo handlebars 5.1.2 registry/::Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#;
161 use craterust-analyzer cargo handlebars 5.1.2 crate/::renderrust-analyzer cargo handlebars 5.1.2 render/::{Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#, RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#};
162
163 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
164 fn testrust-analyzer cargo handlebars 5.1.2 partial/test/test().() {
165 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
166 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
167 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{> t1}}")
168 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
169 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
170 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t1", "{{this}}")
171 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
172 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
173 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t2", "{{#> t99}}not there{{/t99}}")
174 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
175 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
176 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t3", "{{#*inline \"t31\"}}{{this}}{{/inline}}{{> t31}}")
177 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
178 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
179 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
180 "t4",
181 "{{#> t5}}{{#*inline \"nav\"}}navbar{{/inline}}{{/t5}}"
182 )
183 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
184 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
185 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t5", "include {{> nav}}")
186 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
187 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
188 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t6", "{{> t1 a}}")
189 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
190 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
191 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
192 "t7",
193 "{{#*inline \"t71\"}}{{a}}{{/inline}}{{> t71 a=\"world\"}}"
194 )
195 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
196 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t8", "{{a}}").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
197 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
198 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t9", "{{> t8 a=2}}")
199 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
200
201 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &1).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "1".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
202 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
203 handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t2", &1).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
204 "not there".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
205 );
206 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t3", &1).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "1".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
207 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
208 handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t4", &1).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
209 "include navbar".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
210 );
211 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
212 handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t6", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"a": "2"})).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
213 "2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
214 );
215 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
216 handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t7", &1).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
217 "world".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
218 );
219 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t9", &1).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "2".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
220 }
221
222 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
223 fn test_include_partial_blockrust-analyzer cargo handlebars 5.1.2 partial/test/test_include_partial_block().() {
224 let t0 = "hello {{> @partial-block}}";
225 let t1 = "{{#> t0}}inner {{this}}{{/t0}}";
226
227 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
228 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", t0).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
229 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t1", t1).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
230
231 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &true);
232 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "hello inner true".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
233 }
234
235 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
236 fn test_self_inclusionrust-analyzer cargo handlebars 5.1.2 partial/test/test_self_inclusion().() {
237 let t0 = "hello {{> t1}} {{> t0}}";
238 let t1 = "some template";
239 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
240 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", t0).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
241 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t1", t1).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
242
243 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &true);
244 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r0.is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
245 }
246
247 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
248 fn test_issue_143rust-analyzer cargo handlebars 5.1.2 partial/test/test_issue_143().() {
249 let main_template = "one{{> two }}three{{> two }}";
250 let two_partial = "--- two ---";
251
252 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
253 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
254 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("template", main_template)
255 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
256 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
257 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("two", two_partial)
258 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
259
260 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("template", &true);
261 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "one--- two ---three--- two ---");
262 }
263
264 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
265 fn test_hash_context_outscoperust-analyzer cargo handlebars 5.1.2 partial/test/test_hash_context_outscope().() {
266 let main_template = "In: {{> p a=2}} Out: {{a}}";
267 let p_partial = "{{a}}";
268
269 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
270 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars
271 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("template", main_template)
272 .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
273 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("p", p_partial).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
274
275 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("template", &true);
276 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "In: 2 Out: ");
277 }
278
279 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
280 fn test_partial_context_hashrust-analyzer cargo handlebars 5.1.2 partial/test/test_partial_context_hash().() {
281 let mut hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
282 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("one", "This is a test. {{> two name=\"fred\" }}")
283 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
284 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("two", "Lets test {{name}}")
285 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
286 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
287 "This is a test. Lets test fred",
288 hbs.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("one", &0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
289 );
290 }
291
292 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
293 fn teset_partial_context_with_both_hash_and_paramrust-analyzer cargo handlebars 5.1.2 partial/test/teset_partial_context_with_both_hash_and_param().() {
294 let mut hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
295 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("one", "This is a test. {{> two this name=\"fred\" }}")
296 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
297 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("two", "Lets test {{name}} and {{root_name}}")
298 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
299 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
300 "This is a test. Lets test fred and tom",
301 hbs.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("one", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"root_name": "tom"})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
302 );
303 }
304
305 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
306 fn test_partial_subexpression_context_hashrust-analyzer cargo handlebars 5.1.2 partial/test/test_partial_subexpression_context_hash().() {
307 let mut hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
308 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("one", "This is a test. {{> (x @root) name=\"fred\" }}")
309 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
310 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("two", "Lets test {{name}}")
311 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
312
313 hbs.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().(
314 "x",
315 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(
316 |_: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'_>,
317 _: &Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'_>,
318 _: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#,
319 _: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'_, '_>,
320 out: &mut dyn Outputrust-analyzer cargo handlebars 5.1.2 output/Output#|
321 -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
322 out.writerust-analyzer cargo handlebars 5.1.2 output/Output#write().("two")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
323 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
324 },
325 ),
326 );
327 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
328 "This is a test. Lets test fred",
329 hbs.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("one", &0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
330 );
331 }
332
333 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
334 fn test_nested_partial_scoperust-analyzer cargo handlebars 5.1.2 partial/test/test_nested_partial_scope().() {
335 let t = "{{#*inline \"pp\"}}{{a}} {{b}}{{/inline}}{{#each c}}{{> pp a=2}}{{/each}}";
336 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"c": [{"b": true}, {"b": false}]});
337
338 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
339 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t", t).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
340 let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t", &data);
341 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r0.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), "2 true2 false");
342 }
343
344 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
345 fn test_nested_partial_blockrust-analyzer cargo handlebars 5.1.2 partial/test/test_nested_partial_block().() {
346 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
347 let template1 = "<outer>{{> @partial-block }}</outer>";
348 let template2 = "{{#> t1 }}<inner>{{> @partial-block }}</inner>{{/ t1 }}";
349 let template3 = "{{#> t2 }}Hello{{/ t2 }}";
350
351 handlebars
352 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t1", &template1)
353 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
354 handlebars
355 .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t2", &template2)
356 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
357
358 let page = handlebars.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(&template3, &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
359 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("<outer><inner>Hello</inner></outer>", page);
360 }
361
362 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
363 fn test_up_to_partial_levelrust-analyzer cargo handlebars 5.1.2 partial/test/test_up_to_partial_level().() {
364 let outer = r#"{{>inner name="fruit:" vegetables=fruits}}"#;
365 let inner = "{{#each vegetables}}{{../name}} {{this}},{{/each}}";
366
367 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ "fruits": ["carrot", "tomato"] });
368
369 let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
370 handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("outer", outer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
371 handlebars.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("inner", inner).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
372
373 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
374 handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("outer", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
375 "fruit: carrot,fruit: tomato,"
376 );
377 }
378
379 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
380 fn line_stripping_with_inline_and_partialrust-analyzer cargo handlebars 5.1.2 partial/test/line_stripping_with_inline_and_partial().() {
381 let tpl0 = r#"{{#*inline "foo"}}foo
382 {{/inline}}
383 {{> foo}}
384 {{> foo}}
385 {{> foo}}"#;
386 let tpl1 = r#"{{#*inline "foo"}}foo{{/inline}}
387 {{> foo}}
388 {{> foo}}
389 {{> foo}}"#;
390
391 let hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
392 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
393 r#"foo
394 foo
395 foo
396 "#,
397 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(tpl0, &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
398 );
399 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
400 r#"
401 foofoofoo"#,
402 hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(tpl1, &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
403 );
404 }
405
406 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
407 fn test_partial_indentrust-analyzer cargo handlebars 5.1.2 partial/test/test_partial_indent().() {
408 let outer = r#" {{> inner inner_solo}}
409
410 {{#each inners}}
411 {{> inner}}
412 {{/each}}
413
414 {{#each inners}}
415 {{> inner}}
416 {{/each}}
417 "#;
418 let inner = r#"name: {{name}}
419 "#;
420
421 let mut hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
422
423 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("inner", inner).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
424 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("outer", outer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
425
426 let result = hbs
427 .renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().(
428 "outer",
429 &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
430 "inner_solo": {"name": "inner_solo"},
431 "inners": [
432 {"name": "hello"},
433 {"name": "there"}
434 ]
435 }),
436 )
437 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
438
439 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
440 result,
441 r#" name: inner_solo
442
443 name: hello
444 name: there
445
446 name: hello
447 name: there
448 "#
449 );
450 }
451 // Rule::partial_expression should not trim leading indent by default
452
453 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
454 fn test_partial_prevent_indentrust-analyzer cargo handlebars 5.1.2 partial/test/test_partial_prevent_indent().() {
455 let outer = r#" {{> inner inner_solo}}
456
457 {{#each inners}}
458 {{> inner}}
459 {{/each}}
460
461 {{#each inners}}
462 {{> inner}}
463 {{/each}}
464 "#;
465 let inner = r#"name: {{name}}
466 "#;
467
468 let mut hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
469 hbs.set_prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_prevent_indent().(true);
470
471 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("inner", inner).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
472 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("outer", outer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
473
474 let result = hbs
475 .renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().(
476 "outer",
477 &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
478 "inner_solo": {"name": "inner_solo"},
479 "inners": [
480 {"name": "hello"},
481 {"name": "there"}
482 ]
483 }),
484 )
485 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
486
487 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
488 result,
489 r#" name: inner_solo
490
491 name: hello
492 name: there
493
494 name: hello
495 name: there
496 "#
497 );
498 }
499
500 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
501 fn test_nested_partialsrust-analyzer cargo handlebars 5.1.2 partial/test/test_nested_partials().() {
502 let mut hb = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
503 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("partial", "{{> @partial-block}}")
504 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
505 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
506 "index",
507 r#"{{#>partial}}
508 Yo
509 {{#>partial}}
510 Yo 2
511 {{/partial}}
512 {{/partial}}"#,
513 )
514 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
515 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
516 r#" Yo
517 Yo 2
518 "#,
519 hb.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("index", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
520 );
521
522 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("partial2", "{{> @partial-block}}")
523 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
524 let r2 = hb
525 .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(
526 r#"{{#> partial}}
527 {{#> partial2}}
528 :(
529 {{/partial2}}
530 {{/partial}}"#,
531 &(),
532 )
533 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
534 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(":(\n", r2);
535 }
536
537 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
538 fn test_partial_context_issue_495rust-analyzer cargo handlebars 5.1.2 partial/test/test_partial_context_issue_495().() {
539 let mut hb = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
540 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
541 "t1",
542 r#"{{~#*inline "displayName"~}}
543 Template:{{name}}
544 {{/inline}}
545 {{#each data as |name|}}
546 Name:{{name}}
547 {{>displayName name="aaaa"}}
548 {{/each}}"#,
549 )
550 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
551
552 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
553 "t1",
554 r#"{{~#*inline "displayName"~}}
555 Template:{{this}}
556 {{/inline}}
557 {{#each data as |name|}}
558 Name:{{name}}
559 {{>displayName}}
560 {{/each}}"#,
561 )
562 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
563
564 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
565 "data": ["hudel", "test"]
566 });
567
568 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
569 r#"Name:hudel
570 Template:hudel
571 Name:test
572 Template:test
573 "#,
574 hb.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
575 );
576 }
577
578 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
579 fn test_multiline_partial_indentrust-analyzer cargo handlebars 5.1.2 partial/test/test_multiline_partial_indent().() {
580 let mut hb = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
581
582 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
583 "t1",
584 r#"{{#*inline "thepartial"}}
585 inner first line
586 inner second line
587 {{/inline}}
588 {{> thepartial}}
589 outer third line"#,
590 )
591 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
592 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
593 r#" inner first line
594 inner second line
595 outer third line"#,
596 hb.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
597 );
598
599 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
600 "t2",
601 r#"{{#*inline "thepartial"}}inner first line
602 inner second line
603 {{/inline}}
604 {{> thepartial}}
605 outer third line"#,
606 )
607 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
608 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
609 r#" inner first line
610 inner second line
611 outer third line"#,
612 hb.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t2", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
613 );
614
615 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
616 "t3",
617 r#"{{#*inline "thepartial"}}{{a}}{{/inline}}
618 {{> thepartial}}
619 outer third line"#,
620 )
621 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
622 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
623 r#"
624 inner first line
625 inner second lineouter third line"#,
626 hb.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t3", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"a": "inner first line\ninner second line"}))
627 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
628 );
629
630 hb.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
631 "t4",
632 r#"{{#*inline "thepartial"}}
633 inner first line
634 inner second line
635 {{/inline}}
636 {{~> thepartial}}
637 outer third line"#,
638 )
639 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
640 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
641 r#" inner first line
642 inner second line
643 outer third line"#,
644 hb.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t4", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
645 );
646
647 let mut hb2 = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
648 hb2.set_prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_prevent_indent().(true);
649
650 hb2.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(
651 "t1",
652 r#"{{#*inline "thepartial"}}
653 inner first line
654 inner second line
655 {{/inline}}
656 {{> thepartial}}
657 outer third line"#,
658 )
659 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
660 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
661 r#" inner first line
662 inner second line
663 outer third line"#,
664 hb2.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
665 )
666 }
667
668 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
669 fn test_issue_534rust-analyzer cargo handlebars 5.1.2 partial/test/test_issue_534().() {
670 let t1 = "{{title}}";
671 let t2 = "{{#each modules}}{{> (lookup this \"module\") content name=0}}{{/each}}";
672
673 let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({
674 "modules": [
675 {"module": "t1", "content": {"title": "foo"}},
676 {"module": "t1", "content": {"title": "bar"}},
677 ]
678 });
679
680 let mut hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
681 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t1", t1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
682 hbs.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t2", t2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
683
684 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foobar", hbs.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t2", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
685 }
686
687 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
688 fn test_partial_not_foundrust-analyzer cargo handlebars 5.1.2 partial/test/test_partial_not_found().() {
689 let t1 = "{{> bar}}";
690 let hbs = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().();
691 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(hbs.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(&t1, &()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
692 }
693 }