feat: generate template page codegen script
This commit is contained in:
parent
6e62c8d8a9
commit
f62fb85fe6
1 changed files with 100 additions and 0 deletions
100
utils/generate_template_page.sh
Executable file
100
utils/generate_template_page.sh
Executable file
|
@ -0,0 +1,100 @@
|
|||
#!/bin/bash
|
||||
|
||||
help() {
|
||||
echo "Usage: web_test_generator.sh
|
||||
<domain name>
|
||||
<const page name (all caps)>
|
||||
<underscore lowercase page name>
|
||||
<camel case page name>"
|
||||
}
|
||||
|
||||
|
||||
run() {
|
||||
echo "
|
||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
use std::cell::RefCell;
|
||||
|
||||
use derive_builder::*;
|
||||
use derive_more::*;
|
||||
use serde::*;
|
||||
use tera::Context;
|
||||
use url::Url;
|
||||
|
||||
pub use super::*;
|
||||
use crate::utils::*;
|
||||
|
||||
pub const $2_PAGE: TemplateFile = TemplateFile::new(
|
||||
\"$1.$3\",
|
||||
\"$1/$3.html\",
|
||||
);
|
||||
|
||||
pub fn register_templates(t: &mut tera::Tera) {
|
||||
$2_PAGE
|
||||
.register(t)
|
||||
.expect($2_PAGE.name);
|
||||
}
|
||||
|
||||
pub struct $4Page {
|
||||
ctx: RefCell<Context>,
|
||||
}
|
||||
|
||||
impl $4Page {
|
||||
pub fn new() -> Self {
|
||||
let mut ctx = context();
|
||||
|
||||
//ctx.insert(PAYLOAD_KEY, p);
|
||||
|
||||
let ctx = RefCell::new(ctx);
|
||||
Self { ctx }
|
||||
}
|
||||
|
||||
pub fn render(&self) -> String {
|
||||
TEMPLATES
|
||||
.render($2_PAGE.name, &self.ctx.borrow())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn page() -> String {
|
||||
let p = Self::new();
|
||||
p.render()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn render_page_and_write() {
|
||||
const FILE: &str = \"./tmp/$1-$3.html\";
|
||||
|
||||
let tw = TestWriterBuilder::default()
|
||||
.file(FILE.into())
|
||||
.contents($4Page::page())
|
||||
.build()
|
||||
.unwrap();
|
||||
tw.write();
|
||||
}
|
||||
} "
|
||||
}
|
||||
|
||||
|
||||
|
||||
if [ -z $1 ]
|
||||
then
|
||||
help
|
||||
elif [ -z $2 ]
|
||||
then
|
||||
help
|
||||
elif [ -z $3 ]
|
||||
then
|
||||
help
|
||||
elif [ -z $4 ]
|
||||
then
|
||||
help
|
||||
else
|
||||
run $1 $2 $3 $4 | wl-copy
|
||||
run $1 $2 $3 $4
|
||||
fi
|
Loading…
Reference in a new issue