rglw_api_codegen 0.0.1

Rustyglware websocket api.
Documentation
use proc_macro2::TokenStream;
use quote::quote;
use rglw::codegen_utils::macro_attribute_arguments::MacroAttributeArguments;
use syn::{ItemFn};

pub fn implementation(attributes: MacroAttributeArguments, input: ItemFn) -> TokenStream {
    let function_name = input.sig.ident;
    let mut body: Vec<TokenStream> = Vec::new();

    for statement in input.block.stmts.clone() {
        body.push(quote! {#statement});
    }

    let controller_function_name = function_name.to_string();
    let controller_path = attributes.find_string("path").expect("'path' parameter is required!");
    let expanded = quote! {
        pub fn #function_name() -> std::collections::HashMap<String, RglwApiRoute> {
            let controller_path = #controller_path;
            let controller_function_name = #controller_function_name;
            let mut routes: std::collections::HashMap<String, RglwApiRoute> = std::collections::HashMap::new();
            #(#body)*
            routes
        }
    };
    expanded
}