|
7 | 7 |
|
8 | 8 | mod node_handlers; |
9 | 9 |
|
10 | | -use std::{ |
11 | | - collections::{HashMap, HashSet}, |
12 | | - os::linux::raw, |
13 | | -}; |
| 10 | +use std::collections::{HashMap, HashSet}; |
14 | 11 |
|
15 | 12 | use node_handlers::{ |
16 | 13 | handle_block, handle_comment, handle_doctype, handle_element, handle_fragment, handle_raw_text, |
17 | 14 | handle_text, |
18 | 15 | }; |
19 | 16 | use proc_macro::TokenStream; |
20 | | -use proc_macro2::{Ident, Span, TokenStream as TokenStream2}; |
| 17 | +use proc_macro2::{Ident, TokenStream as TokenStream2}; |
21 | 18 | use proc_macro2_diagnostics::Diagnostic; |
22 | | -use quote::{quote, quote_spanned}; |
| 19 | +use quote::quote; |
| 20 | +#[cfg(feature = "basic-css")] |
| 21 | +use quote::quote_spanned; |
23 | 22 | use rstml::{node::Node, Parser, ParserConfig}; |
24 | | -use syn::{spanned::Spanned, Type}; |
| 23 | +#[cfg(feature = "basic-css")] |
| 24 | +use syn::spanned::Spanned; |
| 25 | +use syn::Type; |
25 | 26 |
|
26 | 27 | #[proc_macro] |
27 | 28 | pub fn html(tokens: TokenStream) -> TokenStream { |
28 | 29 | html_inner(tokens.into(), None) |
29 | 30 | } |
30 | 31 |
|
| 32 | +#[cfg(feature = "basic-css")] |
31 | 33 | #[proc_macro] |
32 | 34 | pub fn style(tokens: TokenStream) -> TokenStream { |
33 | 35 | style_inner(tokens.into()) |
@@ -178,11 +180,22 @@ fn tokenize_nodes( |
178 | 180 | (token_streams, diagnostics) |
179 | 181 | } |
180 | 182 |
|
| 183 | +/// Naive conversion of a rust token stream into css content. |
| 184 | +/// |
| 185 | +/// Strips all whitespace from the given tokens, concatenates them into a |
| 186 | +/// single string and returns a token stream of the given css content |
| 187 | +/// wrapped in an HTML style tag. |
| 188 | +#[cfg(feature = "basic-css")] |
181 | 189 | fn style_inner(tokens: TokenStream2) -> TokenStream { |
182 | 190 | let span = tokens.span(); |
183 | 191 | let raw_css = tokens |
184 | 192 | .into_iter() |
185 | | - .map(|t| t.to_string().split_whitespace().collect::<String>()) |
| 193 | + .map(|token_tree| { |
| 194 | + token_tree |
| 195 | + .to_string() |
| 196 | + .split_whitespace() |
| 197 | + .collect::<String>() |
| 198 | + }) |
186 | 199 | .collect::<String>(); |
187 | 200 |
|
188 | 201 | quote_spanned! { span=> |
|
0 commit comments