aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Guillaume Gomez <guillaume1.gomez@gmail.com>2022-04-21 15:41:02 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2022-04-21 16:09:24 +0200
commita64a7273319244813c657d912a0579f5619f0621 (patch)
tree67469a67ade7463f15866494a8a534c74576004b /askama_shared/src/generator.rs
parentb16085acd6290a46448b5a31d147ba6ac640316b (diff)
downloadaskama-a64a7273319244813c657d912a0579f5619f0621.tar.gz
askama-a64a7273319244813c657d912a0579f5619f0621.tar.bz2
askama-a64a7273319244813c657d912a0579f5619f0621.zip
Rename `suppress_whitespace` into `whitespace` and update expected values to "suppress" and "preserve"
Diffstat (limited to '')
-rw-r--r--askama_shared/src/generator.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs
index 9aec1d6..a8636fa 100644
--- a/askama_shared/src/generator.rs
+++ b/askama_shared/src/generator.rs
@@ -1,7 +1,9 @@
use crate::heritage::{Context, Heritage};
use crate::input::{Print, Source, TemplateInput};
use crate::parser::{parse, Cond, CondTest, Expr, Loop, Node, Target, When, Whitespace, Ws};
-use crate::{filters, get_template_source, read_config_file, CompileError, Config};
+use crate::{
+ filters, get_template_source, read_config_file, CompileError, Config, WhitespaceHandling,
+};
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
@@ -66,7 +68,7 @@ fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
&contexts,
heritage.as_ref(),
MapChain::new(),
- config.suppress_whitespace,
+ config.whitespace,
)
.build(&contexts[input.path.as_path()])?;
if input.print == Print::Code || input.print == Print::All {
@@ -251,8 +253,9 @@ struct Generator<'a, S: std::hash::BuildHasher> {
buf_writable: Vec<Writable<'a>>,
// Counter for write! hash named arguments
named: usize,
- // If set to `true`, the whitespace characters will be removed by default unless `+` is used.
- suppress_whitespace: bool,
+ // If set to `suppress`, the whitespace characters will be removed by default unless `+` is
+ // used.
+ whitespace: WhitespaceHandling,
}
impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
@@ -261,7 +264,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
contexts: &'n HashMap<&'n Path, Context<'n>, S>,
heritage: Option<&'n Heritage<'_>>,
locals: MapChain<'n, &'n str, LocalMeta>,
- suppress_whitespace: bool,
+ whitespace: WhitespaceHandling,
) -> Generator<'n, S> {
Generator {
input,
@@ -273,7 +276,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
super_block: None,
buf_writable: vec![],
named: 0,
- suppress_whitespace,
+ whitespace,
}
}
@@ -284,7 +287,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
self.contexts,
self.heritage,
locals,
- self.suppress_whitespace,
+ self.whitespace,
)
}
@@ -1820,7 +1823,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
match ws {
Some(Whitespace::Trim) => true,
Some(Whitespace::Preserve) => false,
- None => self.suppress_whitespace,
+ None => self.whitespace == WhitespaceHandling::Suppress,
}
}
@@ -1832,7 +1835,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
return;
}
- // If `suppress_whitespace` is enabled, we keep the whitespace characters only if there is
+ // If `whitespace` is set to `suppress`, we keep the whitespace characters only if there is
// a `+` character.
if !self.should_trim_ws(ws.0) {
let val = self.next_ws.unwrap();