🚑 [macros] Corrige rutas absolutas en html!

- Mantiene fijas las rutas absolutas en las funciones de la macro html!.
- Introduce un alias interno del crate (`extern crate self as pagetop;`)
  en `src/lib.rs` para que las expansiones funcionen uniformemente en
  tests, ejemplos y dependencias externas.
This commit is contained in:
Manuel Cillero 2025-07-16 02:53:49 +02:00
parent c4518d2eeb
commit 4eb9a87344
6 changed files with 14 additions and 56 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "pagetop-macros"
version = "0.0.4"
version = "0.0.5"
edition = "2021"
description = """\
@ -20,6 +20,5 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.95"
proc-macro2-diagnostics = { version = "0.10.1", default-features = false }
proc-macro-crate = "3.3.0"
quote = "1.0.40"
syn = { version = "2.0.104", features = ["full"] }

View file

@ -10,7 +10,6 @@ mod generate;
use ast::DiagnosticParse;
use proc_macro2::{Ident, Span, TokenStream};
use proc_macro2_diagnostics::Diagnostic;
use proc_macro_crate::{crate_name, FoundCrate};
use quote::quote;
use syn::parse::{ParseStream, Parser};
@ -41,20 +40,11 @@ pub fn expand(input: TokenStream) -> TokenStream {
let output_ident = Ident::new("__maud_output", Span::mixed_site());
let stmts = generate::generate(markups, output_ident.clone());
let found_crate = crate_name("pagetop").expect("pagetop must be in Cargo.toml");
let crate_ident = match found_crate {
FoundCrate::Itself => Ident::new("pagetop", Span::call_site()),
FoundCrate::Name(ref name) => Ident::new(name, Span::call_site()),
};
let pre_escaped = quote! {
#crate_ident::html::PreEscaped(#output_ident)
};
quote! {{
extern crate alloc;
let mut #output_ident = alloc::string::String::with_capacity(#size_hint);
#stmts
#(#diag_tokens)*
#pre_escaped
pagetop::html::PreEscaped(#output_ident)
}}
}

View file

@ -4,8 +4,6 @@ use syn::{parse_quote, token::Brace, Expr, Local};
use crate::maud::{ast::*, escape};
use proc_macro_crate::{crate_name, FoundCrate};
pub fn generate(markups: Markups<Element>, output_ident: Ident) -> TokenStream {
let mut build = Builder::new(output_ident.clone());
Generator::new(output_ident).markups(markups, &mut build);
@ -68,15 +66,9 @@ impl Generator {
fn splice(&self, expr: Expr, build: &mut Builder) {
let output_ident = &self.output_ident;
let found_crate = crate_name("pagetop").expect("pagetop debe existir en Cargo.toml");
let crate_ident = match found_crate {
FoundCrate::Itself => Ident::new("pagetop", Span::call_site()),
FoundCrate::Name(name) => Ident::new(&name, Span::call_site()),
};
build.push_tokens(quote! {
#crate_ident::html::html_private::render_to!(&(#expr), &mut #output_ident);
});
build.push_tokens(
quote!(pagetop::html::html_private::render_to!(&(#expr), &mut #output_ident);),
);
}
fn element(&self, element: Element, build: &mut Builder) {