mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Pass entire AST to code generator
This commit is contained in:
parent
69238e55d3
commit
3478395ca9
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -12,6 +12,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"htmlescape 0.3.1 (git+https://github.com/veddan/rust-htmlescape)",
|
||||
"nom 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -10,3 +10,4 @@ workspace = ".."
|
||||
[dependencies]
|
||||
htmlescape = { git = "https://github.com/veddan/rust-htmlescape" }
|
||||
nom = "2.0"
|
||||
syn = "0.11"
|
||||
|
@ -1,6 +1,7 @@
|
||||
use parser::{Conds, Expr, Node, Nodes, Target};
|
||||
use std::str;
|
||||
use std::collections::HashSet;
|
||||
use syn;
|
||||
|
||||
struct Generator {
|
||||
buf: String,
|
||||
@ -170,9 +171,9 @@ impl Generator {
|
||||
|
||||
}
|
||||
|
||||
pub fn generate(ctx_name: &str, tokens: &Vec<Node>) -> String {
|
||||
pub fn generate(ast: &syn::DeriveInput, tokens: &Vec<Node>) -> String {
|
||||
let mut gen = Generator::new();
|
||||
gen.init(ctx_name);
|
||||
gen.init(ast.ident.as_ref());
|
||||
gen.handle(tokens);
|
||||
gen.finalize();
|
||||
gen.result()
|
||||
|
@ -1,5 +1,6 @@
|
||||
#[macro_use]
|
||||
extern crate nom;
|
||||
extern crate syn;
|
||||
|
||||
pub trait Template {
|
||||
fn render(&self) -> String;
|
||||
|
@ -56,9 +56,8 @@ pub fn derive_template(input: TokenStream) -> TokenStream {
|
||||
_ => panic!("#[derive(Template)] can only be used with structs"),
|
||||
};
|
||||
|
||||
let name = &ast.ident;
|
||||
let path = get_path_from_attrs(&ast.attrs);
|
||||
let src = get_template_source(&path);
|
||||
let tokens = askama::parser::parse(&src);
|
||||
askama::generator::generate(name.as_ref(), &tokens).parse().unwrap()
|
||||
askama::generator::generate(&ast, &tokens).parse().unwrap()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user