sword-macros 0.3.0

Structured web framework built on top of tokio ecosystem, providing powerful features for building robust web applications.
Documentation
mod generation;
mod on_handler;

use super::shared::{CMetaStack, ControllerStruct, ParsedControllerKind};
use generation::generate_socketio_controller_builder;
use proc_macro::TokenStream;
use syn::{Error, Path};

pub use on_handler::expand_on_handler;

pub fn expand_socketio_controller(input: &ControllerStruct) -> syn::Result<TokenStream> {
    let ParsedControllerKind::SocketIo { namespace } = &input.kind else {
        return Err(Error::new(
            input.name.span(),
            "Invalid Socket.IO controller",
        ));
    };

    let controller_name = input.name.to_string();

    CMetaStack::push("socketio", "namespace", namespace);
    CMetaStack::push("socketio", "controller_name", &controller_name);

    let interceptors: Vec<Path> = input
        .interceptors
        .iter()
        .filter_map(|interceptor| interceptor.sword_path().cloned())
        .collect();

    Ok(TokenStream::from(generate_socketio_controller_builder(
        input,
        &interceptors,
    )?))
}