"));
}
#[test]
@@ -187,13 +205,63 @@ fn test_add_subcomponent() {
}
#[test]
-fn test_invalid_component_names() {
+fn test_component_with_dashes() {
+ let mut cmd = Command::cargo_bin("cargo-pgml-components").unwrap();
let temp = assert_fs::TempDir::new().unwrap();
- for name in [
- "has-a-dash",
- "5_starts_with_a_number",
- "has%_special_characters",
+
+ cmd.arg("pgml-components")
+ .arg("--project-path")
+ .arg(temp.path().display().to_string())
+ .arg("add")
+ .arg("component")
+ .arg("test-component/subcomponent/alpha-beta-gamma");
+
+ cmd.assert().success();
+
+ for path in [
+ "mod.rs",
+ "template.html",
+ "alpha_beta_gamma.scss",
+ "alpha_beta_gamma_controller.js",
] {
+ temp.child(&format!(
+ "src/components/test_component/subcomponent/alpha_beta_gamma/{}",
+ path
+ ))
+ .assert(predicate::path::exists());
+ }
+
+ let rust = read_to_string(
+ temp.child("src/components/test_component/subcomponent/alpha_beta_gamma/mod.rs")
+ .path(),
+ )
+ .unwrap();
+
+ assert!(rust.contains("pub struct AlphaBetaGamma {"));
+
+ let js = read_to_string(
+ temp.child(
+ "src/components/test_component/subcomponent/alpha_beta_gamma/alpha_beta_gamma_controller.js",
+ )
+ .path(),
+ ).unwrap();
+
+ assert!(js.contains("export default class extends Controller"));
+ assert!(js.contains("console.log('Initialized test-component-subcomponent-alpha-beta-gamma')"));
+
+ let html = read_to_string(
+ temp.child("src/components/test_component/subcomponent/alpha_beta_gamma/template.html")
+ .path(),
+ )
+ .unwrap();
+
+ assert!(html.contains("
"));
+}
+
+#[test]
+fn test_invalid_component_names() {
+ let temp = assert_fs::TempDir::new().unwrap();
+ for name in ["5_starts_with_a_number", "has%_special_characters"] {
let mut cmd = Command::cargo_bin("cargo-pgml-components").unwrap();
cmd.arg("pgml-components")
From 85b8365ec2b28f721bbf03e9bc30e9b6d524ea29 Mon Sep 17 00:00:00 2001
From: Lev Kokotov
Date: Sat, 2 Sep 2023 20:18:48 -0700
Subject: [PATCH 09/11] more test
---
.../cargo-pgml-components/tests/test_add_component.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/pgml-apps/cargo-pgml-components/tests/test_add_component.rs b/pgml-apps/cargo-pgml-components/tests/test_add_component.rs
index e6a01ac09..c263755d1 100644
--- a/pgml-apps/cargo-pgml-components/tests/test_add_component.rs
+++ b/pgml-apps/cargo-pgml-components/tests/test_add_component.rs
@@ -256,6 +256,17 @@ fn test_component_with_dashes() {
.unwrap();
assert!(html.contains(""));
+
+ for path in [
+ "test_component/subcomponent/mod.rs",
+ "test_component/mod.rs",
+ ] {
+ temp.child(&format!("src/components/{}", path))
+ .assert(predicate::path::exists());
+
+ let file = read_to_string(temp.child(&format!("src/components/{}", path)).path()).unwrap();
+ assert!(file.contains("pub mod"));
+ }
}
#[test]
From f0171c3c586f80d9f89cbcd650a96acc17eb8f85 Mon Sep 17 00:00:00 2001
From: Lev Kokotov
Date: Sun, 3 Sep 2023 15:13:00 -0700
Subject: [PATCH 10/11] Generate more sample code
---
.../src/frontend/components.rs | 2 +-
.../src/frontend/javascript.rs | 1 +
.../cargo-pgml-components/src/frontend/sass.rs | 1 +
.../src/frontend/templates/component.rs.tpl | 4 +++-
.../src/frontend/templates/mod.rs | 14 ++++++++++++++
.../src/frontend/templates/sass.scss.tpl | 17 +++++++++++++++++
.../src/frontend/templates/template.html.tpl | 4 +++-
.../cargo-pgml-components/src/frontend/tools.rs | 2 +-
8 files changed, 41 insertions(+), 4 deletions(-)
create mode 100644 pgml-apps/cargo-pgml-components/src/frontend/templates/sass.scss.tpl
diff --git a/pgml-apps/cargo-pgml-components/src/frontend/components.rs b/pgml-apps/cargo-pgml-components/src/frontend/components.rs
index 8659e47ff..390a1c3a0 100644
--- a/pgml-apps/cargo-pgml-components/src/frontend/components.rs
+++ b/pgml-apps/cargo-pgml-components/src/frontend/components.rs
@@ -148,7 +148,7 @@ pub fn add(path: &Path, overwrite: bool) {
let rust = unwrap_or_exit!(templates::Component::new(&component).render_once());
let stimulus = unwrap_or_exit!(templates::Stimulus::new(&component).render_once());
let html = unwrap_or_exit!(templates::Html::new(&component).render_once());
- let scss = String::new();
+ let scss = unwrap_or_exit!(templates::Sass::new(&component).render_once());
let html_path = path.join("template.html");
unwrap_or_exit!(write_to_file(&html_path, &html));
diff --git a/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs b/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs
index 10499f1b3..9f1c80fc5 100644
--- a/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs
+++ b/pgml-apps/cargo-pgml-components/src/frontend/javascript.rs
@@ -126,6 +126,7 @@ pub fn bundle() {
assemble_modules();
// Bundle JavaScript.
+ info("bundling javascript with rollup");
unwrap_or_exit!(execute_with_nvm(
Command::new(JS_COMPILER)
.arg(MODULES_FILE)
diff --git a/pgml-apps/cargo-pgml-components/src/frontend/sass.rs b/pgml-apps/cargo-pgml-components/src/frontend/sass.rs
index c12ba643d..d07517113 100644
--- a/pgml-apps/cargo-pgml-components/src/frontend/sass.rs
+++ b/pgml-apps/cargo-pgml-components/src/frontend/sass.rs
@@ -78,6 +78,7 @@ pub fn bundle() {
cleanup_old_bundles();
// Build Sass.
+ info("bundling css with sass");
unwrap_or_exit!(execute_with_nvm(
Command::new(SASS_COMPILER).arg(SASS_FILE).arg(CSS_FILE),
));
diff --git a/pgml-apps/cargo-pgml-components/src/frontend/templates/component.rs.tpl b/pgml-apps/cargo-pgml-components/src/frontend/templates/component.rs.tpl
index 8d8512167..1c4873856 100644
--- a/pgml-apps/cargo-pgml-components/src/frontend/templates/component.rs.tpl
+++ b/pgml-apps/cargo-pgml-components/src/frontend/templates/component.rs.tpl
@@ -9,7 +9,9 @@ pub struct <%= component.rust_name() %> {
impl <%= component.rust_name() %> {
pub fn new() -> <%= component.rust_name() %> {
- <%= component.rust_name() %>::default()
+ <%= component.rust_name() %> {
+ value: String::from("<%= component.full_path() %>"),
+ }
}
}
diff --git a/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs b/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs
index 8606549c3..a3e4bc276 100644
--- a/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs
+++ b/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs
@@ -50,3 +50,17 @@ pub struct Mod {
pub modules: Vec,
pub root: bool,
}
+
+#[derive(TemplateOnce)]
+#[template(path = "frontend/templates/sass.scss.tpl")]
+pub struct Sass {
+ pub component: ComponentModel,
+}
+
+impl Sass {
+ pub fn new(component: &ComponentModel) -> Self {
+ Self {
+ component: component.clone(),
+ }
+ }
+}
diff --git a/pgml-apps/cargo-pgml-components/src/frontend/templates/sass.scss.tpl b/pgml-apps/cargo-pgml-components/src/frontend/templates/sass.scss.tpl
new file mode 100644
index 000000000..0ca359d44
--- /dev/null
+++ b/pgml-apps/cargo-pgml-components/src/frontend/templates/sass.scss.tpl
@@ -0,0 +1,17 @@
+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/pgml-apps/cargo-pgml-components/src/frontend/templates/template.html.tpl b/pgml-apps/cargo-pgml-components/src/frontend/templates/template.html.tpl
index d9d5d4450..09ac5491b 100644
--- a/pgml-apps/cargo-pgml-components/src/frontend/templates/template.html.tpl
+++ b/pgml-apps/cargo-pgml-components/src/frontend/templates/template.html.tpl
@@ -1,3 +1,5 @@
- <%%= value %>
+
+ <%%= value %>
+
diff --git a/pgml-apps/cargo-pgml-components/src/frontend/tools.rs b/pgml-apps/cargo-pgml-components/src/frontend/tools.rs
index c3f19f79d..5c7809fd9 100644
--- a/pgml-apps/cargo-pgml-components/src/frontend/tools.rs
+++ b/pgml-apps/cargo-pgml-components/src/frontend/tools.rs
@@ -66,7 +66,7 @@ fn install_node() {
debug!("node is not available");
- if let Err(err) = execute_command(Command::new("nvm").arg("--version")) {
+ if let Err(err) = execute_with_nvm(Command::new("nvm").arg("--version")) {
debug!("nvm is not available");
debug1!(err);
// Install Node Version Manager.
From 0f0f3a9198bcd674c01073e6f0d5df8747e66e4f Mon Sep 17 00:00:00 2001
From: Lev Kokotov
Date: Sun, 3 Sep 2023 15:18:39 -0700
Subject: [PATCH 11/11] version bump
---
pgml-apps/cargo-pgml-components/Cargo.lock | 2 +-
pgml-apps/cargo-pgml-components/Cargo.toml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/pgml-apps/cargo-pgml-components/Cargo.lock b/pgml-apps/cargo-pgml-components/Cargo.lock
index d02e584dd..40c0e87cf 100644
--- a/pgml-apps/cargo-pgml-components/Cargo.lock
+++ b/pgml-apps/cargo-pgml-components/Cargo.lock
@@ -126,7 +126,7 @@ dependencies = [
[[package]]
name = "cargo-pgml-components"
-version = "0.1.11"
+version = "0.1.12"
dependencies = [
"anyhow",
"assert_cmd",
diff --git a/pgml-apps/cargo-pgml-components/Cargo.toml b/pgml-apps/cargo-pgml-components/Cargo.toml
index c16ef5f20..74c3aace5 100644
--- a/pgml-apps/cargo-pgml-components/Cargo.toml
+++ b/pgml-apps/cargo-pgml-components/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "cargo-pgml-components"
-version = "0.1.11"
+version = "0.1.12"
edition = "2021"
authors = ["PostgresML "]
license = "MIT"
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/postgresml/postgresml/pull/975.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy