| 1 | use superrust-analyzer cargo handlebars 5.1.2 helpers/::block_utilrust-analyzer cargo handlebars 5.1.2 helpers/block_util/::create_blockrust-analyzer cargo handlebars 5.1.2 helpers/block_util/create_block().; |
| 2 | use craterust-analyzer cargo handlebars 5.1.2 crate/::blockrust-analyzer cargo handlebars 5.1.2 block/::BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#; |
| 3 | 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#; |
| 4 | 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#; |
| 5 | use craterust-analyzer cargo handlebars 5.1.2 crate/::helpersrust-analyzer cargo handlebars 5.1.2 helpers/::{HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef#, HelperResultrust-analyzer cargo handlebars 5.1.2 helpers/HelperResult#}; |
| 6 | use craterust-analyzer cargo handlebars 5.1.2 crate/::jsonrust-analyzer cargo handlebars 5.1.2 json/::valuerust-analyzer cargo handlebars 5.1.2 json/value/::JsonTruthyrust-analyzer cargo handlebars 5.1.2 json/value/JsonTruthy#; |
| 7 | 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#; |
| 8 | 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#; |
| 9 | 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#, Renderablerust-analyzer cargo handlebars 5.1.2 render/Renderable#}; |
| 10 | use craterust-analyzer cargo handlebars 5.1.2 crate/::RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#; |
| 11 | |
| 12 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 13 | pub struct WithHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/WithHelper#; |
| 14 | |
| 15 | impl HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# for WithHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/WithHelper# { |
| 16 | fn callrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/impl#[WithHelper][HelperDef]call().<'reg: 'rc, 'rc>( |
| 17 | &self, |
| 18 | h: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'rc>, |
| 19 | r: &'reg Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg>, |
| 20 | ctx: &'rc Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 21 | rc: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'reg, 'rc>, |
| 22 | out: &mut dyn Outputrust-analyzer cargo handlebars 5.1.2 output/Output#, |
| 23 | ) -> HelperResultrust-analyzer cargo handlebars 5.1.2 helpers/HelperResult# { |
| 24 | let param = h |
| 25 | .paramrust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]param().(0) |
| 26 | .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::ParamNotFoundForIndexrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#ParamNotFoundForIndex#("with", 0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 27 | |
| 28 | if param.valuerust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]value().().is_truthyrust-analyzer cargo handlebars 5.1.2 json/value/impl#[Json][JsonTruthy]is_truthy().(false) { |
| 29 | let mut block = create_blockrust-analyzer cargo handlebars 5.1.2 helpers/block_util/create_block().(param); |
| 30 | |
| 31 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(block_param) = h.block_paramrust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]block_param().() { |
| 32 | let mut params = BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#::newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]new().(); |
| 33 | if param.context_pathrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]context_path().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 34 | params.add_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_path().(block_param, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 35 | } else { |
| 36 | params.add_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_value().(block_param, param.valuerust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]value().().clonerust-analyzer cargo serde_json 1.0.114 value/impl#[Value][Clone]clone().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 37 | } |
| 38 | |
| 39 | block.set_block_paramsrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_block_params().(params); |
| 40 | } |
| 41 | |
| 42 | rc.push_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]push_block().(block); |
| 43 | |
| 44 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = h.templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]template().() { |
| 45 | t.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(r, ctx, rc, out)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 46 | }; |
| 47 | |
| 48 | rc.pop_blockrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]pop_block().(); |
| 49 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 50 | } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = h.inverserust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]inverse().() { |
| 51 | t.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(r, ctx, rc, out) |
| 52 | } else if r.strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]strict_mode().() { |
| 53 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::strict_errorrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError]strict_error().(param.relative_pathrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]relative_path().())) |
| 54 | } else { |
| 55 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | pub static WITH_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/WITH_HELPER.: WithHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/WithHelper# = WithHelperrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/WithHelper#; |
| 61 | |
| 62 | #[cfg(test)] |
| 63 | mod testrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/ { |
| 64 | 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#; |
| 65 | |
| 66 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:)] |
| 67 | struct Addressrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address# { |
| 68 | cityrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#city.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 69 | countryrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#country.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 70 | } |
| 71 | |
| 72 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:)] |
| 73 | struct Personrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person# { |
| 74 | namerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 75 | agerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#age.: i16, |
| 76 | addrrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#addr.: Addressrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#, |
| 77 | titlesrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#titles.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 78 | } |
| 79 | |
| 80 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 81 | fn test_withrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_with().() { |
| 82 | let addr = Addressrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address# { |
| 83 | cityrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#city.: "Beijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 84 | countryrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#country.: "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 85 | }; |
| 86 | |
| 87 | let person = Personrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person# { |
| 88 | namerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#name.: "Ning Sun".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 89 | agerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#age.: 27, |
| 90 | addrrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#addr., |
| 91 | titlesrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#titles.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["programmer".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "cartographier".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 92 | }; |
| 93 | |
| 94 | let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 95 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 96 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#with addr}}{{city}}{{/with}}") |
| 97 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 98 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 99 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t1", "{{#with notfound}}hello{{else}}world{{/with}}") |
| 100 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 101 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 102 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t2", "{{#with addr/country}}{{this}}{{/with}}") |
| 103 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 104 | |
| 105 | let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &person); |
| 106 | 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().(), "Beijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 107 | |
| 108 | let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &person); |
| 109 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.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().(), "world".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 110 | |
| 111 | let r2 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t2", &person); |
| 112 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r2.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().(), "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 113 | } |
| 114 | |
| 115 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 116 | fn test_with_block_paramrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_with_block_param().() { |
| 117 | let addr = Addressrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address# { |
| 118 | cityrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#city.: "Beijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 119 | countryrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#country.: "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 120 | }; |
| 121 | |
| 122 | let person = Personrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person# { |
| 123 | namerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#name.: "Ning Sun".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 124 | agerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#age.: 27, |
| 125 | addrrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#addr., |
| 126 | titlesrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#titles.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["programmer".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "cartographier".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 127 | }; |
| 128 | |
| 129 | let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 130 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 131 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#with addr as |a|}}{{a.city}}{{/with}}") |
| 132 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 133 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 134 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t1", "{{#with notfound as |c|}}hello{{else}}world{{/with}}") |
| 135 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 136 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 137 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t2", "{{#with addr/country as |t|}}{{t}}{{/with}}") |
| 138 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 139 | |
| 140 | let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &person); |
| 141 | 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().(), "Beijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 142 | |
| 143 | let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &person); |
| 144 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.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().(), "world".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 145 | |
| 146 | let r2 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t2", &person); |
| 147 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r2.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().(), "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 148 | } |
| 149 | |
| 150 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 151 | fn test_with_in_eachrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_with_in_each().() { |
| 152 | let addr = Addressrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address# { |
| 153 | cityrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#city.: "Beijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 154 | countryrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#country.: "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 155 | }; |
| 156 | |
| 157 | let person = Personrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person# { |
| 158 | namerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#name.: "Ning Sun".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 159 | agerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#age.: 27, |
| 160 | addrrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#addr., |
| 161 | titlesrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#titles.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["programmer".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "cartographier".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 162 | }; |
| 163 | |
| 164 | let addr2 = Addressrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address# { |
| 165 | cityrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#city.: "Beijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 166 | countryrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Address#country.: "China".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 167 | }; |
| 168 | |
| 169 | let person2 = Personrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person# { |
| 170 | namerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#name.: "Ning Sun".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 171 | agerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#age.: 27, |
| 172 | addrrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#addr.: addr2, |
| 173 | titlesrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/Person#titles.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["programmer".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "cartographier".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()], |
| 174 | }; |
| 175 | |
| 176 | let people = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![person, person2]; |
| 177 | |
| 178 | let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 179 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 180 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().( |
| 181 | "t0", |
| 182 | "{{#each this}}{{#with addr}}{{city}}{{/with}}{{/each}}" |
| 183 | ) |
| 184 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 185 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 186 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().( |
| 187 | "t1", |
| 188 | "{{#each this}}{{#with addr}}{{../age}}{{/with}}{{/each}}" |
| 189 | ) |
| 190 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 191 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 192 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().( |
| 193 | "t2", |
| 194 | "{{#each this}}{{#with addr}}{{@../index}}{{/with}}{{/each}}" |
| 195 | ) |
| 196 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 197 | |
| 198 | let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &people); |
| 199 | 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().(), "BeijingBeijing".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 200 | |
| 201 | let r1 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &people); |
| 202 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r1.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().(), "2727".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 203 | |
| 204 | let r2 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t2", &people); |
| 205 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r2.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().(), "01".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 206 | } |
| 207 | |
| 208 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 209 | fn test_path_uprust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_path_up().() { |
| 210 | let mut handlebars = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 211 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(handlebars |
| 212 | .register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#with a}}{{#with b}}{{../../d}}{{/with}}{{/with}}") |
| 213 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 214 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 215 | "a": { |
| 216 | "b": [{"c": [1]}] |
| 217 | }, |
| 218 | "d": 1 |
| 219 | }); |
| 220 | |
| 221 | let r0 = handlebars.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t0", &data); |
| 222 | 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().(), "1".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 223 | } |
| 224 | |
| 225 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 226 | fn test_else_contextrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_else_context().() { |
| 227 | let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 228 | let template = "{{#with list}}A{{else}}{{foo}}{{/with}}"; |
| 229 | let input = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"list": [], "foo": "bar"}); |
| 230 | let rendered = reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 231 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("bar", rendered); |
| 232 | } |
| 233 | |
| 234 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 235 | fn test_derived_valuerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_derived_value().() { |
| 236 | let hb = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 237 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"a": {"b": {"c": "d"}}}); |
| 238 | let template = "{{#with (lookup a.b \"c\")}}{{this}}{{/with}}"; |
| 239 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("d", hb.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 240 | } |
| 241 | |
| 242 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 243 | fn test_nested_derived_valuerust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_nested_derived_value().() { |
| 244 | let hb = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 245 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"a": {"b": {"c": "d"}}}); |
| 246 | let template = "{{#with (lookup a \"b\")}}{{#with this}}{{c}}{{/with}}{{/with}}"; |
| 247 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("d", hb.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(template, &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 248 | } |
| 249 | |
| 250 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 251 | fn test_strict_withrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/test/test_strict_with().() { |
| 252 | let mut hb = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 253 | |
| 254 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 255 | hb.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#with name}}yes{{/with}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})) |
| 256 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 257 | "" |
| 258 | ); |
| 259 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 260 | hb.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#with name}}yes{{else}}no{{/with}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})) |
| 261 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 262 | "no" |
| 263 | ); |
| 264 | |
| 265 | hb.set_strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_strict_mode().(true); |
| 266 | |
| 267 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(hb |
| 268 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#with name}}yes{{/with}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})) |
| 269 | .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 270 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 271 | hb.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{#with name}}yes{{else}}no{{/with}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({})) |
| 272 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 273 | "no" |
| 274 | ); |
| 275 | } |
| 276 | } |