🚑 [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:
parent
c4518d2eeb
commit
4eb9a87344
6 changed files with 14 additions and 56 deletions
31
Cargo.lock
generated
31
Cargo.lock
generated
|
@ -1449,9 +1449,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pagetop-macros"
|
name = "pagetop-macros"
|
||||||
version = "0.0.4"
|
version = "0.0.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate",
|
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"proc-macro2-diagnostics",
|
"proc-macro2-diagnostics",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1618,15 +1617,6 @@ dependencies = [
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-crate"
|
|
||||||
version = "3.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
|
|
||||||
dependencies = [
|
|
||||||
"toml_edit",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-hack"
|
name = "proc-macro-hack"
|
||||||
version = "0.5.20+deprecated"
|
version = "0.5.20+deprecated"
|
||||||
|
@ -2185,17 +2175,11 @@ checksum = "f271e09bde39ab52250160a67e88577e0559ad77e9085de6e9051a2c4353f8f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_spanned",
|
"serde_spanned",
|
||||||
"toml_datetime 0.7.0",
|
"toml_datetime",
|
||||||
"toml_parser",
|
"toml_parser",
|
||||||
"winnow",
|
"winnow",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_datetime"
|
|
||||||
version = "0.6.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -2205,17 +2189,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_edit"
|
|
||||||
version = "0.22.27"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
|
|
||||||
dependencies = [
|
|
||||||
"indexmap",
|
|
||||||
"toml_datetime 0.6.11",
|
|
||||||
"winnow",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_parser"
|
name = "toml_parser"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pagetop-macros"
|
name = "pagetop-macros"
|
||||||
version = "0.0.4"
|
version = "0.0.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
description = """\
|
description = """\
|
||||||
|
@ -20,6 +20,5 @@ proc-macro = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1.0.95"
|
proc-macro2 = "1.0.95"
|
||||||
proc-macro2-diagnostics = { version = "0.10.1", default-features = false }
|
proc-macro2-diagnostics = { version = "0.10.1", default-features = false }
|
||||||
proc-macro-crate = "3.3.0"
|
|
||||||
quote = "1.0.40"
|
quote = "1.0.40"
|
||||||
syn = { version = "2.0.104", features = ["full"] }
|
syn = { version = "2.0.104", features = ["full"] }
|
||||||
|
|
|
@ -10,7 +10,6 @@ mod generate;
|
||||||
use ast::DiagnosticParse;
|
use ast::DiagnosticParse;
|
||||||
use proc_macro2::{Ident, Span, TokenStream};
|
use proc_macro2::{Ident, Span, TokenStream};
|
||||||
use proc_macro2_diagnostics::Diagnostic;
|
use proc_macro2_diagnostics::Diagnostic;
|
||||||
use proc_macro_crate::{crate_name, FoundCrate};
|
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::parse::{ParseStream, Parser};
|
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 output_ident = Ident::new("__maud_output", Span::mixed_site());
|
||||||
let stmts = generate::generate(markups, output_ident.clone());
|
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! {{
|
quote! {{
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
let mut #output_ident = alloc::string::String::with_capacity(#size_hint);
|
let mut #output_ident = alloc::string::String::with_capacity(#size_hint);
|
||||||
#stmts
|
#stmts
|
||||||
#(#diag_tokens)*
|
#(#diag_tokens)*
|
||||||
#pre_escaped
|
pagetop::html::PreEscaped(#output_ident)
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@ use syn::{parse_quote, token::Brace, Expr, Local};
|
||||||
|
|
||||||
use crate::maud::{ast::*, escape};
|
use crate::maud::{ast::*, escape};
|
||||||
|
|
||||||
use proc_macro_crate::{crate_name, FoundCrate};
|
|
||||||
|
|
||||||
pub fn generate(markups: Markups<Element>, output_ident: Ident) -> TokenStream {
|
pub fn generate(markups: Markups<Element>, output_ident: Ident) -> TokenStream {
|
||||||
let mut build = Builder::new(output_ident.clone());
|
let mut build = Builder::new(output_ident.clone());
|
||||||
Generator::new(output_ident).markups(markups, &mut build);
|
Generator::new(output_ident).markups(markups, &mut build);
|
||||||
|
@ -68,15 +66,9 @@ impl Generator {
|
||||||
|
|
||||||
fn splice(&self, expr: Expr, build: &mut Builder) {
|
fn splice(&self, expr: Expr, build: &mut Builder) {
|
||||||
let output_ident = &self.output_ident;
|
let output_ident = &self.output_ident;
|
||||||
|
build.push_tokens(
|
||||||
let found_crate = crate_name("pagetop").expect("pagetop debe existir en Cargo.toml");
|
quote!(pagetop::html::html_private::render_to!(&(#expr), &mut #output_ident);),
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn element(&self, element: Element, build: &mut Builder) {
|
fn element(&self, element: Element, build: &mut Builder) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ impl fmt::Write for Escaper<'_> {
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use pagetop::html::{html, Markup, Render};
|
/// use pagetop::prelude::*;
|
||||||
///
|
///
|
||||||
/// /// Provides a shorthand for linking to a CSS stylesheet.
|
/// /// Provides a shorthand for linking to a CSS stylesheet.
|
||||||
/// pub struct Stylesheet(&'static str);
|
/// pub struct Stylesheet(&'static str);
|
||||||
|
@ -195,7 +195,7 @@ impl_render_with_itoa! {
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use pagetop::html::{display, html};
|
/// use pagetop::prelude::*;
|
||||||
/// use std::net::Ipv4Addr;
|
/// use std::net::Ipv4Addr;
|
||||||
///
|
///
|
||||||
/// let ip_address = Ipv4Addr::new(127, 0, 0, 1);
|
/// let ip_address = Ipv4Addr::new(127, 0, 0, 1);
|
||||||
|
@ -266,7 +266,7 @@ impl<T: Default> Default for PreEscaped<T> {
|
||||||
/// A minimal web page:
|
/// A minimal web page:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use pagetop::html::{DOCTYPE, html};
|
/// use pagetop::prelude::*;
|
||||||
///
|
///
|
||||||
/// let markup = html! {
|
/// let markup = html! {
|
||||||
/// (DOCTYPE)
|
/// (DOCTYPE)
|
||||||
|
|
|
@ -34,6 +34,10 @@
|
||||||
html_favicon_url = "https://git.cillero.es/manuelcillero/pagetop/raw/branch/main/static/favicon.ico"
|
html_favicon_url = "https://git.cillero.es/manuelcillero/pagetop/raw/branch/main/static/favicon.ico"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
// Alias para que las rutas absolutas `::pagetop::…` generadas por las macros funcionen en el propio
|
||||||
|
// *crate*, en *crates* externos y en *doctests*.
|
||||||
|
extern crate self as pagetop;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue