Added back in reference.
This commit is contained in:
parent
da6655d4b6
commit
bbc1a24631
@ -1,8 +1,10 @@
|
|||||||
use crate::parser::template;
|
use crate::parser::template;
|
||||||
use crate::parser::Body;
|
use crate::parser::Body;
|
||||||
use crate::parser::DustTag;
|
use crate::parser::DustTag;
|
||||||
|
use crate::parser::Filter;
|
||||||
use crate::parser::PartialNameElement;
|
use crate::parser::PartialNameElement;
|
||||||
use crate::parser::Path;
|
use crate::parser::Path;
|
||||||
|
use crate::parser::Special;
|
||||||
use crate::parser::Template;
|
use crate::parser::Template;
|
||||||
use crate::parser::TemplateElement;
|
use crate::parser::TemplateElement;
|
||||||
use crate::renderer::breadcrumb_tree::BreadcrumbTree;
|
use crate::renderer::breadcrumb_tree::BreadcrumbTree;
|
||||||
@ -11,6 +13,7 @@ use crate::renderer::context_element::ContextElement;
|
|||||||
use crate::renderer::context_element::IntoContextElement;
|
use crate::renderer::context_element::IntoContextElement;
|
||||||
use crate::renderer::errors::CompileError;
|
use crate::renderer::errors::CompileError;
|
||||||
use crate::renderer::errors::RenderError;
|
use crate::renderer::errors::RenderError;
|
||||||
|
use crate::renderer::errors::WalkError;
|
||||||
use crate::renderer::inline_partial_tree::extract_inline_partials;
|
use crate::renderer::inline_partial_tree::extract_inline_partials;
|
||||||
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
|
use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
|
||||||
use crate::renderer::tree_walking::walk_path;
|
use crate::renderer::tree_walking::walk_path;
|
||||||
@ -132,6 +135,32 @@ impl<'a> DustRenderer<'a> {
|
|||||||
blocks: &'a BlockContext<'a>,
|
blocks: &'a BlockContext<'a>,
|
||||||
) -> Result<String, RenderError> {
|
) -> Result<String, RenderError> {
|
||||||
match tag {
|
match tag {
|
||||||
|
DustTag::DTComment(_comment) => (),
|
||||||
|
DustTag::DTSpecial(special) => {
|
||||||
|
return Ok(match special {
|
||||||
|
Special::Space => " ",
|
||||||
|
Special::NewLine => "\n",
|
||||||
|
Special::CarriageReturn => "\r",
|
||||||
|
Special::LeftCurlyBrace => "{",
|
||||||
|
Special::RightCurlyBrace => "}",
|
||||||
|
}
|
||||||
|
.to_owned())
|
||||||
|
}
|
||||||
|
DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()),
|
||||||
|
DustTag::DTReference(reference) => {
|
||||||
|
let val = walk_path(breadcrumbs, &reference.path.keys)
|
||||||
|
.map(|ice| ice.into_context_element(self, breadcrumbs));
|
||||||
|
match val {
|
||||||
|
Err(WalkError::CantWalk) => return Ok("".to_owned()),
|
||||||
|
Ok(final_val) => {
|
||||||
|
return if final_val.is_truthy() {
|
||||||
|
final_val.render(&Self::preprocess_filters(&reference.filters))
|
||||||
|
} else {
|
||||||
|
Ok("".to_owned())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => panic!("Unsupported tag"),
|
_ => panic!("Unsupported tag"),
|
||||||
}
|
}
|
||||||
Ok("".to_owned())
|
Ok("".to_owned())
|
||||||
@ -281,6 +310,21 @@ impl<'a> DustRenderer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn preprocess_filters(filters: &Vec<Filter>) -> Vec<Filter> {
|
||||||
|
let mut final_filters: Vec<Filter> = filters
|
||||||
|
.into_iter()
|
||||||
|
.filter(|f| f != &&Filter::DisableHtmlEncode)
|
||||||
|
.map(|f| f.clone())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// If the user has not specified any escaping filter (|s or
|
||||||
|
// |h), automatically add an html escape filter
|
||||||
|
if !filters.iter().any(|f| f == &Filter::DisableHtmlEncode) {
|
||||||
|
final_filters.push(Filter::HtmlEncode);
|
||||||
|
}
|
||||||
|
final_filters
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlockContext<'a> {
|
struct BlockContext<'a> {
|
||||||
|
Loading…
Reference in New Issue
Block a user