diff --git a/askama_derive/src/integration.rs b/askama_derive/src/integration.rs index 553c97f6..1558abe9 100644 --- a/askama_derive/src/integration.rs +++ b/askama_derive/src/integration.rs @@ -12,7 +12,7 @@ use syn::{ use crate::generator::TmplKind; use crate::input::{PartialTemplateArgs, TemplateArgs}; -use crate::{CompileError, Context, build_template_item}; +use crate::{CompileError, Context, Print, build_template_item}; /// Implement every integration for the given item pub(crate) fn impl_everything(ast: &DeriveInput, buf: &mut Buffer) { @@ -367,6 +367,11 @@ pub(crate) fn build_template_enum( &mut size_hint_arms, ); } + let print_code = enum_args.as_ref().is_some_and(|args| { + args.print + .is_some_and(|print| print == Print::Code || print == Print::All) + }); + if has_default_impl { let size_hint = build_template_item( buf, @@ -433,6 +438,9 @@ pub(crate) fn build_template_enum( }), enum_ast.span(), ); + if print_code { + eprintln!("{}", buf.to_string()); + } Ok(biggest_size_hint) } diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index 1af73b39..d36ae6d7 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -395,9 +395,6 @@ fn build_template_item( } let size_hint = template_to_string(buf, &input, &contexts, heritage.as_ref(), tmpl_kind)?; - if input.print == Print::Code || input.print == Print::All { - eprintln!("{}", buf.to_string()); - } Ok(size_hint) }