proto-seeder

A prototype to integrate to seeder later

Description

This proto cli should be able to parse a rust file and read the Routes enum :

```rust

#[derive(Debug, PartialEq, Clone, RoutingModules)] #[modulespath = "pages"] pub enum Routes { Other { id: String, children: Settings, }, #[guard = "loggeduser => adminguard => notauthorizedview"] Admin { // will load module "admin.rs" // will load model.admin and as well // will check init has correct arguments // will check view has correct arguments query: IndexMap, }, #[guard = "loggeduser => userguard => notloggeduserview"] Dashboard(DashboardRoutes), // will load module "dashboard" Profile { // will load module "profile" id: String, }, #[guard = "loggeduser => adminguard => notauthorizedview"] #[view = " => mystuff"] MyStuff, #[view = " => notfound"] #[defaultroute] NotFound, #[view = " => home"] #[aspath = ""] Root, }

```

Example

See the following lib.rs

```rust use seed::{prelude::*, *}; extern crate heck; use crate::{ models::user::{LoggedData, Role}, theme::Theme, top_bar::TopBar, };

[macro_use]

extern crate seedrouting; use seedrouting::{View, *};

use std::fmt::Debug;

// ------ ------ // Init // ------ ------

fn init(url: Url, orders: &mut impl Orders) -> Model { orders .subscribe(Msg::UrlChanged) .subscribe(Msg::UrlRequested) .subscribe(Msg::UserLogged);

let mut router: Router<Routes> = Router::new();
router.init_url_and_navigation(url);

Model {
    router,
}

}

[derive(Debug, PartialEq, Clone, RoutingModules)]

[modules_path = "pages"]

pub enum Routes { #[guard = " => guard => forbidden"] Login { query: IndexMap, // -> http://localhost:8000/login?name=JohnDoe }, #[guard = " => guard => forbidden"] Dashboard(pages::dashboard::Routes), // -> http://localhost:8000/dashboard/* #[guard = " => adminguard => forbiddenuser"] Admin { // -> /admin/:id/* id: String, children: pages::admin::Routes, }, #[defaultroute] #[view = " => notfound"] // -> http://localhost:8000/notfound* NotFound, #[view = " => forbidden"] // -> http://localhost:8000/forbidden* Forbidden, #[aspath = ""] #[view = "theme => home"] // -> http://localhost:8000/ Home, }

// ------ ------ // Model // ------ ------

struct Model { router:Router }

pub enum Msg { }

fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders) { //---- update body ---- }

// ------ ------ // View // ------ ------ /// View function which renders stuff to html fn view(model: &Model) -> impl IntoNodes { vec![ header(&model), if let Some(route) = &model.router.current_route { route.view(model) } else { home(&model.theme) }, ] }

fn header(model: &Model) -> Node { div![ TopBar::new(whoisconnected(model)) .style(model.theme.clone()) .setuserloginstate(model.loggeduser.issome()) .content(div![ style! {St::Display => "flex" }, button![ "back", attrs! { At::Disabled => (!model.router.canback()).asatvalue(), }, ev(Ev::Click, || Msg::GoBack) ], button![ "forward", attrs! { At::Disabled => (!model.router.canforward()).asatvalue(), }, ev(Ev::Click, || Msg::GoForward) ], span![style! {St::Flex => "5" },], buildaccountbutton(model.loggeduser.issome()) ]), renderroute(model) ] } fn home(theme: &Theme) -> Node { div![ div!["Welcome home!"], match theme { Theme::Dark => { button![ "Switch to Light", ev(Ev::Click, || Msg::SwitchToTheme(Theme::Light)) ] } Theme::Light => { button![ "Switch to Dark", ev(Ev::Click, || Msg::SwitchToTheme(Theme::Dark)) ] } } ] } // ------ Other view content // ------ ------ // Start // ------ ------

[wasm_bindgen(start)]

pub fn start() { App::start("app", init, update, view); } fn notfound(model: &Model) -> Node { div!["notfound"] }

```

You should get the following output from this command at root of your project:

proto_seeder ./src/lib.rs

if you go to /src and run :

proto_seeder lib.rs

Will not work because of https://github.com/arn-the-long-beard/proto-seeder/issues/1

Here is an example of output with the example.

-> found 3 locals view to create -> found 2 guards to create -> found 3 modules to create [+] finished parsing the file [+] created folder ./examples/backbone_app/src/pages [+] created file at ./examples/backbone_app/src/pages/mod.rs [+] updated ./examples/backbone_app/src/pages/mod.rs for import parent module => pub mod login; pub mod dashboard; pub mod admin; [+] created file at ./examples/backbone_app/src/pages/login.rs [+] updated ./examples/backbone_app/src/pages/login.rs [+] updated ./examples/backbone_app/src/pages/login.rs for adding pub fn init() [+] updated ./examples/backbone_app/src/pages/login.rs for adding pub struct Model{} [+] updated ./examples/backbone_app/src/pages/login.rs for adding pub enum Routes{} [+] updated ./examples/backbone_app/src/pages/login.rs for adding pub enum Msg{} [+] updated ./examples/backbone_app/src/pages/login.rs for adding pub fn update() [+] updated ./examples/backbone_app/src/pages/login.rs for adding pub fn view() [+] created file at ./examples/backbone_app/src/pages/dashboard.rs [+] updated ./examples/backbone_app/src/pages/dashboard.rs [+] updated ./examples/backbone_app/src/pages/dashboard.rs for adding pub fn init() [+] updated ./examples/backbone_app/src/pages/dashboard.rs for adding pub struct Model{} [+] updated ./examples/backbone_app/src/pages/dashboard.rs for adding pub enum Routes{} [+] updated ./examples/backbone_app/src/pages/dashboard.rs for adding pub enum Msg{} [+] updated ./examples/backbone_app/src/pages/dashboard.rs for adding pub fn update() [+] updated ./examples/backbone_app/src/pages/dashboard.rs for adding pub fn view() [+] created file at ./examples/backbone_app/src/pages/admin.rs [+] updated ./examples/backbone_app/src/pages/admin.rs [+] updated ./examples/backbone_app/src/pages/admin.rs for adding pub fn init() [+] updated ./examples/backbone_app/src/pages/admin.rs for adding pub struct Model{} [+] updated ./examples/backbone_app/src/pages/admin.rs for adding pub enum Routes{} [+] updated ./examples/backbone_app/src/pages/admin.rs for adding pub enum Msg{} [+] updated ./examples/backbone_app/src/pages/admin.rs for adding pub fn update() [+] updated ./examples/backbone_app/src/pages/admin.rs for adding pub fn view() [+] found file to update at ./examples/backbone_app/src/lib.rs [=>] No need to create view for route NotFound [ => ] as fn not_found () [+] found file to update at ./examples/backbone_app/src/lib.rs [+] updated ./examples/backbone_app/src/lib.rs for writing local view forbidden for route Forbidden [+] updated ./examples/backbone_app/src/lib.rs for Added indentation [+] found file to update at ./examples/backbone_app/src/lib.rs [=>] No need to create view for route Home [ => ] as fn home () [+] found file to update at ./examples/backbone_app/src/lib.rs [+] updated ./examples/backbone_app/src/lib.rs for writing local guard as guard [+] updated ./examples/backbone_app/src/lib.rs for Added indentation [=>] No need to create redirect forbidden for [ => ] guard () [+] found file to update at ./examples/backbone_app/src/lib.rs [+] updated ./examples/backbone_app/src/lib.rs for writing local guard as admin_guard [+] updated ./examples/backbone_app/src/lib.rs for Added indentation [+] updated ./examples/backbone_app/src/lib.rs for writing redirect for guard as forbidden_user [+] updated ./examples/backbone_app/src/lib.rs for Added indentation [=>] Created 4 new files [=>] Updated 2 files [=>] Ignored 0 files ▪▪▪▪▪ Done You should have the following new code in lib.rs as well

rust fn not_found(model : &Model) -> Node<Msg>{div!["not_found"]} fn forbidden(model : &Model) -> Node<Msg>{div!["forbidden"]} fn guard(model : &Model) -> Option<bool> {log!("Write condition")} fn admin_guard(model : &Model) -> Option<bool> {log!("Write condition")} fn forbidden_user(model : &Model) -> Node<Msg>{div!["forbidden_user"]}

And 4 new files with TEA code inside and a new folder for this example.

Todo

For later - Detect if future file already exist -> Done - If future file already exist, try to apply the command line recursively to its Routes enum? - Check if content already exist, then it will not add it -> Done - Check if local content ( local views and guard ) already exist, then it will not add it -> Done