aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-10-06 11:30:37 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-11-01 12:52:09 +0100
commit145420b68ebe6d310a81c8965f9a9e81aa4dbfe1 (patch)
tree137aab999cdf04241da3bce70c29e4ae7410fcb1 /askama_derive/src
parent94d3bc1dc039f26fb157e50215dcf139078ab231 (diff)
downloadaskama-145420b68ebe6d310a81c8965f9a9e81aa4dbfe1.tar.gz
askama-145420b68ebe6d310a81c8965f9a9e81aa4dbfe1.tar.bz2
askama-145420b68ebe6d310a81c8965f9a9e81aa4dbfe1.zip
Inline nested derive_template() implementation
Diffstat (limited to 'askama_derive/src')
-rw-r--r--askama_derive/src/generator.rs12
-rw-r--r--askama_derive/src/lib.rs6
2 files changed, 6 insertions, 12 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 6f561f8..cb4b102 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -7,7 +7,6 @@ use parser::node::{
Call, Comment, CondTest, If, Include, Let, Lit, Loop, Match, Target, Whitespace, Ws,
};
use parser::{Expr, Node, Parsed};
-use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::punctuated::Punctuated;
@@ -15,15 +14,6 @@ use std::collections::hash_map::{Entry, HashMap};
use std::path::{Path, PathBuf};
use std::{cmp, hash, mem, str};
-/// The actual implementation for askama_derive::Template
-pub(crate) fn derive_template(input: TokenStream) -> TokenStream {
- let ast: syn::DeriveInput = syn::parse(input).unwrap();
- match build_template(&ast) {
- Ok(source) => source.parse().unwrap(),
- Err(e) => e.into_compile_error(),
- }
-}
-
/// Takes a `syn::DeriveInput` and generates source code for it
///
/// Reads the metadata from the `template()` attribute to get the template
@@ -31,7 +21,7 @@ pub(crate) fn derive_template(input: TokenStream) -> TokenStream {
/// parsed, and the parse tree is fed to the code generator. Will print
/// the parse tree and/or generated source according to the `print` key's
/// value as passed to the `template()` attribute.
-fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
+pub(crate) fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
let template_args = TemplateArgs::new(ast)?;
let config_toml = read_config_file(template_args.config_path.as_deref())?;
let config = Config::new(&config_toml, template_args.whitespace.as_ref())?;
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs
index 8a737aa..3b80635 100644
--- a/askama_derive/src/lib.rs
+++ b/askama_derive/src/lib.rs
@@ -16,7 +16,11 @@ mod input;
#[proc_macro_derive(Template, attributes(template))]
pub fn derive_template(input: TokenStream) -> TokenStream {
- generator::derive_template(input)
+ let ast = syn::parse::<syn::DeriveInput>(input).unwrap();
+ match generator::build_template(&ast) {
+ Ok(source) => source.parse().unwrap(),
+ Err(e) => e.into_compile_error(),
+ }
}
#[derive(Debug, Clone)]