Debian Codegraph @

src/block.rs

raw symbols SCIP
1 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/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#;
2
3 use serde_jsonrust-analyzer cargo serde_json 1.0.114 crate/::valuerust-analyzer cargo serde_json 1.0.114 value/::Valuerust-analyzer cargo serde_json 1.0.114 value/Value# as Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#;
4
5 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#;
6 use craterust-analyzer cargo handlebars 5.1.2 crate/::local_varsrust-analyzer cargo handlebars 5.1.2 local_vars/::LocalVarsrust-analyzer cargo handlebars 5.1.2 local_vars/LocalVars#;
7
8 #[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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
9 pub enum BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder# {
10 // a reference to certain context value
11 Pathrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#Path#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
12 // an actual value holder
13 Valuerust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#Value#(Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#),
14 }
15
16 impl BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder# {
17 pub fn valuerust-analyzer cargo handlebars 5.1.2 block/impl#[BlockParamHolder]value().(v: Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#) -> BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder# {
18 BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#::Valuerust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#Value#(v)
19 }
20
21 pub fn pathrust-analyzer cargo handlebars 5.1.2 block/impl#[BlockParamHolder]path().(r: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder# {
22 BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#::Pathrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#Path#(r)
23 }
24 }
25
26 /// A map holds block parameters. The parameter can be either a value or a reference
27 #[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:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
28 pub struct BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#<'reg> {
29 datarust-analyzer cargo handlebars 5.1.2 block/BlockParams#data.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<&'reg str, BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#>,
30 }
31
32 impl<'reg> BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#<'reg> {
33 /// Create a empty block parameter map.
34 pub fn newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]new().() -> BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#<'reg> {
35 BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#::defaultrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`][Default]default().()
36 }
37
38 /// Add a path reference as the parameter. The `path` is a vector of path
39 /// segments the relative to current block's base path.
40 pub fn add_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_path().(&mut self, k: &'reg str, path: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
41 self.datarust-analyzer cargo handlebars 5.1.2 block/BlockParams#data..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(k, BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#::pathrust-analyzer cargo handlebars 5.1.2 block/impl#[BlockParamHolder]path().(path));
42 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
43 }
44
45 /// Add a value as parameter.
46 pub fn add_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]add_value().(&mut self, k: &'reg str, v: Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), RenderErrorrust-analyzer cargo handlebars 5.1.2 error/RenderError#> {
47 self.datarust-analyzer cargo handlebars 5.1.2 block/BlockParams#data..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]insert().(k, BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#::valuerust-analyzer cargo handlebars 5.1.2 block/impl#[BlockParamHolder]value().(v));
48 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
49 }
50
51 /// Get a block parameter by its name.
52 pub fn getrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]get().(&self, k: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#> {
53 self.datarust-analyzer cargo handlebars 5.1.2 block/BlockParams#data..getrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]get().(k)
54 }
55 }
56
57 /// A data structure holds contextual data for current block scope.
58 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
59 pub struct BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'rc> {
60 /// the base_path of current block scope
61 base_pathrust-analyzer cargo handlebars 5.1.2 block/BlockContext#base_path.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
62 /// the base_value of current block scope, when the block is using a
63 /// constant or derived value as block base
64 base_valuerust-analyzer cargo handlebars 5.1.2 block/BlockContext#base_value.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#>,
65 /// current block context variables
66 block_paramsrust-analyzer cargo handlebars 5.1.2 block/BlockContext#block_params.: BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#<'rc>,
67 /// local variables in current context
68 local_variablesrust-analyzer cargo handlebars 5.1.2 block/BlockContext#local_variables.: LocalVarsrust-analyzer cargo handlebars 5.1.2 local_vars/LocalVars#,
69 }
70
71 impl<'rc> BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'rc> {
72 /// create a new `BlockContext` with default data
73 pub fn newrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]new().() -> BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#<'rc> {
74 BlockContextrust-analyzer cargo handlebars 5.1.2 block/BlockContext#::defaultrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`][Default]default().()
75 }
76
77 /// set a local variable into current scope
78 pub fn set_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_local_var().(&mut self, name: &str, value: Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#) {
79 self.local_variablesrust-analyzer cargo handlebars 5.1.2 block/BlockContext#local_variables..putrust-analyzer cargo handlebars 5.1.2 local_vars/impl#[LocalVars]put().(name, value);
80 }
81
82 /// Get mutable access to the local variables
83 pub fn local_variables_mutrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]local_variables_mut().(&mut self) -> &mut LocalVarsrust-analyzer cargo handlebars 5.1.2 local_vars/LocalVars# {
84 &mut self.local_variablesrust-analyzer cargo handlebars 5.1.2 block/BlockContext#local_variables.
85 }
86
87 /// get a local variable from current scope
88 pub fn get_local_varrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]get_local_var().(&self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#> {
89 self.local_variablesrust-analyzer cargo handlebars 5.1.2 block/BlockContext#local_variables..getrust-analyzer cargo handlebars 5.1.2 local_vars/impl#[LocalVars]get().(name)
90 }
91
92 /// borrow a reference to current scope's base path
93 /// all paths inside this block will be relative to this path
94 pub fn base_pathrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path().(&self) -> &Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
95 &self.base_pathrust-analyzer cargo handlebars 5.1.2 block/BlockContext#base_path.
96 }
97
98 /// borrow a mutable reference to the base path
99 pub fn base_path_mutrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_path_mut().(&mut self) -> &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
100 &mut self.base_pathrust-analyzer cargo handlebars 5.1.2 block/BlockContext#base_path.
101 }
102
103 /// borrow the base value
104 pub fn base_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]base_value().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#> {
105 self.base_valuerust-analyzer cargo handlebars 5.1.2 block/BlockContext#base_value..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
106 }
107
108 /// set the base value
109 pub fn set_base_valuerust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_base_value().(&mut self, value: Jsonrust-analyzer cargo serde_json 1.0.114 value/Value#) {
110 self.base_valuerust-analyzer cargo handlebars 5.1.2 block/BlockContext#base_value. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value);
111 }
112
113 /// Get a block parameter from this block.
114 /// Block parameters needed to be supported by the block helper.
115 /// The typical syntax for block parameter is:
116 ///
117 /// ```skip
118 /// {{#myblock param1 as |block_param1|}}
119 /// ...
120 /// {{/myblock}}
121 /// ```
122 ///
123 pub fn get_block_paramrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]get_block_param().(&self, block_param_name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&BlockParamHolderrust-analyzer cargo handlebars 5.1.2 block/BlockParamHolder#> {
124 self.block_paramsrust-analyzer cargo handlebars 5.1.2 block/BlockContext#block_params..getrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockParams<'reg>`]get().(block_param_name)
125 }
126
127 /// Set a block parameter into this block.
128 pub fn set_block_paramsrust-analyzer cargo handlebars 5.1.2 block/impl#[`BlockContext<'rc>`]set_block_params().(&mut self, block_params: BlockParamsrust-analyzer cargo handlebars 5.1.2 block/BlockParams#<'rc>) {
129 self.block_paramsrust-analyzer cargo handlebars 5.1.2 block/BlockContext#block_params. = block_params;
130 }
131 }