Struct handlebars::BlockParams
source · pub struct BlockParams<'reg> { /* private fields */ }
Expand description
A map holds block parameters. The parameter can be either a value or a reference
Implementations§
source§impl<'reg> BlockParams<'reg>
impl<'reg> BlockParams<'reg>
sourcepub fn new() -> BlockParams<'reg>
pub fn new() -> BlockParams<'reg>
Create a empty block parameter map.
Examples found in repository?
src/helpers/helper_each.rs (line 40)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn set_block_param<'reg: 'rc, 'rc>(
block: &mut BlockContext<'reg>,
h: &Helper<'reg, 'rc>,
base_path: Option<&Vec<String>>,
k: &Json,
v: &Json,
) -> Result<(), RenderError> {
if let Some(bp_val) = h.block_param() {
let mut params = BlockParams::new();
if base_path.is_some() {
params.add_path(bp_val, Vec::with_capacity(0))?;
} else {
params.add_value(bp_val, v.clone())?;
}
block.set_block_params(params);
} else if let Some((bp_val, bp_key)) = h.block_param_pair() {
let mut params = BlockParams::new();
if base_path.is_some() {
params.add_path(bp_val, Vec::with_capacity(0))?;
} else {
params.add_value(bp_val, v.clone())?;
}
params.add_value(bp_key, k.clone())?;
block.set_block_params(params);
}
Ok(())
}
More examples
src/helpers/helper_with.rs (line 31)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn call<'reg: 'rc, 'rc>(
&self,
h: &Helper<'reg, 'rc>,
r: &'reg Registry<'reg>,
ctx: &'rc Context,
rc: &mut RenderContext<'reg, 'rc>,
out: &mut dyn Output,
) -> HelperResult {
let param = h
.param(0)
.ok_or_else(|| RenderError::new("Param not found for helper \"with\""))?;
if param.value().is_truthy(false) {
let mut block = create_block(param);
if let Some(block_param) = h.block_param() {
let mut params = BlockParams::new();
if param.context_path().is_some() {
params.add_path(block_param, Vec::with_capacity(0))?;
} else {
params.add_value(block_param, param.value().clone())?;
}
block.set_block_params(params);
}
rc.push_block(block);
if let Some(t) = h.template() {
t.render(r, ctx, rc, out)?;
};
rc.pop_block();
Ok(())
} else if let Some(t) = h.inverse() {
t.render(r, ctx, rc, out)
} else if r.strict_mode() {
Err(RenderError::strict_error(param.relative_path()))
} else {
Ok(())
}
}
sourcepub fn add_path(
&mut self,
k: &'reg str,
path: Vec<String>
) -> Result<(), RenderError>
pub fn add_path(
&mut self,
k: &'reg str,
path: Vec<String>
) -> Result<(), RenderError>
Add a path reference as the parameter. The path
is a vector of path
segments the relative to current block’s base path.
Examples found in repository?
src/helpers/helper_each.rs (line 42)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn set_block_param<'reg: 'rc, 'rc>(
block: &mut BlockContext<'reg>,
h: &Helper<'reg, 'rc>,
base_path: Option<&Vec<String>>,
k: &Json,
v: &Json,
) -> Result<(), RenderError> {
if let Some(bp_val) = h.block_param() {
let mut params = BlockParams::new();
if base_path.is_some() {
params.add_path(bp_val, Vec::with_capacity(0))?;
} else {
params.add_value(bp_val, v.clone())?;
}
block.set_block_params(params);
} else if let Some((bp_val, bp_key)) = h.block_param_pair() {
let mut params = BlockParams::new();
if base_path.is_some() {
params.add_path(bp_val, Vec::with_capacity(0))?;
} else {
params.add_value(bp_val, v.clone())?;
}
params.add_value(bp_key, k.clone())?;
block.set_block_params(params);
}
Ok(())
}
More examples
src/helpers/helper_with.rs (line 33)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn call<'reg: 'rc, 'rc>(
&self,
h: &Helper<'reg, 'rc>,
r: &'reg Registry<'reg>,
ctx: &'rc Context,
rc: &mut RenderContext<'reg, 'rc>,
out: &mut dyn Output,
) -> HelperResult {
let param = h
.param(0)
.ok_or_else(|| RenderError::new("Param not found for helper \"with\""))?;
if param.value().is_truthy(false) {
let mut block = create_block(param);
if let Some(block_param) = h.block_param() {
let mut params = BlockParams::new();
if param.context_path().is_some() {
params.add_path(block_param, Vec::with_capacity(0))?;
} else {
params.add_value(block_param, param.value().clone())?;
}
block.set_block_params(params);
}
rc.push_block(block);
if let Some(t) = h.template() {
t.render(r, ctx, rc, out)?;
};
rc.pop_block();
Ok(())
} else if let Some(t) = h.inverse() {
t.render(r, ctx, rc, out)
} else if r.strict_mode() {
Err(RenderError::strict_error(param.relative_path()))
} else {
Ok(())
}
}
sourcepub fn add_value(&mut self, k: &'reg str, v: Json) -> Result<(), RenderError>
pub fn add_value(&mut self, k: &'reg str, v: Json) -> Result<(), RenderError>
Add a value as parameter.
Examples found in repository?
src/helpers/helper_each.rs (line 44)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn set_block_param<'reg: 'rc, 'rc>(
block: &mut BlockContext<'reg>,
h: &Helper<'reg, 'rc>,
base_path: Option<&Vec<String>>,
k: &Json,
v: &Json,
) -> Result<(), RenderError> {
if let Some(bp_val) = h.block_param() {
let mut params = BlockParams::new();
if base_path.is_some() {
params.add_path(bp_val, Vec::with_capacity(0))?;
} else {
params.add_value(bp_val, v.clone())?;
}
block.set_block_params(params);
} else if let Some((bp_val, bp_key)) = h.block_param_pair() {
let mut params = BlockParams::new();
if base_path.is_some() {
params.add_path(bp_val, Vec::with_capacity(0))?;
} else {
params.add_value(bp_val, v.clone())?;
}
params.add_value(bp_key, k.clone())?;
block.set_block_params(params);
}
Ok(())
}
More examples
src/helpers/helper_with.rs (line 35)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn call<'reg: 'rc, 'rc>(
&self,
h: &Helper<'reg, 'rc>,
r: &'reg Registry<'reg>,
ctx: &'rc Context,
rc: &mut RenderContext<'reg, 'rc>,
out: &mut dyn Output,
) -> HelperResult {
let param = h
.param(0)
.ok_or_else(|| RenderError::new("Param not found for helper \"with\""))?;
if param.value().is_truthy(false) {
let mut block = create_block(param);
if let Some(block_param) = h.block_param() {
let mut params = BlockParams::new();
if param.context_path().is_some() {
params.add_path(block_param, Vec::with_capacity(0))?;
} else {
params.add_value(block_param, param.value().clone())?;
}
block.set_block_params(params);
}
rc.push_block(block);
if let Some(t) = h.template() {
t.render(r, ctx, rc, out)?;
};
rc.pop_block();
Ok(())
} else if let Some(t) = h.inverse() {
t.render(r, ctx, rc, out)
} else if r.strict_mode() {
Err(RenderError::strict_error(param.relative_path()))
} else {
Ok(())
}
}
Trait Implementations§
source§impl<'reg> Clone for BlockParams<'reg>
impl<'reg> Clone for BlockParams<'reg>
source§fn clone(&self) -> BlockParams<'reg>
fn clone(&self) -> BlockParams<'reg>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'reg> Debug for BlockParams<'reg>
impl<'reg> Debug for BlockParams<'reg>
source§impl<'reg> Default for BlockParams<'reg>
impl<'reg> Default for BlockParams<'reg>
source§fn default() -> BlockParams<'reg>
fn default() -> BlockParams<'reg>
Returns the “default value” for a type. Read more