1 use crate::context
::Context
;
2 use crate::decorators
::{DecoratorDef, DecoratorResult}
;
3 use crate::error
::RenderError
;
4 use crate::registry
::Registry
;
5 use crate::render
::{Decorator, RenderContext}
;
8 pub struct InlineDecorator
;
10 fn get_name
<'reg
: 'rc
, 'rc
>(d
: &'rc Decorator
<'reg
, 'rc
>) -> Result
<&'rc
str, RenderError
> {
12 .ok_or_else(|| RenderError
::new("Param required for decorator \"inline\""))
16 .ok_or_else(|| RenderError
::new("inline name must be string"))
20 impl DecoratorDef
for InlineDecorator
{
21 fn call
<'reg
: 'rc
, 'rc
>(
23 d
: &Decorator
<'reg
, 'rc
>,
24 _
: &'reg Registry
<'reg
>,
26 rc
: &mut RenderContext
<'reg
, 'rc
>,
27 ) -> DecoratorResult
{
28 let name
= get_name(d
)?
;
32 .ok_or_else(|| RenderError
::new("inline should have a block"))?
;
34 rc
.set_partial(name
.to_owned(), template
);
39 pub static INLINE_DECORATOR
: InlineDecorator
= InlineDecorator
;
43 use crate::context
::Context
;
44 use crate::registry
::Registry
;
45 use crate::render
::{Evaluable, RenderContext}
;
46 use crate::template
::Template
;
50 let t0
= Template
::compile(
51 "{{#*inline \"hello\"}}the hello world inline partial.{{/inline}}".to_string(),
56 let hbs
= Registry
::new();
58 let ctx
= Context
::null();
59 let mut rc
= RenderContext
::new(None
);
60 t0
.elements
[0].eval(&hbs
, &ctx
, &mut rc
).unwrap();
62 assert
!(rc
.get_partial(&"hello".to_owned()).is_some());