Content-Length: 7732 | pFad | http://github.com/postgresml/postgresml/pull/1403.patch

thub.com From 21fb81fb0187e6f83651a76195634cc62f1aa086 Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 11 Apr 2024 10:51:01 -0700 Subject: [PATCH] --template-only & remove boilerplate --- packages/cargo-pgml-components/Cargo.lock | 2 +- packages/cargo-pgml-components/Cargo.toml | 2 +- .../src/frontend/components.rs | 18 ++++++++++------- .../src/frontend/templates/component.rs.tpl | 8 ++------ .../src/frontend/templates/sass.scss.tpl | 14 ------------- .../src/frontend/templates/stimulus.js.tpl | 6 +++--- .../src/frontend/templates/template.html.tpl | 4 +--- packages/cargo-pgml-components/src/main.rs | 20 +++++++++++++++---- 8 files changed, 35 insertions(+), 39 deletions(-) diff --git a/packages/cargo-pgml-components/Cargo.lock b/packages/cargo-pgml-components/Cargo.lock index d5f0f5649..84c11d69c 100644 --- a/packages/cargo-pgml-components/Cargo.lock +++ b/packages/cargo-pgml-components/Cargo.lock @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cargo-pgml-components" -version = "0.1.24" +version = "0.1.25" dependencies = [ "anyhow", "assert_cmd", diff --git a/packages/cargo-pgml-components/Cargo.toml b/packages/cargo-pgml-components/Cargo.toml index e4dacd2e2..ef52d8136 100644 --- a/packages/cargo-pgml-components/Cargo.toml +++ b/packages/cargo-pgml-components/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-pgml-components" -version = "0.1.24" +version = "0.1.25" edition = "2021" authors = ["PostgresML "] license = "MIT" diff --git a/packages/cargo-pgml-components/src/frontend/components.rs b/packages/cargo-pgml-components/src/frontend/components.rs index 06b73d6d8..6c9fdfe5c 100644 --- a/packages/cargo-pgml-components/src/frontend/components.rs +++ b/packages/cargo-pgml-components/src/frontend/components.rs @@ -86,7 +86,7 @@ impl From<&Path> for Component { } //github.com/ Add a new component. -pub fn add(path: &Path, overwrite: bool) { +pub fn add(path: &Path, overwrite: bool, template_only: bool) { if let Some(_extension) = path.extension() { error("component name should not contain an extension"); exit(1); @@ -154,17 +154,21 @@ pub fn add(path: &Path, overwrite: bool) { unwrap_or_exit!(write_to_file(&html_path, &html)); info(&format!("written {}", html_path.display())); - let stimulus_path = path.join(&component.controller_path()); - unwrap_or_exit!(write_to_file(&stimulus_path, &stimulus)); - info(&format!("written {}", stimulus_path.display())); + if !template_only { + let stimulus_path = path.join(&component.controller_path()); + unwrap_or_exit!(write_to_file(&stimulus_path, &stimulus)); + info(&format!("written {}", stimulus_path.display())); + } let rust_path = path.join("mod.rs"); unwrap_or_exit!(write_to_file(&rust_path, &rust)); info(&format!("written {}", rust_path.display())); - let scss_path = path.join(&format!("{}.scss", component.name())); - unwrap_or_exit!(write_to_file(&scss_path, &scss)); - info(&format!("written {}", scss_path.display())); + if !template_only { + let scss_path = path.join(&format!("{}.scss", component.name())); + unwrap_or_exit!(write_to_file(&scss_path, &scss)); + info(&format!("written {}", scss_path.display())); + } update_modules(); } diff --git a/packages/cargo-pgml-components/src/frontend/templates/component.rs.tpl b/packages/cargo-pgml-components/src/frontend/templates/component.rs.tpl index 8374c932a..ddb421294 100644 --- a/packages/cargo-pgml-components/src/frontend/templates/component.rs.tpl +++ b/packages/cargo-pgml-components/src/frontend/templates/component.rs.tpl @@ -3,15 +3,11 @@ use pgml_components::component; #[derive(TemplateOnce, Default)] #[template(path = "<%= component.path() %>/template.html")] -pub struct <%= component.rust_name() %> { - value: String, -} +pub struct <%= component.rust_name() %> {} impl <%= component.rust_name() %> { pub fn new() -> <%= component.rust_name() %> { - <%= component.rust_name() %> { - value: String::from("<%= component.full_path() %>"), - } + <%= component.rust_name() %> {} } } diff --git a/packages/cargo-pgml-components/src/frontend/templates/sass.scss.tpl b/packages/cargo-pgml-components/src/frontend/templates/sass.scss.tpl index 0ca359d44..5517eba73 100644 --- a/packages/cargo-pgml-components/src/frontend/templates/sass.scss.tpl +++ b/packages/cargo-pgml-components/src/frontend/templates/sass.scss.tpl @@ -1,17 +1,3 @@ div[data-controller="<%= component.controller_name() %>"] { - // Used to identify the component in the DOM. - // Delete these styles if you don't need them. - min-width: 100px; - width: 100%; - height: 100px; - background: red; - - display: flex; - justify-content: center; - align-items: center; - - h3 { - color: white; - } } diff --git a/packages/cargo-pgml-components/src/frontend/templates/stimulus.js.tpl b/packages/cargo-pgml-components/src/frontend/templates/stimulus.js.tpl index ea0564b98..de4922d70 100644 --- a/packages/cargo-pgml-components/src/frontend/templates/stimulus.js.tpl +++ b/packages/cargo-pgml-components/src/frontend/templates/stimulus.js.tpl @@ -1,11 +1,11 @@ import { Controller } from '@hotwired/stimulus' export default class extends Controller { - static targets = [] - static outlets = [] + static targets = []; + static outlets = []; initialize() { - console.log('Initialized <%= controller_name %>') + console.log("Initialized <%= controller_name %>"); } connect() {} diff --git a/packages/cargo-pgml-components/src/frontend/templates/template.html.tpl b/packages/cargo-pgml-components/src/frontend/templates/template.html.tpl index 0cb25aab1..fa4ecafdd 100644 --- a/packages/cargo-pgml-components/src/frontend/templates/template.html.tpl +++ b/packages/cargo-pgml-components/src/frontend/templates/template.html.tpl @@ -1,5 +1,3 @@
-

- <%%= value %> -

+
diff --git a/packages/cargo-pgml-components/src/main.rs b/packages/cargo-pgml-components/src/main.rs index 65ae67015..abba907cd 100644 --- a/packages/cargo-pgml-components/src/main.rs +++ b/packages/cargo-pgml-components/src/main.rs @@ -89,7 +89,14 @@ enum Commands { #[derive(Subcommand, Debug)] enum AddCommands { //github.com/ Add a new component. - Component { name: String }, + Component { + //github.com/ Name of the new component. + name: String, + + //github.com/ Generate only the HTML template. Don't generate SCSS and JavaScript. + #[arg(short, long, default_value = "false")] + template_only: bool, + }, } #[derive(Subcommand, Debug)] @@ -114,9 +121,14 @@ fn main() { lock, } => bundle(config, minify, debug, lock), Commands::Add(command) => match command { - AddCommands::Component { name } => { - crate::frontend::components::add(&Path::new(&name), pgml_commands.overwrite) - } + AddCommands::Component { + name, + template_only, + } => crate::frontend::components::add( + &Path::new(&name), + pgml_commands.overwrite, + template_only, + ), }, Commands::LocalDev(command) => match command { LocalDevCommands::Check {} => local_dev::setup(),








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgresml/postgresml/pull/1403.patch

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy