Crates.io | proto_seeder |
lib.rs | proto_seeder |
version | 0.0.8 |
source | src |
created_at | 2021-02-04 12:54:00.755359 |
updated_at | 2021-02-26 10:41:39.816826 |
description | Cli to create files from Routes with seed_routing |
homepage | https://github.com/arn-the-long-beard/proto-seeder |
repository | |
max_upload_size | |
id | 350496 |
size | 120,428 |
A Cli prototype to integrate to seeder later.
It generates files and methods for a Seed app from a Route
enum
.
This proto cli should be able to parse a rust file and read the Route enum :
#[derive(Debug, PartialEq, Clone, RoutingModules)]
#[modules_path = "pages"]
pub enum Route {
Other {
id: String,
children: Settings,
},
#[guard = "logged_user => admin_guard => not_authorized_view"]
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<String, String>,
},
#[guard = "logged_user => user_guard => not_logged_user_view"]
Dashboard(DashboardRoutes), // will load module "dashboard"
Profile { // will load module "profile"
id: String,
},
#[guard = "logged_user => admin_guard => not_authorized_view"]
#[view = " => my_stuff"]
MyStuff,
#[view = " => not_found"]
#[default_route]
NotFound,
#[view = " => home"]
#[as_path = ""]
Root,
}
See the following lib.rs
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
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.
#[modules_path]
#[view = "Model/prop => local_view"]
#[guard = "Model/prop => guard => callback_view"]
For later
Detect if future file already exist
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
Check if local content ( local views and guard ) already exist, then it will not add it
Check if update has been made or not and display message instead of now which is actually the number of file to update. Needs improvement.
Generate implementation of the router in lib.rs