| 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 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#}; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error# as IoErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 7 | |
| 8 | use serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#; |
| 9 | |
| 10 | 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#; |
| 11 | use craterust-analyzer cargo handlebars 5.1.2 crate/::decoratorsrust-analyzer cargo handlebars 5.1.2 decorators/::{selfrust-analyzer cargo handlebars 5.1.2 decorators/, DecoratorDefrust-analyzer cargo handlebars 5.1.2 decorators/DecoratorDef#}; |
| 12 | #[cfg(feature = "script_helper")] |
| 13 | use craterust-analyzer cargo handlebars 5.1.2 crate/::errorrust-analyzer cargo handlebars 5.1.2 error/::ScriptErrorrust-analyzer cargo handlebars 5.1.2 error/ScriptError#; |
| 14 | 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#, RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#, TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#}; |
| 15 | use craterust-analyzer cargo handlebars 5.1.2 crate/::helpersrust-analyzer cargo handlebars 5.1.2 helpers/::{selfrust-analyzer cargo handlebars 5.1.2 helpers/, HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef#}; |
| 16 | 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#, StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput#, WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#}; |
| 17 | use craterust-analyzer cargo handlebars 5.1.2 crate/::renderrust-analyzer cargo handlebars 5.1.2 render/::{RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#, Renderablerust-analyzer cargo handlebars 5.1.2 render/Renderable#}; |
| 18 | use craterust-analyzer cargo handlebars 5.1.2 crate/::sourcesrust-analyzer cargo handlebars 5.1.2 sources/::{FileSourcerust-analyzer cargo handlebars 5.1.2 sources/FileSource#, Sourcerust-analyzer cargo handlebars 5.1.2 sources/Source#}; |
| 19 | use craterust-analyzer cargo handlebars 5.1.2 crate/::supportrust-analyzer cargo handlebars 5.1.2 support/::strrust-analyzer cargo handlebars 5.1.2 support/str/::{selfrust-analyzer cargo handlebars 5.1.2 support/str/, StringWriterrust-analyzer cargo handlebars 5.1.2 support/str/StringWriter#}; |
| 20 | 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#, TemplateOptionsrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions#}; |
| 21 | |
| 22 | #[cfg(feature = "dir_source")] |
| 23 | use walkdirrust-analyzer cargo walkdir 2.5.0 crate/::WalkDirrust-analyzer cargo walkdir 2.5.0 WalkDir#; |
| 24 | |
| 25 | #[cfg(feature = "script_helper")] |
| 26 | use rhairust-analyzer cargo rhai 1.17.1 crate/::Enginerust-analyzer cargo rhai 1.17.1 engine/Engine#; |
| 27 | |
| 28 | #[cfg(feature = "script_helper")] |
| 29 | use craterust-analyzer cargo handlebars 5.1.2 crate/::helpersrust-analyzer cargo handlebars 5.1.2 helpers/::scriptingrust-analyzer cargo handlebars 5.1.2 helpers/scripting/::ScriptHelperrust-analyzer cargo handlebars 5.1.2 helpers/scripting/ScriptHelper#; |
| 30 | |
| 31 | #[cfg(feature = "rust-embed")] |
| 32 | use craterust-analyzer cargo handlebars 5.1.2 crate/::sourcesrust-analyzer cargo handlebars 5.1.2 sources/::LazySourcerust-analyzer cargo handlebars 5.1.2 sources/LazySource#; |
| 33 | #[cfg(feature = "rust-embed")] |
| 34 | use rust_embedrust-analyzer cargo rust-embed 8.3.0 crate/::RustEmbedrust-analyzer cargo rust-embed 8.3.0 RustEmbed#; |
| 35 | |
| 36 | /// This type represents an *escape fn*, that is a function whose purpose it is |
| 37 | /// to escape potentially problematic characters in a string. |
| 38 | /// |
| 39 | /// An *escape fn* is represented as a `Box` to avoid unnecessary type |
| 40 | /// parameters (and because traits cannot be aliased using `type`). |
| 41 | pub type EscapeFnrust-analyzer cargo handlebars 5.1.2 registry/EscapeFn# = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>; |
| 42 | |
| 43 | /// The default *escape fn* replaces the characters `&"<>` |
| 44 | /// with the equivalent html / xml entities. |
| 45 | pub fn html_escaperust-analyzer cargo handlebars 5.1.2 registry/html_escape().(data: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 46 | strrust-analyzer cargo handlebars 5.1.2 support/str/::escape_htmlrust-analyzer cargo handlebars 5.1.2 support/str/escape_html().(data) |
| 47 | } |
| 48 | |
| 49 | /// `EscapeFn` that does not change anything. Useful when using in a non-html |
| 50 | /// environment. |
| 51 | pub fn no_escaperust-analyzer cargo handlebars 5.1.2 registry/no_escape().(data: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 52 | data.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().() |
| 53 | } |
| 54 | |
| 55 | /// The single entry point of your Handlebars templates |
| 56 | /// |
| 57 | /// It maintains compiled templates and registered helpers. |
| 58 | #[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:)] |
| 59 | pub struct Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg> { |
| 60 | templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Templaterust-analyzer cargo handlebars 5.1.2 template/Template#>, |
| 61 | |
| 62 | helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg>>, |
| 63 | decoratorsrust-analyzer cargo handlebars 5.1.2 registry/Registry#decorators.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn DecoratorDefrust-analyzer cargo handlebars 5.1.2 decorators/DecoratorDef# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg>>, |
| 64 | |
| 65 | escape_fnrust-analyzer cargo handlebars 5.1.2 registry/Registry#escape_fn.: EscapeFnrust-analyzer cargo handlebars 5.1.2 registry/EscapeFn#, |
| 66 | strict_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#strict_mode.: bool, |
| 67 | dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode.: bool, |
| 68 | prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent.: bool, |
| 69 | #[cfg(feature = "script_helper")] |
| 70 | pub(craterust-analyzer cargo handlebars 5.1.2 crate/) enginerust-analyzer cargo handlebars 5.1.2 registry/Registry#engine.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Enginerust-analyzer cargo rhai 1.17.1 engine/Engine#>, |
| 71 | |
| 72 | template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources.: |
| 73 | HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Sourcerust-analyzer cargo handlebars 5.1.2 sources/Source#<Itemrust-analyzer cargo handlebars 5.1.2 sources/Source#Item# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Errorrust-analyzer cargo handlebars 5.1.2 sources/Source#Error# = IoErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg>>, |
| 74 | #[cfg(feature = "script_helper")] |
| 75 | script_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#script_sources.: |
| 76 | HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Sourcerust-analyzer cargo handlebars 5.1.2 sources/Source#<Itemrust-analyzer cargo handlebars 5.1.2 sources/Source#Item# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Errorrust-analyzer cargo handlebars 5.1.2 sources/Source#Error# = IoErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg>>, |
| 77 | } |
| 78 | |
| 79 | impl<'reg> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg> { |
| 80 | fn fmtrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 81 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("Handlebars") |
| 82 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("templates", &self.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates.) |
| 83 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("helpers", &self.helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers..keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().()) |
| 84 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("decorators", &self.decoratorsrust-analyzer cargo handlebars 5.1.2 registry/Registry#decorators..keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().()) |
| 85 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("strict_mode", &self.strict_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#strict_mode.) |
| 86 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("dev_mode", &self.dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode.) |
| 87 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | impl<'reg> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg> { |
| 92 | fn defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`][Default]default().() -> Selfrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`][Default] { |
| 93 | Selfrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`][Default]::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().() |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | #[cfg(feature = "script_helper")] |
| 98 | fn rhai_enginerust-analyzer cargo handlebars 5.1.2 registry/rhai_engine().() -> Enginerust-analyzer cargo rhai 1.17.1 engine/Engine# { |
| 99 | Enginerust-analyzer cargo rhai 1.17.1 engine/Engine#::newrust-analyzer cargo rhai 1.17.1 engine/impl#[Engine]new().() |
| 100 | } |
| 101 | |
| 102 | /// Options for importing template files from a directory. |
| 103 | #[cfg(feature = "dir_source")] |
| 104 | pub struct DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions# { |
| 105 | /// The name extension for template files |
| 106 | pub tpl_extensionrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#tpl_extension.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 107 | /// Whether to include hidden files (file name that starts with `.`) |
| 108 | pub hiddenrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#hidden.: bool, |
| 109 | /// Whether to include temporary files (file name that starts with `#`) |
| 110 | pub temporaryrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#temporary.: bool, |
| 111 | } |
| 112 | |
| 113 | #[cfg(feature = "dir_source")] |
| 114 | impl DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions# { |
| 115 | fn ignore_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions]ignore_file().(&self, name: &str) -> bool { |
| 116 | self.ignored_as_hidden_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions]ignored_as_hidden_file().(name) || self.ignored_as_temporary_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions]ignored_as_temporary_file().(name) |
| 117 | } |
| 118 | |
| 119 | #[inline] |
| 120 | fn ignored_as_hidden_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions]ignored_as_hidden_file().(&self, name: &str) -> bool { |
| 121 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.hiddenrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#hidden. && name.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('.') |
| 122 | } |
| 123 | |
| 124 | #[inline] |
| 125 | fn ignored_as_temporary_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions]ignored_as_temporary_file().(&self, name: &str) -> bool { |
| 126 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.temporaryrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#temporary. && name.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('#') |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | #[cfg(feature = "dir_source")] |
| 131 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions# { |
| 132 | fn defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default]default().() -> Selfrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default] { |
| 133 | DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions# { |
| 134 | tpl_extensionrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#tpl_extension.: ".hbs".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 135 | hiddenrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#hidden.: false, |
| 136 | temporaryrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#temporary.: false, |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | impl<'reg> Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg> { |
| 142 | pub fn newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().() -> Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg> { |
| 143 | let r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry# { |
| 144 | templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(), |
| 145 | template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(), |
| 146 | helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(), |
| 147 | decoratorsrust-analyzer cargo handlebars 5.1.2 registry/Registry#decorators.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(), |
| 148 | escape_fnrust-analyzer cargo handlebars 5.1.2 registry/Registry#escape_fn.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(html_escaperust-analyzer cargo handlebars 5.1.2 registry/html_escape().), |
| 149 | strict_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#strict_mode.: false, |
| 150 | dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode.: false, |
| 151 | prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent.: false, |
| 152 | #[cfg(feature = "script_helper")] |
| 153 | enginerust-analyzer cargo handlebars 5.1.2 registry/Registry#engine.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(rhai_enginerust-analyzer cargo handlebars 5.1.2 registry/rhai_engine().()), |
| 154 | #[cfg(feature = "script_helper")] |
| 155 | script_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#script_sources.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(), |
| 156 | }; |
| 157 | |
| 158 | r.setup_builtinsrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]setup_builtins().() |
| 159 | } |
| 160 | |
| 161 | fn setup_builtinsrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]setup_builtins().(mut self) -> Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg> { |
| 162 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("if", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::IF_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_if/IF_HELPER.)); |
| 163 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("unless", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::UNLESS_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_if/UNLESS_HELPER.)); |
| 164 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("each", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::EACH_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_each/EACH_HELPER.)); |
| 165 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("with", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::WITH_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_with/WITH_HELPER.)); |
| 166 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("lookup", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::LOOKUP_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_lookup/LOOKUP_HELPER.)); |
| 167 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("raw", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::RAW_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_raw/RAW_HELPER.)); |
| 168 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("log", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::LOG_HELPERrust-analyzer cargo handlebars 5.1.2 helpers/helper_log/LOG_HELPER.)); |
| 169 | |
| 170 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("eq", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::eqrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/eq#)); |
| 171 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("ne", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::nerust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/ne#)); |
| 172 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("gt", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::gtrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/gt#)); |
| 173 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("gte", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::gterust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/gte#)); |
| 174 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("lt", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::ltrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/lt#)); |
| 175 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("lte", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::lterust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/lte#)); |
| 176 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("and", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::andrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/and#)); |
| 177 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("or", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::orrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/or#)); |
| 178 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("not", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::notrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/not#)); |
| 179 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("len", 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().(helpersrust-analyzer cargo handlebars 5.1.2 helpers/::helper_extrasrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/::lenrust-analyzer cargo handlebars 5.1.2 helpers/helper_extras/len#)); |
| 180 | |
| 181 | #[cfg(feature = "string_helpers")] |
| 182 | self.register_string_helpersrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_string_helpers().(); |
| 183 | |
| 184 | self.register_decoratorrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_decorator().("inline", 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().(decoratorsrust-analyzer cargo handlebars 5.1.2 decorators/::INLINE_DECORATORrust-analyzer cargo handlebars 5.1.2 decorators/inline/INLINE_DECORATOR.)); |
| 185 | self |
| 186 | } |
| 187 | |
| 188 | /// Enable or disable handlebars strict mode |
| 189 | /// |
| 190 | /// By default, handlebars renders empty string for value that |
| 191 | /// undefined or never exists. Since rust is a static type |
| 192 | /// language, we offer strict mode in handlebars-rust. In strict |
| 193 | /// mode, if you were to render a value that doesn't exist, a |
| 194 | /// `RenderError` will be raised. |
| 195 | pub fn set_strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_strict_mode().(&mut self, enabled: bool) { |
| 196 | self.strict_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#strict_mode. = enabled; |
| 197 | } |
| 198 | |
| 199 | /// Return strict mode state, default is false. |
| 200 | /// |
| 201 | /// By default, handlebars renders empty string for value that |
| 202 | /// undefined or never exists. Since rust is a static type |
| 203 | /// language, we offer strict mode in handlebars-rust. In strict |
| 204 | /// mode, if you were access a value that doesn't exist, a |
| 205 | /// `RenderError` will be raised. |
| 206 | pub fn strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]strict_mode().(&self) -> bool { |
| 207 | self.strict_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#strict_mode. |
| 208 | } |
| 209 | |
| 210 | /// Return dev mode state, default is false |
| 211 | /// |
| 212 | /// With dev mode turned on, handlebars enables a set of development |
| 213 | /// friendly features, that may affect its performance. |
| 214 | pub fn dev_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]dev_mode().(&self) -> bool { |
| 215 | self.dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode. |
| 216 | } |
| 217 | |
| 218 | /// Enable or disable dev mode |
| 219 | /// |
| 220 | /// With dev mode turned on, handlebars enables a set of development |
| 221 | /// friendly features, that may affect its performance. |
| 222 | /// |
| 223 | /// **Note that you have to enable dev mode before adding templates to |
| 224 | /// the registry**. Otherwise it won't take effect at all. |
| 225 | pub fn set_dev_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_dev_mode().(&mut self, enabled: bool) { |
| 226 | self.dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode. = enabled; |
| 227 | |
| 228 | // clear template source when disabling dev mode |
| 229 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().enabled { |
| 230 | self.template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources..clearrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]clear().(); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /// Enable or disable indent for partial include tag `{{>}}` |
| 235 | /// |
| 236 | /// By default handlebars keeps indent whitespaces for partial |
| 237 | /// include tag, to change this behaviour, set this toggle to `true`. |
| 238 | pub fn set_prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_prevent_indent().(&mut self, enable: bool) { |
| 239 | self.prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent. = enable; |
| 240 | } |
| 241 | |
| 242 | /// Return state for `prevent_indent` option, default to `false`. |
| 243 | pub fn prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]prevent_indent().(&self) -> bool { |
| 244 | self.prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent. |
| 245 | } |
| 246 | |
| 247 | /// Register a `Template` |
| 248 | /// |
| 249 | /// This is infallible since the template has already been parsed and |
| 250 | /// insert cannot fail. If there is an existing template with this name it |
| 251 | /// will be overwritten. |
| 252 | /// |
| 253 | /// Dev mode doesn't apply for pre-compiled template because it's lifecycle |
| 254 | /// is not managed by the registry. |
| 255 | pub fn register_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template().(&mut self, name: &str, tpl: Templaterust-analyzer cargo handlebars 5.1.2 template/Template#) { |
| 256 | self.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), tpl); |
| 257 | } |
| 258 | |
| 259 | /// Register a template string |
| 260 | /// |
| 261 | /// Returns `TemplateError` if there is syntax error on parsing the template. |
| 262 | pub fn register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().<S>( |
| 263 | &mut self, |
| 264 | name: &str, |
| 265 | tpl_str: S, |
| 266 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#> |
| 267 | where |
| 268 | S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 269 | { |
| 270 | let template = Templaterust-analyzer cargo handlebars 5.1.2 template/Template#::compile2rust-analyzer cargo handlebars 5.1.2 template/impl#[Template]compile2().( |
| 271 | tpl_str.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(), |
| 272 | TemplateOptionsrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions# { |
| 273 | namerust-analyzer cargo handlebars 5.1.2 template/TemplateOptions#name.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()), |
| 274 | prevent_indentrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions#prevent_indent.: self.prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent., |
| 275 | }, |
| 276 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 277 | self.register_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template().(name, template); |
| 278 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 279 | } |
| 280 | |
| 281 | /// Register a partial string |
| 282 | /// |
| 283 | /// A named partial will be added to the registry. It will overwrite template with |
| 284 | /// same name. Currently a registered partial is just identical to a template. |
| 285 | pub fn register_partialrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_partial().<S>(&mut self, name: &str, partial_str: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#> |
| 286 | where |
| 287 | S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>, |
| 288 | { |
| 289 | self.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(name, partial_str) |
| 290 | } |
| 291 | |
| 292 | /// Register a template from a path on file system |
| 293 | /// |
| 294 | /// If dev mode is enabled, the registry will keep reading the template file |
| 295 | /// from file system everytime it's visited. |
| 296 | pub fn register_template_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_file().<P>( |
| 297 | &mut self, |
| 298 | name: &str, |
| 299 | tpl_path: P, |
| 300 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#> |
| 301 | where |
| 302 | P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, |
| 303 | { |
| 304 | let source = FileSourcerust-analyzer cargo handlebars 5.1.2 sources/FileSource#::newrust-analyzer cargo handlebars 5.1.2 sources/impl#[FileSource]new().(tpl_path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 305 | let template_string = source |
| 306 | .loadrust-analyzer cargo handlebars 5.1.2 sources/impl#[FileSource][Source]load().() |
| 307 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[TemplateError][`From<(IOError, String)>`]from().((err, name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 308 | |
| 309 | self.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(name, template_string)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 310 | if self.dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode. { |
| 311 | self.template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources. |
| 312 | .insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(source)); |
| 313 | } |
| 314 | |
| 315 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 316 | } |
| 317 | |
| 318 | /// Register templates from a directory |
| 319 | /// |
| 320 | /// * `tpl_extension`: the template file extension |
| 321 | /// * `dir_path`: the path of directory |
| 322 | /// |
| 323 | /// Hidden files and tempfile (starts with `#`) will be ignored by default. |
| 324 | /// Set `DirectorySourceOptions` to something other than `DirectorySourceOptions::default()` to adjust this. |
| 325 | /// All registered templates will use their relative path to determine their template name. |
| 326 | /// For example, when `dir_path` is `templates/` and `DirectorySourceOptions.tpl_extension` is `.hbs`, the file |
| 327 | /// `templates/some/path/file.hbs` will be registered as `some/path/file`. |
| 328 | /// |
| 329 | /// This method is not available by default. |
| 330 | /// You will need to enable the `dir_source` feature to use it. |
| 331 | /// |
| 332 | /// When dev_mode is enabled, like with `register_template_file`, templates are reloaded |
| 333 | /// from the file system every time they're visited. |
| 334 | #[cfg(feature = "dir_source")] |
| 335 | #[cfg_attr(docsrs, doc(cfg(feature = "dir_source")))] |
| 336 | pub fn register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_templates_directory().<P>( |
| 337 | &mut self, |
| 338 | dir_path: P, |
| 339 | options: DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#, |
| 340 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#> |
| 341 | where |
| 342 | P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, |
| 343 | { |
| 344 | let dir_path = dir_path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 345 | |
| 346 | let walker = WalkDirrust-analyzer cargo walkdir 2.5.0 WalkDir#::newrust-analyzer cargo walkdir 2.5.0 impl#[WalkDir]new().(dir_path); |
| 347 | let dir_iter = walker |
| 348 | .min_depthrust-analyzer cargo walkdir 2.5.0 impl#[WalkDir]min_depth().(1) |
| 349 | .into_iterrust-analyzer cargo walkdir 2.5.0 impl#[WalkDir][IntoIterator]into_iter().() |
| 350 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|e| e.okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|e| e.into_pathrust-analyzer cargo walkdir 2.5.0 dent/impl#[DirEntry]into_path().())) |
| 351 | // Checks if extension matches |
| 352 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|tpl_path| { |
| 353 | tpl_path |
| 354 | .to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().() |
| 355 | .ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(options.tpl_extensionrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#tpl_extension..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) |
| 356 | }) |
| 357 | // Rejects any hidden or temporary files. |
| 358 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|tpl_path| { |
| 359 | tpl_path |
| 360 | .file_stemrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_stem().() |
| 361 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|stem| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().options.ignore_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions]ignore_file().(&stem.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().())) |
| 362 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false) |
| 363 | }) |
| 364 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|tpl_path| { |
| 365 | tpl_path |
| 366 | .strip_prefixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]strip_prefix().(dir_path) |
| 367 | .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 368 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|tpl_canonical_name| { |
| 369 | let tpl_name = tpl_canonical_name |
| 370 | .componentsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]components().() |
| 371 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|component| component.as_os_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[`Component<'a>`]as_os_str().().to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().()) |
| 372 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 373 | .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("/"); |
| 374 | |
| 375 | tpl_name |
| 376 | .strip_suffixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_suffix().(options.tpl_extensionrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#tpl_extension..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) |
| 377 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()) |
| 378 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(tpl_name) |
| 379 | }) |
| 380 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|tpl_canonical_name| (tpl_canonical_name, tpl_path)) |
| 381 | }); |
| 382 | |
| 383 | for (tpl_canonical_name, tpl_path) in dir_iter { |
| 384 | self.register_template_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_file().(&tpl_canonical_name, &tpl_path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 385 | } |
| 386 | |
| 387 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 388 | } |
| 389 | |
| 390 | /// Register templates using a |
| 391 | /// [RustEmbed](https://github.com/pyros2097/rust-embed) type |
| 392 | /// Calls register_embed_templates_with_extension with empty extension. |
| 393 | /// |
| 394 | /// File names from embed struct are used as template name. |
| 395 | /// |
| 396 | /// ```skip |
| 397 | /// #[derive(RustEmbed)] |
| 398 | /// #[folder = "templates"] |
| 399 | /// #[include = "*.hbs"] |
| 400 | /// struct Assets; |
| 401 | /// |
| 402 | /// let mut hbs = Handlebars::new(); |
| 403 | /// hbs.register_embed_templates::<Assets>(); |
| 404 | /// ``` |
| 405 | /// |
| 406 | #[cfg(feature = "rust-embed")] |
| 407 | #[cfg_attr(docsrs, doc(cfg(feature = "rust-embed")))] |
| 408 | pub fn register_embed_templatesrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_embed_templates().<E>(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#> |
| 409 | where |
| 410 | E: RustEmbedrust-analyzer cargo rust-embed 8.3.0 RustEmbed#, |
| 411 | { |
| 412 | self.register_embed_templates_with_extensionrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_embed_templates_with_extension().::<E>("") |
| 413 | } |
| 414 | |
| 415 | /// Register templates using a |
| 416 | /// [RustEmbed](https://github.com/pyros2097/rust-embed) type |
| 417 | /// * `tpl_extension`: the template file extension |
| 418 | /// |
| 419 | /// File names from embed struct are used as template name, but extension is stripped. |
| 420 | /// |
| 421 | /// When dev_mode enabled templates is reloaded |
| 422 | /// from embed struct everytime it's visied. |
| 423 | /// |
| 424 | /// ```skip |
| 425 | /// #[derive(RustEmbed)] |
| 426 | /// #[folder = "templates"] |
| 427 | /// struct Assets; |
| 428 | /// |
| 429 | /// let mut hbs = Handlebars::new(); |
| 430 | /// hbs.register_embed_templates_with_extension::<Assets>(".hbs"); |
| 431 | /// ``` |
| 432 | /// |
| 433 | #[cfg(feature = "rust-embed")] |
| 434 | #[cfg_attr(docsrs, doc(cfg(feature = "rust-embed")))] |
| 435 | pub fn register_embed_templates_with_extensionrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_embed_templates_with_extension().<E>( |
| 436 | &mut self, |
| 437 | tpl_extension: &str, |
| 438 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#> |
| 439 | where |
| 440 | E: RustEmbedrust-analyzer cargo rust-embed 8.3.0 RustEmbed#, |
| 441 | { |
| 442 | for file_name in E::iterrust-analyzer cargo rust-embed 8.3.0 RustEmbed#iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|x| x.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(tpl_extension)) { |
| 443 | let tpl_name = file_name |
| 444 | .strip_suffixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_suffix().(tpl_extension) |
| 445 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&file_name) |
| 446 | .to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 447 | let source = LazySourcerust-analyzer cargo handlebars 5.1.2 sources/LazySource#::newrust-analyzer cargo handlebars 5.1.2 sources/impl#[`LazySource<F>`]new().(move || { |
| 448 | E::getrust-analyzer cargo rust-embed 8.3.0 RustEmbed#get().(&file_name) |
| 449 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|file| file.datarust-analyzer cargo rust-embed-utils 8.3.0 EmbeddedFile#data..to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()) |
| 450 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|data| Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(data).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()) |
| 451 | }); |
| 452 | let tpl_content = source |
| 453 | .loadrust-analyzer cargo handlebars 5.1.2 sources/impl#[`LazySource<F>`][Source]load().() |
| 454 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| (e, "Template load error".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 455 | self.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().(&tpl_name, &tpl_content)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 456 | |
| 457 | if self.dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode. { |
| 458 | self.template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(tpl_name, Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(source)); |
| 459 | } |
| 460 | } |
| 461 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 462 | } |
| 463 | |
| 464 | /// Remove a template from the registry |
| 465 | pub fn unregister_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]unregister_template().(&mut self, name: &str) { |
| 466 | self.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(name); |
| 467 | self.template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources..removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(name); |
| 468 | } |
| 469 | |
| 470 | /// Register a helper |
| 471 | pub fn register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().(&mut self, name: &str, def: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg>) { |
| 472 | self.helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), def.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 473 | } |
| 474 | |
| 475 | /// Register a [rhai](https://docs.rs/rhai/) script as handlebars helper |
| 476 | /// |
| 477 | /// Currently only simple helpers are supported. You can do computation or |
| 478 | /// string formatting with rhai script. |
| 479 | /// |
| 480 | /// Helper parameters and hash are available in rhai script as array `params` |
| 481 | /// and map `hash`. Example script: |
| 482 | /// |
| 483 | /// ```handlebars |
| 484 | /// {{percent 0.34 label="%"}} |
| 485 | /// ``` |
| 486 | /// |
| 487 | /// ```rhai |
| 488 | /// // percent.rhai |
| 489 | /// let value = params[0]; |
| 490 | /// let label = hash["label"]; |
| 491 | /// |
| 492 | /// (value * 100).to_string() + label |
| 493 | /// ``` |
| 494 | /// |
| 495 | #[cfg(feature = "script_helper")] |
| 496 | #[cfg_attr(docsrs, doc(cfg(feature = "script_helper")))] |
| 497 | pub fn register_script_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_script_helper().(&mut self, name: &str, script: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ScriptErrorrust-analyzer cargo handlebars 5.1.2 error/ScriptError#> { |
| 498 | let compiled = self.enginerust-analyzer cargo handlebars 5.1.2 registry/Registry#engine..compilerust-analyzer cargo rhai 1.17.1 api/compile/impl#[Engine]compile().(script)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 499 | let script_helper = ScriptHelperrust-analyzer cargo handlebars 5.1.2 helpers/scripting/ScriptHelper# { scriptrust-analyzer cargo handlebars 5.1.2 helpers/scripting/ScriptHelper#script.: compiled }; |
| 500 | self.helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers. |
| 501 | .insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(script_helper)); |
| 502 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 503 | } |
| 504 | |
| 505 | /// Register a [rhai](https://docs.rs/rhai/) script from file |
| 506 | /// |
| 507 | /// When dev mode is enable, script file is reloaded from original file |
| 508 | /// everytime it is called. |
| 509 | #[cfg(feature = "script_helper")] |
| 510 | #[cfg_attr(docsrs, doc(cfg(feature = "script_helper")))] |
| 511 | pub fn register_script_helper_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_script_helper_file().<P>( |
| 512 | &mut self, |
| 513 | name: &str, |
| 514 | script_path: P, |
| 515 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ScriptErrorrust-analyzer cargo handlebars 5.1.2 error/ScriptError#> |
| 516 | where |
| 517 | P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, |
| 518 | { |
| 519 | let source = FileSourcerust-analyzer cargo handlebars 5.1.2 sources/FileSource#::newrust-analyzer cargo handlebars 5.1.2 sources/impl#[FileSource]new().(script_path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 520 | let script = source.loadrust-analyzer cargo handlebars 5.1.2 sources/impl#[FileSource][Source]load().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 521 | |
| 522 | self.script_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#script_sources. |
| 523 | .insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(source)); |
| 524 | self.register_script_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_script_helper().(name, &script) |
| 525 | } |
| 526 | |
| 527 | /// Borrow a read-only reference to current rhai engine |
| 528 | #[cfg(feature = "script_helper")] |
| 529 | #[cfg_attr(docsrs, doc(cfg(feature = "script_helper")))] |
| 530 | pub fn enginerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]engine().(&self) -> &Enginerust-analyzer cargo rhai 1.17.1 engine/Engine# { |
| 531 | self.enginerust-analyzer cargo handlebars 5.1.2 registry/Registry#engine..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][`AsRef<T>`]as_ref().() |
| 532 | } |
| 533 | |
| 534 | /// Set a custom rhai engine for the registry. |
| 535 | /// |
| 536 | /// *Note that* you need to set custom engine before adding scripts. |
| 537 | #[cfg(feature = "script_helper")] |
| 538 | #[cfg_attr(docsrs, doc(cfg(feature = "script_helper")))] |
| 539 | pub fn set_enginerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_engine().(&mut self, engine: Enginerust-analyzer cargo rhai 1.17.1 engine/Engine#) { |
| 540 | self.enginerust-analyzer cargo handlebars 5.1.2 registry/Registry#engine. = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(engine); |
| 541 | } |
| 542 | |
| 543 | /// Register a decorator |
| 544 | pub fn register_decoratorrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_decorator().( |
| 545 | &mut self, |
| 546 | name: &str, |
| 547 | def: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn DecoratorDefrust-analyzer cargo handlebars 5.1.2 decorators/DecoratorDef# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg>, |
| 548 | ) { |
| 549 | self.decoratorsrust-analyzer cargo handlebars 5.1.2 registry/Registry#decorators..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), def.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 550 | } |
| 551 | |
| 552 | /// Register a new *escape fn* to be used from now on by this registry. |
| 553 | pub fn register_escape_fnrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_escape_fn().<F: 'static + Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>( |
| 554 | &mut self, |
| 555 | escape_fn: F, |
| 556 | ) { |
| 557 | self.escape_fnrust-analyzer cargo handlebars 5.1.2 registry/Registry#escape_fn. = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(escape_fn); |
| 558 | } |
| 559 | |
| 560 | /// Restore the default *escape fn*. |
| 561 | pub fn unregister_escape_fnrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]unregister_escape_fn().(&mut self) { |
| 562 | self.escape_fnrust-analyzer cargo handlebars 5.1.2 registry/Registry#escape_fn. = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(html_escaperust-analyzer cargo handlebars 5.1.2 registry/html_escape().); |
| 563 | } |
| 564 | |
| 565 | /// Get a reference to the current *escape fn*. |
| 566 | pub fn get_escape_fnrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_escape_fn().(&self) -> &dyn Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 567 | self.escape_fnrust-analyzer cargo handlebars 5.1.2 registry/Registry#escape_fn..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][`AsRef<T>`]as_ref().() |
| 568 | } |
| 569 | |
| 570 | /// Return `true` if a template is registered for the given name |
| 571 | pub fn has_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]has_template().(&self, name: &str) -> bool { |
| 572 | self.get_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_template().(name).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 573 | } |
| 574 | |
| 575 | /// Return a registered template, |
| 576 | pub fn get_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_template().(&self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Templaterust-analyzer cargo handlebars 5.1.2 template/Template#> { |
| 577 | self.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name) |
| 578 | } |
| 579 | |
| 580 | #[inline] |
| 581 | pub(craterust-analyzer cargo handlebars 5.1.2 crate/) fn get_or_load_template_optionalrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_or_load_template_optional().( |
| 582 | &'reg self, |
| 583 | name: &str, |
| 584 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'reg, Templaterust-analyzer cargo handlebars 5.1.2 template/Template#>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#>> { |
| 585 | if let (true, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(source)) = (self.dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode., self.template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name)) { |
| 586 | let r = source |
| 587 | .loadrust-analyzer cargo handlebars 5.1.2 sources/Source#load().() |
| 588 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| TemplateErrorrust-analyzer cargo handlebars 5.1.2 error/TemplateError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[TemplateError][`From<(IOError, String)>`]from().((e, name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()))) |
| 589 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|tpl_str| { |
| 590 | Templaterust-analyzer cargo handlebars 5.1.2 template/Template#::compile2rust-analyzer cargo handlebars 5.1.2 template/impl#[Template]compile2().( |
| 591 | tpl_str.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AsRef<str>`]as_ref().(), |
| 592 | TemplateOptionsrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions# { |
| 593 | namerust-analyzer cargo handlebars 5.1.2 template/TemplateOptions#name.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()), |
| 594 | prevent_indentrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions#prevent_indent.: self.prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent., |
| 595 | }, |
| 596 | ) |
| 597 | }) |
| 598 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#) |
| 599 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<TemplateError>`]from().); |
| 600 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r) |
| 601 | } else { |
| 602 | self.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|t| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(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#(t))) |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | #[inline] |
| 607 | pub(craterust-analyzer cargo handlebars 5.1.2 crate/) fn get_or_load_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_or_load_template().( |
| 608 | &'reg self, |
| 609 | name: &str, |
| 610 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'reg, Templaterust-analyzer cargo handlebars 5.1.2 template/Template#>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> { |
| 611 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result) = self.get_or_load_template_optionalrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_or_load_template_optional().(name) { |
| 612 | result |
| 613 | } else { |
| 614 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::TemplateNotFoundrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#TemplateNotFound#(name.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().()) |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | /// Return a registered helper |
| 619 | #[inline] |
| 620 | pub(craterust-analyzer cargo handlebars 5.1.2 crate/) fn get_or_load_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_or_load_helper().( |
| 621 | &'reg self, |
| 622 | name: &str, |
| 623 | ) -> 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#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg>>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> { |
| 624 | #[cfg(feature = "script_helper")] |
| 625 | if let (true, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(source)) = (self.dev_moderust-analyzer cargo handlebars 5.1.2 registry/Registry#dev_mode., self.script_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#script_sources..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name)) { |
| 626 | return source |
| 627 | .loadrust-analyzer cargo handlebars 5.1.2 sources/Source#load().() |
| 628 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ScriptErrorrust-analyzer cargo handlebars 5.1.2 error/ScriptError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[ScriptError][`From<IOError>`]from().) |
| 629 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|s| { |
| 630 | let helper = 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().(ScriptHelperrust-analyzer cargo handlebars 5.1.2 helpers/scripting/ScriptHelper# { |
| 631 | scriptrust-analyzer cargo handlebars 5.1.2 helpers/scripting/ScriptHelper#script.: self.enginerust-analyzer cargo handlebars 5.1.2 registry/Registry#engine..compilerust-analyzer cargo rhai 1.17.1 api/compile/impl#[Engine]compile().(s)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 632 | }) as Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>; |
| 633 | 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#(helper.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())) |
| 634 | }) |
| 635 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<RenderErrorReason>`]from().(RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderErrorReason][`From<ScriptError>`]from().(e))); |
| 636 | } |
| 637 | |
| 638 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().()) |
| 639 | } |
| 640 | |
| 641 | #[inline] |
| 642 | pub(craterust-analyzer cargo handlebars 5.1.2 crate/) fn has_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]has_helper().(&self, name: &str) -> bool { |
| 643 | self.helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(name) |
| 644 | } |
| 645 | |
| 646 | /// Return a registered decorator |
| 647 | #[inline] |
| 648 | pub(craterust-analyzer cargo handlebars 5.1.2 crate/) fn get_decoratorrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_decorator().( |
| 649 | &self, |
| 650 | name: &str, |
| 651 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn DecoratorDefrust-analyzer cargo handlebars 5.1.2 decorators/DecoratorDef# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'reg)> { |
| 652 | self.decoratorsrust-analyzer cargo handlebars 5.1.2 registry/Registry#decorators..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(name).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][`AsRef<T>`]as_ref().()) |
| 653 | } |
| 654 | |
| 655 | /// Return all templates registered |
| 656 | /// |
| 657 | /// **Note that** in dev mode, the template returned from this method may |
| 658 | /// not reflect its latest state. This method doesn't try to reload templates |
| 659 | /// from its source. |
| 660 | pub fn get_templatesrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_templates().(&self) -> &HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Templaterust-analyzer cargo handlebars 5.1.2 template/Template#> { |
| 661 | &self.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates. |
| 662 | } |
| 663 | |
| 664 | /// Unregister all templates |
| 665 | pub fn clear_templatesrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]clear_templates().(&mut self) { |
| 666 | self.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..clearrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]clear().(); |
| 667 | self.template_sourcesrust-analyzer cargo handlebars 5.1.2 registry/Registry#template_sources..clearrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]clear().(); |
| 668 | } |
| 669 | |
| 670 | #[inline] |
| 671 | fn render_to_outputrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_to_output().<O>( |
| 672 | &self, |
| 673 | name: &str, |
| 674 | ctx: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 675 | output: &mut O, |
| 676 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> |
| 677 | where |
| 678 | O: Outputrust-analyzer cargo handlebars 5.1.2 output/Output#, |
| 679 | { |
| 680 | self.get_or_load_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]get_or_load_template().(name).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(|t| { |
| 681 | let mut render_context = RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#::newrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]new().(t.namerust-analyzer cargo handlebars 5.1.2 template/Template#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()); |
| 682 | t.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(self, ctx, &mut render_context, output) |
| 683 | }) |
| 684 | } |
| 685 | |
| 686 | /// Render a registered template with some data into a string |
| 687 | /// |
| 688 | /// * `name` is the template name you registered previously |
| 689 | /// * `data` is the data that implements `serde::Serialize` |
| 690 | /// |
| 691 | /// Returns rendered string or a struct with error information |
| 692 | pub fn renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().<T>(&self, name: &str, data: &T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> |
| 693 | where |
| 694 | T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 695 | { |
| 696 | let mut output = StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput#::newrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]new().(); |
| 697 | let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 698 | self.render_to_outputrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_to_output().(name, &ctx, &mut output)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 699 | output.into_stringrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]into_string().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<FromUtf8Error>`]from().) |
| 700 | } |
| 701 | |
| 702 | /// Render a registered template with reused context |
| 703 | pub fn render_with_contextrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_with_context().(&self, name: &str, ctx: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> { |
| 704 | let mut output = StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput#::newrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]new().(); |
| 705 | self.render_to_outputrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_to_output().(name, ctx, &mut output)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 706 | output.into_stringrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]into_string().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<FromUtf8Error>`]from().) |
| 707 | } |
| 708 | |
| 709 | /// Render a registered template and write data to the `std::io::Write` |
| 710 | pub fn render_to_writerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_to_write().<T, W>(&self, name: &str, data: &T, writer: W) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> |
| 711 | where |
| 712 | T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 713 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 714 | { |
| 715 | let mut output = WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#::newrust-analyzer cargo handlebars 5.1.2 output/impl#[`WriteOutput<W>`]new().(writer); |
| 716 | let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 717 | self.render_to_outputrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_to_output().(name, &ctx, &mut output) |
| 718 | } |
| 719 | |
| 720 | /// Render a registered template using reusable `Context`, and write data to |
| 721 | /// the `std::io::Write` |
| 722 | pub fn render_with_context_to_writerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_with_context_to_write().<W>( |
| 723 | &self, |
| 724 | name: &str, |
| 725 | ctx: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 726 | writer: W, |
| 727 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> |
| 728 | where |
| 729 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 730 | { |
| 731 | let mut output = WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#::newrust-analyzer cargo handlebars 5.1.2 output/impl#[`WriteOutput<W>`]new().(writer); |
| 732 | self.render_to_outputrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_to_output().(name, ctx, &mut output) |
| 733 | } |
| 734 | |
| 735 | /// Render a template string using current registry without registering it |
| 736 | pub fn render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().<T>(&self, template_string: &str, data: &T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> |
| 737 | where |
| 738 | T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 739 | { |
| 740 | let mut writer = StringWriterrust-analyzer cargo handlebars 5.1.2 support/str/StringWriter#::newrust-analyzer cargo handlebars 5.1.2 support/str/impl#[StringWriter]new().(); |
| 741 | self.render_template_to_writerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template_to_write().(template_string, data, &mut writer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 742 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(writer.into_stringrust-analyzer cargo handlebars 5.1.2 support/str/impl#[StringWriter]into_string().()) |
| 743 | } |
| 744 | |
| 745 | /// Render a template string using reusable context data |
| 746 | pub fn render_template_with_contextrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template_with_context().( |
| 747 | &self, |
| 748 | template_string: &str, |
| 749 | ctx: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 750 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> { |
| 751 | let tpl = Templaterust-analyzer cargo handlebars 5.1.2 template/Template#::compile2rust-analyzer cargo handlebars 5.1.2 template/impl#[Template]compile2().( |
| 752 | template_string, |
| 753 | TemplateOptionsrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions# { |
| 754 | prevent_indentrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions#prevent_indent.: self.prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent., |
| 755 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo handlebars 5.1.2 template/impl#[TemplateOptions][Default]default().() |
| 756 | }, |
| 757 | ) |
| 758 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<TemplateError>`]from().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 759 | |
| 760 | let mut out = StringOutputrust-analyzer cargo handlebars 5.1.2 output/StringOutput#::newrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]new().(); |
| 761 | { |
| 762 | let mut render_context = RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#::newrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 763 | tpl.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(self, ctx, &mut render_context, &mut out)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 764 | } |
| 765 | |
| 766 | out.into_stringrust-analyzer cargo handlebars 5.1.2 output/impl#[StringOutput]into_string().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<FromUtf8Error>`]from().) |
| 767 | } |
| 768 | |
| 769 | /// Render a template string using resuable context, and write data into |
| 770 | /// `std::io::Write` |
| 771 | pub fn render_template_with_context_to_writerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template_with_context_to_write().<W>( |
| 772 | &self, |
| 773 | template_string: &str, |
| 774 | ctx: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 775 | writer: W, |
| 776 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> |
| 777 | where |
| 778 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 779 | { |
| 780 | let tpl = Templaterust-analyzer cargo handlebars 5.1.2 template/Template#::compile2rust-analyzer cargo handlebars 5.1.2 template/impl#[Template]compile2().( |
| 781 | template_string, |
| 782 | TemplateOptionsrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions# { |
| 783 | prevent_indentrust-analyzer cargo handlebars 5.1.2 template/TemplateOptions#prevent_indent.: self.prevent_indentrust-analyzer cargo handlebars 5.1.2 registry/Registry#prevent_indent., |
| 784 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo handlebars 5.1.2 template/impl#[TemplateOptions][Default]default().() |
| 785 | }, |
| 786 | ) |
| 787 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#::fromrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError][`From<TemplateError>`]from().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 788 | let mut render_context = RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#::newrust-analyzer cargo handlebars 5.1.2 render/impl#[`RenderContext<'reg, 'rc>`]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 789 | let mut out = WriteOutputrust-analyzer cargo handlebars 5.1.2 output/WriteOutput#::newrust-analyzer cargo handlebars 5.1.2 output/impl#[`WriteOutput<W>`]new().(writer); |
| 790 | tpl.renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(self, ctx, &mut render_context, &mut out) |
| 791 | } |
| 792 | |
| 793 | /// Render a template string using current registry without registering it |
| 794 | pub fn render_template_to_writerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template_to_write().<T, W>( |
| 795 | &self, |
| 796 | template_string: &str, |
| 797 | data: &T, |
| 798 | writer: W, |
| 799 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> |
| 800 | where |
| 801 | T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 802 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 803 | { |
| 804 | let ctx = Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 805 | self.render_template_with_context_to_writerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template_with_context_to_write().(template_string, &ctx, writer) |
| 806 | } |
| 807 | |
| 808 | #[cfg(feature = "string_helpers")] |
| 809 | #[inline] |
| 810 | fn register_string_helpersrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_string_helpers().(&mut self) { |
| 811 | use helpersrust-analyzer cargo handlebars 5.1.2 helpers/::string_helpersrust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/::{ |
| 812 | kebab_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/kebab_case()., lower_camel_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/lower_camel_case()., shouty_kebab_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/shouty_kebab_case()., shouty_snake_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/shouty_snake_case()., snake_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/snake_case()., |
| 813 | title_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/title_case()., train_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/train_case()., upper_camel_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/upper_camel_case()., |
| 814 | }; |
| 815 | |
| 816 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("lowerCamelCase", 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().(lower_camel_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/lower_camel_case().)); |
| 817 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("upperCamelCase", 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().(upper_camel_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/upper_camel_case().)); |
| 818 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("snakeCase", 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().(snake_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/snake_case().)); |
| 819 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("kebabCase", 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().(kebab_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/kebab_case().)); |
| 820 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("shoutySnakeCase", 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().(shouty_snake_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/shouty_snake_case().)); |
| 821 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("shoutyKebabCase", 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().(shouty_kebab_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/shouty_kebab_case().)); |
| 822 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("titleCase", 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().(title_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/title_case().)); |
| 823 | self.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("trainCase", 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().(train_caserust-analyzer cargo handlebars 5.1.2 helpers/string_helpers/train_case().)); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | #[cfg(test)] |
| 828 | mod testrust-analyzer cargo handlebars 5.1.2 registry/test/ { |
| 829 | 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#; |
| 830 | 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#, RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#}; |
| 831 | 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#; |
| 832 | 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#; |
| 833 | 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#; |
| 834 | 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#}; |
| 835 | use craterust-analyzer cargo handlebars 5.1.2 crate/::supportrust-analyzer cargo handlebars 5.1.2 support/::strrust-analyzer cargo handlebars 5.1.2 support/str/::StringWriterrust-analyzer cargo handlebars 5.1.2 support/str/StringWriter#; |
| 836 | 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#; |
| 837 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 838 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#; |
| 839 | use tempfilerust-analyzer cargo tempfile 3.10.1 crate/::tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().; |
| 840 | |
| 841 | #[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:)] |
| 842 | struct DummyHelperrust-analyzer cargo handlebars 5.1.2 registry/test/DummyHelper#; |
| 843 | |
| 844 | impl HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# for DummyHelperrust-analyzer cargo handlebars 5.1.2 registry/test/DummyHelper# { |
| 845 | fn callrust-analyzer cargo handlebars 5.1.2 registry/test/impl#[DummyHelper][HelperDef]call().<'reg: 'rc, 'rc>( |
| 846 | &self, |
| 847 | h: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'rc>, |
| 848 | r: &'reg Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg>, |
| 849 | ctx: &'rc Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 850 | rc: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'reg, 'rc>, |
| 851 | out: &mut dyn Outputrust-analyzer cargo handlebars 5.1.2 output/Output#, |
| 852 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> { |
| 853 | h.templaterust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]template().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().renderrust-analyzer cargo handlebars 5.1.2 render/impl#[Template][Renderable]render().(r, ctx, rc, out) |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | static DUMMY_HELPERrust-analyzer cargo handlebars 5.1.2 registry/test/DUMMY_HELPER.: DummyHelperrust-analyzer cargo handlebars 5.1.2 registry/test/DummyHelper# = DummyHelperrust-analyzer cargo handlebars 5.1.2 registry/test/DummyHelper#; |
| 858 | |
| 859 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 860 | fn test_registry_operationsrust-analyzer cargo handlebars 5.1.2 registry/test/test_registry_operations().() { |
| 861 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 862 | |
| 863 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("index", "<h1></h1>").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 864 | |
| 865 | let tpl = Templaterust-analyzer cargo handlebars 5.1.2 template/Template#::compilerust-analyzer cargo handlebars 5.1.2 template/impl#[Template]compile().("<h2></h2>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 866 | r.register_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template().("index2", tpl); |
| 867 | |
| 868 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 2); |
| 869 | |
| 870 | r.unregister_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]unregister_template().("index"); |
| 871 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 1); |
| 872 | |
| 873 | r.clear_templatesrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]clear_templates().(); |
| 874 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 0); |
| 875 | |
| 876 | r.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("dummy", 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().(DUMMY_HELPERrust-analyzer cargo handlebars 5.1.2 registry/test/DUMMY_HELPER.)); |
| 877 | |
| 878 | // built-in helpers plus 1 |
| 879 | let num_helpers = 7; |
| 880 | let num_boolean_helpers = 10; // stuff like gt and lte |
| 881 | let num_custom_helpers = 1; // dummy from above |
| 882 | #[cfg(feature = "string_helpers")] |
| 883 | let string_helpers = 8; |
| 884 | #[cfg(not(feature = "string_helpers"))] |
| 885 | let string_helpers = 0; |
| 886 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 887 | r.helpersrust-analyzer cargo handlebars 5.1.2 registry/Registry#helpers..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), |
| 888 | num_helpers +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). num_boolean_helpers +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). num_custom_helpers +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). string_helpers |
| 889 | ); |
| 890 | } |
| 891 | |
| 892 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 893 | #[cfg(feature = "dir_source")] |
| 894 | fn test_register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/test/test_register_templates_directory().() { |
| 895 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::DirBuilderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirBuilder#; |
| 896 | |
| 897 | use craterust-analyzer cargo handlebars 5.1.2 crate/::registryrust-analyzer cargo handlebars 5.1.2 registry/::DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#; |
| 898 | |
| 899 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 900 | { |
| 901 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 902 | |
| 903 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 0); |
| 904 | |
| 905 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t1.hbs"); |
| 906 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 907 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file1, "<h1>Hello {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 908 | |
| 909 | let file2_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t2.hbs"); |
| 910 | let mut file2: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file2_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 911 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file2, "<h1>Hola {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 912 | |
| 913 | let file3_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t3.hbs"); |
| 914 | let mut file3: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file3_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 915 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file3, "<h1>Hallo {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 916 | |
| 917 | let file4_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(".t4.hbs"); |
| 918 | let mut file4: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file4_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 919 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file4, "<h1>Hallo {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 920 | |
| 921 | r.register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_templates_directory().(dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().(), DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#::defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default]default().()) |
| 922 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 923 | |
| 924 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 3); |
| 925 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("t1"), true); |
| 926 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("t2"), true); |
| 927 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("t3"), true); |
| 928 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("t4"), false); |
| 929 | |
| 930 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file1); |
| 931 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file2); |
| 932 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file3); |
| 933 | |
| 934 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 935 | } |
| 936 | |
| 937 | { |
| 938 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 939 | |
| 940 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t4.hbs"); |
| 941 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 942 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file1, "<h1>Hello {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 943 | |
| 944 | let file2_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t5.erb"); |
| 945 | let mut file2: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file2_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 946 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file2, "<h1>Hello {{% world %}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 947 | |
| 948 | let file3_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t6.html"); |
| 949 | let mut file3: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file3_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 950 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file3, "<h1>Hello world!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 951 | |
| 952 | r.register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_templates_directory().(dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().(), DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#::defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default]default().()) |
| 953 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 954 | |
| 955 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 4); |
| 956 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("t4"), true); |
| 957 | |
| 958 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file1); |
| 959 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file2); |
| 960 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file3); |
| 961 | |
| 962 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 963 | } |
| 964 | |
| 965 | { |
| 966 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 967 | |
| 968 | let _ = DirBuilderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirBuilder#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirBuilder]new().().createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirBuilder]create().(dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("french")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 969 | let _ = DirBuilderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirBuilder#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirBuilder]new().() |
| 970 | .createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirBuilder]create().(dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("portugese")) |
| 971 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 972 | let _ = DirBuilderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirBuilder#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirBuilder]new().() |
| 973 | .createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirBuilder]create().(dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("italian")) |
| 974 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 975 | |
| 976 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("french/t7.hbs"); |
| 977 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 978 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file1, "<h1>Bonjour {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 979 | |
| 980 | let file2_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("portugese/t8.hbs"); |
| 981 | let mut file2: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file2_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 982 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file2, "<h1>Ola {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 983 | |
| 984 | let file3_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("italian/t9.hbs"); |
| 985 | let mut file3: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file3_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 986 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file3, "<h1>Ciao {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 987 | |
| 988 | r.register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_templates_directory().(dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().(), DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#::defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default]default().()) |
| 989 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 990 | |
| 991 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 7); |
| 992 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("french/t7"), true); |
| 993 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("portugese/t8"), true); |
| 994 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("italian/t9"), true); |
| 995 | |
| 996 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file1); |
| 997 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file2); |
| 998 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file3); |
| 999 | |
| 1000 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1001 | } |
| 1002 | |
| 1003 | { |
| 1004 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1005 | |
| 1006 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t10.hbs"); |
| 1007 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1008 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file1, "<h1>Bonjour {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1009 | |
| 1010 | let mut dir_path = dir |
| 1011 | .pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().() |
| 1012 | .to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().() |
| 1013 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::MAIN_SEPARATORrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/MAIN_SEPARATOR., "/"); |
| 1014 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dir_path.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().("/") { |
| 1015 | dir_path.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('/'); |
| 1016 | } |
| 1017 | r.register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_templates_directory().(dir_path, DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#::defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default]default().()) |
| 1018 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1019 | |
| 1020 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 8); |
| 1021 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("t10"), true); |
| 1022 | |
| 1023 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file1); |
| 1024 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1025 | } |
| 1026 | |
| 1027 | { |
| 1028 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1029 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1030 | |
| 1031 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t11.hbs.html"); |
| 1032 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1033 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file1, "<h1>Bonjour {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1034 | |
| 1035 | let mut dir_path = dir |
| 1036 | .pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().() |
| 1037 | .to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().() |
| 1038 | .replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::MAIN_SEPARATORrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/MAIN_SEPARATOR., "/"); |
| 1039 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dir_path.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().("/") { |
| 1040 | dir_path.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('/'); |
| 1041 | } |
| 1042 | r.register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_templates_directory().( |
| 1043 | dir_path, |
| 1044 | DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions# { |
| 1045 | tpl_extensionrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#tpl_extension.: ".hbs.html".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), |
| 1046 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default]default().() |
| 1047 | }, |
| 1048 | ) |
| 1049 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1050 | |
| 1051 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 1); |
| 1052 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().("t11"), true); |
| 1053 | |
| 1054 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file1); |
| 1055 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1056 | } |
| 1057 | |
| 1058 | { |
| 1059 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1060 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1061 | |
| 1062 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 0); |
| 1063 | |
| 1064 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(".t12.hbs"); |
| 1065 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1066 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(file1, "<h1>Hello {{world}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1067 | |
| 1068 | r.register_templates_directoryrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_templates_directory().( |
| 1069 | dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().(), |
| 1070 | DirectorySourceOptionsrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions# { |
| 1071 | hiddenrust-analyzer cargo handlebars 5.1.2 registry/DirectorySourceOptions#hidden.: true, |
| 1072 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo handlebars 5.1.2 registry/impl#[DirectorySourceOptions][Default]default().() |
| 1073 | }, |
| 1074 | ) |
| 1075 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1076 | |
| 1077 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().(), 1); |
| 1078 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.templatesrust-analyzer cargo handlebars 5.1.2 registry/Registry#templates..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(".t12"), true); |
| 1079 | |
| 1080 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(file1); |
| 1081 | |
| 1082 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1087 | fn test_render_to_writerust-analyzer cargo handlebars 5.1.2 registry/test/test_render_to_write().() { |
| 1088 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1089 | |
| 1090 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("index", "<h1></h1>").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 1091 | |
| 1092 | let mut sw = StringWriterrust-analyzer cargo handlebars 5.1.2 support/str/StringWriter#::newrust-analyzer cargo handlebars 5.1.2 support/str/impl#[StringWriter]new().(); |
| 1093 | { |
| 1094 | r.render_to_writerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_to_write().("index", &(), &mut sw).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().(); |
| 1095 | } |
| 1096 | |
| 1097 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("<h1></h1>".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), sw.into_stringrust-analyzer cargo handlebars 5.1.2 support/str/impl#[StringWriter]into_string().()); |
| 1098 | } |
| 1099 | |
| 1100 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1101 | fn test_escape_fnrust-analyzer cargo handlebars 5.1.2 registry/test/test_escape_fn().() { |
| 1102 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1103 | |
| 1104 | let input = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("\"<>&"); |
| 1105 | |
| 1106 | r.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("test", Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("{{this}}")) |
| 1107 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1108 | |
| 1109 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(""<>&", r.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("test", &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 1110 | |
| 1111 | r.register_escape_fnrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_escape_fn().(|s| s.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 1112 | |
| 1113 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("\"<>&", r.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("test", &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 1114 | |
| 1115 | r.unregister_escape_fnrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]unregister_escape_fn().(); |
| 1116 | |
| 1117 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(""<>&", r.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("test", &input).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 1118 | } |
| 1119 | |
| 1120 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1121 | fn test_escaperust-analyzer cargo handlebars 5.1.2 registry/test/test_escape().() { |
| 1122 | let r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1123 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"hello": "world"}); |
| 1124 | |
| 1125 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1126 | "{{hello}}", |
| 1127 | r.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r"\{{hello}}", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1128 | ); |
| 1129 | |
| 1130 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1131 | " {{hello}}", |
| 1132 | r.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r" \{{hello}}", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1133 | ); |
| 1134 | |
| 1135 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r"\world", r.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().(r"\\{{hello}}", &data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 1136 | } |
| 1137 | |
| 1138 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1139 | fn test_strict_moderust-analyzer cargo handlebars 5.1.2 registry/test/test_strict_mode().() { |
| 1140 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1141 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().r.strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]strict_mode().()); |
| 1142 | |
| 1143 | r.set_strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_strict_mode().(true); |
| 1144 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r.strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]strict_mode().()); |
| 1145 | |
| 1146 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 1147 | "the_only_key": "the_only_value" |
| 1148 | }); |
| 1149 | |
| 1150 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r |
| 1151 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("accessing the_only_key {{the_only_key}}", &data) |
| 1152 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 1153 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r |
| 1154 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("accessing non-exists key {{the_key_never_exists}}", &data) |
| 1155 | .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 1156 | |
| 1157 | let render_error = r |
| 1158 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("accessing non-exists key {{the_key_never_exists}}", &data) |
| 1159 | .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(); |
| 1160 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(render_error.column_norust-analyzer cargo handlebars 5.1.2 error/RenderError#column_no..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 26); |
| 1161 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1162 | match render_error.reasonrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError]reason().() { |
| 1163 | RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::MissingVariablerust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#MissingVariable#(path) => path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 1164 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 1165 | }, |
| 1166 | "the_key_never_exists" |
| 1167 | ); |
| 1168 | |
| 1169 | let data2 = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!([1, 2, 3]); |
| 1170 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r |
| 1171 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("accessing valid array index {{this.[2]}}", &data2) |
| 1172 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 1173 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r |
| 1174 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("accessing invalid array index {{this.[3]}}", &data2) |
| 1175 | .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 1176 | let render_error2 = r |
| 1177 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("accessing invalid array index {{this.[3]}}", &data2) |
| 1178 | .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(); |
| 1179 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(render_error2.column_norust-analyzer cargo handlebars 5.1.2 error/RenderError#column_no..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 31); |
| 1180 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1181 | match render_error2.reasonrust-analyzer cargo handlebars 5.1.2 error/impl#[RenderError]reason().() { |
| 1182 | RenderErrorReasonrust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#::MissingVariablerust-analyzer cargo handlebars 5.1.2 error/RenderErrorReason#MissingVariable#(path) => path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), |
| 1183 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 1184 | }, |
| 1185 | "this.[3]" |
| 1186 | ) |
| 1187 | } |
| 1188 | |
| 1189 | 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/::ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#; |
| 1190 | struct GenMissingHelperrust-analyzer cargo handlebars 5.1.2 registry/test/GenMissingHelper#; |
| 1191 | impl HelperDefrust-analyzer cargo handlebars 5.1.2 helpers/HelperDef# for GenMissingHelperrust-analyzer cargo handlebars 5.1.2 registry/test/GenMissingHelper# { |
| 1192 | fn call_innerrust-analyzer cargo handlebars 5.1.2 registry/test/impl#[GenMissingHelper][HelperDef]call_inner().<'reg: 'rc, 'rc>( |
| 1193 | &self, |
| 1194 | _: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'rc>, |
| 1195 | _: &'reg Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'reg>, |
| 1196 | _: &'rc Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 1197 | _: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'reg, 'rc>, |
| 1198 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#<'rc>, RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> { |
| 1199 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ScopedJsonrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#::Missingrust-analyzer cargo handlebars 5.1.2 json/value/ScopedJson#Missing#) |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1204 | fn test_strict_mode_in_helperrust-analyzer cargo handlebars 5.1.2 registry/test/test_strict_mode_in_helper().() { |
| 1205 | let mut r = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1206 | r.set_strict_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_strict_mode().(true); |
| 1207 | |
| 1208 | r.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().( |
| 1209 | "check_missing", |
| 1210 | 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().( |
| 1211 | |h: &Helperrust-analyzer cargo handlebars 5.1.2 render/Helper#<'_>, |
| 1212 | _: &Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#<'_>, |
| 1213 | _: &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#, |
| 1214 | _: &mut RenderContextrust-analyzer cargo handlebars 5.1.2 render/RenderContext#<'_, '_>, |
| 1215 | _: &mut dyn Outputrust-analyzer cargo handlebars 5.1.2 output/Output#| |
| 1216 | -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> { |
| 1217 | let value = h.paramrust-analyzer cargo handlebars 5.1.2 render/impl#[`Helper<'rc>`]param().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 1218 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(value.is_value_missingrust-analyzer cargo handlebars 5.1.2 json/value/impl#[`PathAndJson<'rc>`]is_value_missing().()); |
| 1219 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 1220 | }, |
| 1221 | ), |
| 1222 | ); |
| 1223 | |
| 1224 | r.register_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_helper().("generate_missing_value", 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().(GenMissingHelperrust-analyzer cargo handlebars 5.1.2 registry/test/GenMissingHelper#)); |
| 1225 | |
| 1226 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 1227 | "the_key_we_have": "the_value_we_have" |
| 1228 | }); |
| 1229 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r |
| 1230 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("accessing non-exists key {{the_key_we_dont_have}}", &data) |
| 1231 | .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 1232 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r |
| 1233 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1234 | "accessing non-exists key from helper {{check_missing the_key_we_dont_have}}", |
| 1235 | &data |
| 1236 | ) |
| 1237 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 1238 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r |
| 1239 | .render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1240 | "accessing helper that generates missing value {{generate_missing_value}}", |
| 1241 | &data |
| 1242 | ) |
| 1243 | .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 1244 | } |
| 1245 | |
| 1246 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1247 | fn test_html_expressionrust-analyzer cargo handlebars 5.1.2 registry/test/test_html_expression().() { |
| 1248 | let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1249 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1250 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{{ a }}}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"a": "<b>bold</b>"})) |
| 1251 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 1252 | "<b>bold</b>" |
| 1253 | ); |
| 1254 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1255 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{ &a }}", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"a": "<b>bold</b>"})) |
| 1256 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 1257 | "<b>bold</b>" |
| 1258 | ); |
| 1259 | } |
| 1260 | |
| 1261 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1262 | fn test_render_contextrust-analyzer cargo handlebars 5.1.2 registry/test/test_render_context().() { |
| 1263 | let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1264 | |
| 1265 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!([0, 1, 2, 3]); |
| 1266 | |
| 1267 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1268 | "0123", |
| 1269 | reg.render_template_with_contextrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template_with_context().( |
| 1270 | "{{#each this}}{{this}}{{/each}}", |
| 1271 | &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::wrapsrust-analyzer cargo handlebars 5.1.2 context/impl#[Context]wraps().(&data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1272 | ) |
| 1273 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1274 | ); |
| 1275 | |
| 1276 | reg.register_template_stringrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_string().("t0", "{{#each this}}{{this}}{{/each}}") |
| 1277 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1278 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1279 | "0123", |
| 1280 | reg.render_with_contextrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_with_context().("t0", &Contextrust-analyzer cargo handlebars 5.1.2 context/Context#::fromrust-analyzer cargo handlebars 5.1.2 context/impl#[Context][`From<Json>`]from().(data)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1281 | ); |
| 1282 | } |
| 1283 | |
| 1284 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1285 | fn test_keys_starts_with_nullrust-analyzer cargo handlebars 5.1.2 registry/test/test_keys_starts_with_null().() { |
| 1286 | env_loggerrust-analyzer cargo env_logger 0.11.11 crate/::initrust-analyzer cargo env_logger 0.11.11 logger/init().(); |
| 1287 | let reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1288 | let data = jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({ |
| 1289 | "optional": true, |
| 1290 | "is_null": true, |
| 1291 | "nullable": true, |
| 1292 | "null": true, |
| 1293 | "falsevalue": true, |
| 1294 | }); |
| 1295 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1296 | "optional: true --> true", |
| 1297 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1298 | "optional: {{optional}} --> {{#if optional }}true{{else}}false{{/if}}", |
| 1299 | &data |
| 1300 | ) |
| 1301 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1302 | ); |
| 1303 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1304 | "is_null: true --> true", |
| 1305 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1306 | "is_null: {{is_null}} --> {{#if is_null }}true{{else}}false{{/if}}", |
| 1307 | &data |
| 1308 | ) |
| 1309 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1310 | ); |
| 1311 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1312 | "nullable: true --> true", |
| 1313 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1314 | "nullable: {{nullable}} --> {{#if nullable }}true{{else}}false{{/if}}", |
| 1315 | &data |
| 1316 | ) |
| 1317 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1318 | ); |
| 1319 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1320 | "falsevalue: true --> true", |
| 1321 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1322 | "falsevalue: {{falsevalue}} --> {{#if falsevalue }}true{{else}}false{{/if}}", |
| 1323 | &data |
| 1324 | ) |
| 1325 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1326 | ); |
| 1327 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1328 | "null: true --> false", |
| 1329 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1330 | "null: {{null}} --> {{#if null }}true{{else}}false{{/if}}", |
| 1331 | &data |
| 1332 | ) |
| 1333 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1334 | ); |
| 1335 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1336 | "null: true --> true", |
| 1337 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().( |
| 1338 | "null: {{null}} --> {{#if this.[null]}}true{{else}}false{{/if}}", |
| 1339 | &data |
| 1340 | ) |
| 1341 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 1342 | ); |
| 1343 | } |
| 1344 | |
| 1345 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1346 | fn test_dev_mode_template_reloadrust-analyzer cargo handlebars 5.1.2 registry/test/test_dev_mode_template_reload().() { |
| 1347 | let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1348 | reg.set_dev_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_dev_mode().(true); |
| 1349 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(reg.dev_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]dev_mode().()); |
| 1350 | |
| 1351 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1352 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("t1.hbs"); |
| 1353 | { |
| 1354 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1355 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(file1, "<h1>Hello {{{{name}}}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1356 | } |
| 1357 | |
| 1358 | reg.register_template_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_template_file().("t1", &file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1359 | |
| 1360 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1361 | reg.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"name": "Alex"})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 1362 | "<h1>Hello Alex!</h1>" |
| 1363 | ); |
| 1364 | |
| 1365 | { |
| 1366 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1367 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(file1, "<h1>Privet {{{{name}}}}!</h1>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1368 | } |
| 1369 | |
| 1370 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1371 | reg.renderrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render().("t1", &jsonrust-analyzer cargo serde_json 1.0.114 macros/json!!({"name": "Alex"})).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 1372 | "<h1>Privet Alex!</h1>" |
| 1373 | ); |
| 1374 | |
| 1375 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1376 | } |
| 1377 | |
| 1378 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1379 | #[cfg(feature = "script_helper")] |
| 1380 | fn test_script_helperrust-analyzer cargo handlebars 5.1.2 registry/test/test_script_helper().() { |
| 1381 | let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1382 | |
| 1383 | reg.register_script_helperrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_script_helper().("acc", "params.reduce(|sum, x| x + sum, 0)") |
| 1384 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1385 | |
| 1386 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1387 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{acc 1 2 3 4}}", &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().(), |
| 1388 | "10" |
| 1389 | ); |
| 1390 | } |
| 1391 | |
| 1392 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1393 | #[cfg(feature = "script_helper")] |
| 1394 | fn test_script_helper_dev_moderust-analyzer cargo handlebars 5.1.2 registry/test/test_script_helper_dev_mode().() { |
| 1395 | let mut reg = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1396 | reg.set_dev_moderust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_dev_mode().(true); |
| 1397 | |
| 1398 | let dir = tempdirrust-analyzer cargo tempfile 3.10.1 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1399 | let file1_path = dir.pathrust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("acc.rhai"); |
| 1400 | { |
| 1401 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1402 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(file1, "params.reduce(|sum, x| x + sum, 0)").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1403 | } |
| 1404 | |
| 1405 | reg.register_script_helper_filerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]register_script_helper_file().("acc", &file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1406 | |
| 1407 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1408 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{acc 1 2 3 4}}", &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().(), |
| 1409 | "10" |
| 1410 | ); |
| 1411 | |
| 1412 | { |
| 1413 | let mut file1: Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File# = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(&file1_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1414 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(file1, "params.reduce(|sum, x| x * sum, 1)").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1415 | } |
| 1416 | |
| 1417 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 1418 | reg.render_templaterust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]render_template().("{{acc 1 2 3 4}}", &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().(), |
| 1419 | "24" |
| 1420 | ); |
| 1421 | |
| 1422 | dir.closerust-analyzer cargo tempfile 3.10.1 dir/impl#[TempDir]close().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1423 | } |
| 1424 | |
| 1425 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1426 | #[cfg(feature = "script_helper")] |
| 1427 | fn test_engine_accessrust-analyzer cargo handlebars 5.1.2 registry/test/test_engine_access().() { |
| 1428 | use rhairust-analyzer cargo rhai 1.17.1 crate/::Enginerust-analyzer cargo rhai 1.17.1 engine/Engine#; |
| 1429 | |
| 1430 | let mut registry = Registryrust-analyzer cargo handlebars 5.1.2 registry/Registry#::newrust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]new().(); |
| 1431 | let mut eng = Enginerust-analyzer cargo rhai 1.17.1 engine/Engine#::newrust-analyzer cargo rhai 1.17.1 engine/impl#[Engine]new().(); |
| 1432 | eng.set_max_string_sizerust-analyzer cargo rhai 1.17.1 api/limits/impl#[Engine]set_max_string_size().(1000); |
| 1433 | registry.set_enginerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]set_engine().(eng); |
| 1434 | |
| 1435 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1000, registry.enginerust-analyzer cargo handlebars 5.1.2 registry/impl#[`Registry<'reg>`]engine().().max_string_sizerust-analyzer cargo rhai 1.17.1 api/limits/impl#[Engine]max_string_size().()); |
| 1436 | } |
| 1437 | } |