-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
481e1d0
commit e249077
Showing
21 changed files
with
862 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,44 @@ | ||
use rrgen::RRgen; | ||
use serde_json::json; | ||
|
||
use super::{AppInfo, Result}; | ||
use crate as gen; | ||
|
||
const API_CONTROLLER_CONTROLLER_T: &str = include_str!("templates/controller/api/controller.t"); | ||
const API_CONTROLLER_TEST_T: &str = include_str!("templates/controller/api/test.t"); | ||
|
||
const HTMX_CONTROLLER_CONTROLLER_T: &str = include_str!("templates/controller/htmx/controller.t"); | ||
const HTMX_VIEW_T: &str = include_str!("templates/controller/htmx/view.t"); | ||
|
||
const HTML_CONTROLLER_CONTROLLER_T: &str = include_str!("templates/controller/html/controller.t"); | ||
const HTML_VIEW_T: &str = include_str!("templates/controller/html/view.t"); | ||
|
||
use super::{collect_messages, AppInfo, Result}; | ||
use rrgen::{GenResult, RRgen}; | ||
use serde_json::json; | ||
use std::path::Path; | ||
|
||
pub fn generate( | ||
rrgen: &RRgen, | ||
name: &str, | ||
actions: &[String], | ||
kind: &gen::ScaffoldKind, | ||
appinfo: &AppInfo, | ||
) -> Result<String> { | ||
) -> Result<Vec<GenResult>> { | ||
let vars = json!({"name": name, "actions": actions, "pkg_name": appinfo.app_name}); | ||
match kind { | ||
gen::ScaffoldKind::Api => { | ||
let res1 = rrgen.generate(API_CONTROLLER_CONTROLLER_T, &vars)?; | ||
let res2 = rrgen.generate(API_CONTROLLER_TEST_T, &vars)?; | ||
let messages = collect_messages(vec![res1, res2]); | ||
Ok(messages) | ||
} | ||
gen::ScaffoldKind::Api => gen::render_template(rrgen, Path::new("controller/api"), &vars), | ||
gen::ScaffoldKind::Html => { | ||
let mut messages = Vec::new(); | ||
let res = rrgen.generate(HTML_CONTROLLER_CONTROLLER_T, &vars)?; | ||
messages.push(res); | ||
let mut gen_result = | ||
gen::render_template(rrgen, Path::new("controller/html/controller.t"), &vars)?; | ||
for action in actions { | ||
let vars = json!({"name": name, "action": action, "pkg_name": appinfo.app_name}); | ||
messages.push(rrgen.generate(HTML_VIEW_T, &vars)?); | ||
gen_result.extend(gen::render_template( | ||
rrgen, | ||
Path::new("controller/html/view.t"), | ||
&vars, | ||
)?); | ||
} | ||
Ok(collect_messages(messages)) | ||
Ok(gen_result) | ||
} | ||
gen::ScaffoldKind::Htmx => { | ||
let mut messages = Vec::new(); | ||
let res = rrgen.generate(HTMX_CONTROLLER_CONTROLLER_T, &vars)?; | ||
messages.push(res); | ||
let mut gen_result = | ||
gen::render_template(rrgen, Path::new("controller/htmx/controller.t"), &vars)?; | ||
for action in actions { | ||
let vars = json!({"name": name, "action": action, "pkg_name": appinfo.app_name}); | ||
messages.push(rrgen.generate(HTMX_VIEW_T, &vars)?); | ||
gen_result.extend(gen::render_template( | ||
rrgen, | ||
Path::new("controller/htmx/view.t"), | ||
&vars, | ||
)?); | ||
} | ||
Ok(collect_messages(messages)) | ||
Ok(gen_result) | ||
} | ||
} | ||
} |
Oops, something went wrong.