From a971c853a051a37c3d9a66ad171422cf86fe4add Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Wed, 6 Sep 2023 13:03:15 -0700 Subject: [PATCH 1/3] pgml-components library --- packages/pgml-components/Cargo.lock | 315 ++++++++++++++++++ packages/pgml-components/Cargo.toml | 7 + packages/pgml-components/src/lib.rs | 14 + .../templates/components/component.html | 1 + 4 files changed, 337 insertions(+) create mode 100644 packages/pgml-components/Cargo.lock create mode 100644 packages/pgml-components/Cargo.toml create mode 100644 packages/pgml-components/src/lib.rs create mode 100644 packages/pgml-components/templates/components/component.html diff --git a/packages/pgml-components/Cargo.lock b/packages/pgml-components/Cargo.lock new file mode 100644 index 000000000..c890e4e64 --- /dev/null +++ b/packages/pgml-components/Cargo.lock @@ -0,0 +1,315 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "filetime" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys", +] + +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9028f49264629065d057f340a86acb84867925865f73bbf8d47b4d149a7e88b8" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "memchr" +version = "2.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" + +[[package]] +name = "pgml-components" +version = "0.1.0" +dependencies = [ + "sailfish", +] + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + +[[package]] +name = "sailfish" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7519b7521780097b0183bb4b0c7c2165b924f5f1d44c3ef765bde8c2f8008fd1" +dependencies = [ + "itoap", + "ryu", + "sailfish-macros", + "version_check", +] + +[[package]] +name = "sailfish-compiler" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "535500faca492ee8054fbffdfca6447ca97fa495e0ede9f28fa473e1a44f9d5c" +dependencies = [ + "filetime", + "home", + "memchr", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", +] + +[[package]] +name = "sailfish-macros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06a95a6b8a0f59bf66f430a4ed37ece23fcefcd26898399573043e56fb202be2" +dependencies = [ + "proc-macro2", + "sailfish-compiler", +] + +[[package]] +name = "serde" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde", +] + +[[package]] +name = "syn" +version = "2.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c2e3184b9c4e92ad5167ca73039d0c42476302ab603e2fec4487511f38ccefc" +dependencies = [ + "memchr", +] diff --git a/packages/pgml-components/Cargo.toml b/packages/pgml-components/Cargo.toml new file mode 100644 index 000000000..a6f869ccd --- /dev/null +++ b/packages/pgml-components/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "pgml-components" +version = "0.1.0" +edition = "2021" + +[dependencies] +sailfish = ">=0.8" diff --git a/packages/pgml-components/src/lib.rs b/packages/pgml-components/src/lib.rs new file mode 100644 index 000000000..7d12d9af8 --- /dev/null +++ b/packages/pgml-components/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/packages/pgml-components/templates/components/component.html b/packages/pgml-components/templates/components/component.html new file mode 100644 index 000000000..d4c8df92e --- /dev/null +++ b/packages/pgml-components/templates/components/component.html @@ -0,0 +1 @@ +<%- value %> From a59fd57c2bd7a959138a2595526197ee1c39e715 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Wed, 6 Sep 2023 13:18:10 -0700 Subject: [PATCH 2/3] Use shared pgml_components library --- packages/pgml-components/src/lib.rs | 60 ++++++++++++++++--- pgml-apps/cargo-pgml-components/Cargo.toml | 2 +- .../src/components/component.html | 1 - .../src/components/component.rs | 56 ----------------- .../src/components/mod.rs | 32 ---------- .../src/frontend/components.rs | 8 +-- .../src/frontend/templates/component.rs.tpl | 2 +- .../src/frontend/templates/mod.rs | 1 - .../src/frontend/templates/mod.rs.tpl | 4 -- pgml-apps/cargo-pgml-components/src/main.rs | 2 - pgml-dashboard/Cargo.lock | 8 +++ pgml-dashboard/Cargo.toml | 1 + .../src/components/breadcrumbs/mod.rs | 2 +- pgml-dashboard/src/components/component.rs | 56 ----------------- .../src/components/confirm_modal/mod.rs | 2 +- pgml-dashboard/src/components/dropdown/mod.rs | 4 +- .../src/components/github_icon/mod.rs | 2 +- .../src/components/left_nav_menu/mod.rs | 2 +- .../src/components/left_nav_web_app/mod.rs | 2 +- pgml-dashboard/src/components/mod.rs | 3 - pgml-dashboard/src/components/modal/mod.rs | 2 +- pgml-dashboard/src/components/nav/mod.rs | 2 +- pgml-dashboard/src/components/navbar/mod.rs | 2 +- .../src/components/navbar_web_app/mod.rs | 2 +- .../src/components/navigation/tabs/tab/mod.rs | 4 +- .../components/navigation/tabs/tabs/mod.rs | 2 +- .../src/components/postgres_logo/mod.rs | 2 +- .../src/components/profile_icon/mod.rs | 2 +- .../src/components/tables/large/row/mod.rs | 4 +- .../src/components/tables/large/table/mod.rs | 2 +- .../src/components/test_component/mod.rs | 2 +- 31 files changed, 86 insertions(+), 190 deletions(-) delete mode 100644 pgml-apps/cargo-pgml-components/src/components/component.html delete mode 100644 pgml-apps/cargo-pgml-components/src/components/component.rs delete mode 100644 pgml-apps/cargo-pgml-components/src/components/mod.rs delete mode 100644 pgml-dashboard/src/components/component.rs diff --git a/packages/pgml-components/src/lib.rs b/packages/pgml-components/src/lib.rs index 7d12d9af8..2f413df88 100644 --- a/packages/pgml-components/src/lib.rs +++ b/packages/pgml-components/src/lib.rs @@ -1,14 +1,56 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +#![allow(dead_code, unused_macros, unused_imports)] +//! A basic UI component. Any other component can accept this +//! as a parameter and render it. + +use sailfish::TemplateOnce; + +#[derive(Default, Clone, TemplateOnce)] +#[template(path = "components/component.html")] +pub struct Component { + pub value: String, +} + +#[macro_export] +macro_rules! component { + ($name:tt) => { + impl From<$name> for pgml_components::Component { + fn from(thing: $name) -> pgml_components::Component { + use sailfish::TemplateOnce; + + pgml_components::Component { + value: thing.render_once().unwrap(), + } + } + } + }; + + ($name:tt, $lifetime:lifetime) => { + impl<$lifetime> From<$name<$lifetime>> for pgml_components::Component { + fn from(thing: $name<$lifetime>) -> pgml_components::Component { + use sailfish::TemplateOnce; + + pgml_components::Component { + value: thing.render_once().unwrap(), + } + } + } + }; } -#[cfg(test)] -mod tests { - use super::*; +// pub use component; + +// Render any string. +impl From<&str> for Component { + fn from(value: &str) -> Component { + Component { + value: value.to_owned(), + } + } +} - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); +// Render any string. +impl From for Component { + fn from(value: String) -> Component { + Component { value } } } diff --git a/pgml-apps/cargo-pgml-components/Cargo.toml b/pgml-apps/cargo-pgml-components/Cargo.toml index e816eada5..a12c8bd27 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.14" +version = "0.1.15" edition = "2021" authors = ["PostgresML "] license = "MIT" diff --git a/pgml-apps/cargo-pgml-components/src/components/component.html b/pgml-apps/cargo-pgml-components/src/components/component.html deleted file mode 100644 index d4c8df92e..000000000 --- a/pgml-apps/cargo-pgml-components/src/components/component.html +++ /dev/null @@ -1 +0,0 @@ -<%- value %> diff --git a/pgml-apps/cargo-pgml-components/src/components/component.rs b/pgml-apps/cargo-pgml-components/src/components/component.rs deleted file mode 100644 index e0504177c..000000000 --- a/pgml-apps/cargo-pgml-components/src/components/component.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![allow(dead_code, unused_macros, unused_imports)] -//! A basic UI component. Any other component can accept this -//! as a parameter and render it. - -use sailfish::TemplateOnce; - -#[derive(Default, Clone, TemplateOnce)] -#[template(path = "components/component.html")] -pub struct Component { - pub value: String, -} - -#[macro_export] -macro_rules! component { - ($name:tt) => { - impl From<$name> for crate::components::Component { - fn from(thing: $name) -> crate::components::Component { - use sailfish::TemplateOnce; - - crate::components::Component { - value: thing.render_once().unwrap(), - } - } - } - }; - - ($name:tt, $lifetime:lifetime) => { - impl<$lifetime> From<$name<$lifetime>> for crate::components::Component { - fn from(thing: $name<$lifetime>) -> crate::components::Component { - use sailfish::TemplateOnce; - - crate::components::Component { - value: thing.render_once().unwrap(), - } - } - } - }; -} - -pub use component; - -// Render any string. -impl From<&str> for Component { - fn from(value: &str) -> Component { - Component { - value: value.to_owned(), - } - } -} - -// Render any string. -impl From for Component { - fn from(value: String) -> Component { - Component { value } - } -} diff --git a/pgml-apps/cargo-pgml-components/src/components/mod.rs b/pgml-apps/cargo-pgml-components/src/components/mod.rs deleted file mode 100644 index 8c244c73c..000000000 --- a/pgml-apps/cargo-pgml-components/src/components/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -use crate::util::{compare_strings, info, unwrap_or_exit, write_to_file}; -use std::fs::read_to_string; -use std::path::Path; - -static COMPONENT_PATH: &str = "src/components/component.rs"; -static COMPONENT_TEMPLATE: &str = "templates/components/component.html"; - -pub mod component; - -pub fn install() { - let source = include_str!("component.rs"); - let template = include_str!("component.html"); - - compare_and_install(Path::new(COMPONENT_PATH), source); - compare_and_install(Path::new(COMPONENT_TEMPLATE), template); -} - -fn compare_and_install(path: &Path, source: &str) { - if !path.exists() { - debug!("{} doesn't exist", path.display()); - info(&format!("written {}", path.display())); - unwrap_or_exit!(write_to_file(&path, &source)); - } else { - let template_source = unwrap_or_exit!(read_to_string(path)); - - if !compare_strings(&template_source, source) { - debug!("{} is different", path.display()); - unwrap_or_exit!(write_to_file(&path, &source)); - info(&format!("written {}", path.display())); - } - } -} diff --git a/pgml-apps/cargo-pgml-components/src/frontend/components.rs b/pgml-apps/cargo-pgml-components/src/frontend/components.rs index 390a1c3a0..5a8a479df 100644 --- a/pgml-apps/cargo-pgml-components/src/frontend/components.rs +++ b/pgml-apps/cargo-pgml-components/src/frontend/components.rs @@ -171,12 +171,12 @@ pub fn add(path: &Path, overwrite: bool) { /// Update `mod.rs` with all the components in `src/components`. pub fn update_modules() { - update_module(Path::new(COMPONENT_DIRECTORY), true); + update_module(Path::new(COMPONENT_DIRECTORY)); } /// Recusively write `mod.rs` in every Rust module directory /// that has other modules in it. -fn update_module(path: &Path, root: bool) { +fn update_module(path: &Path) { debug!("updating {} module", path.display()); let mut modules = Vec::new(); let mut paths: Vec<_> = unwrap_or_exit!(read_dir(path)) @@ -192,7 +192,7 @@ fn update_module(path: &Path, root: bool) { if has_more_modules(&path) { debug!("{} has more modules", path.display()); - update_module(&path, false); + update_module(&path); } else { debug!("it does not really no"); } @@ -206,7 +206,7 @@ fn update_module(path: &Path, root: bool) { let components_mod = path.join("mod.rs"); let modules = - unwrap_or_exit!(templates::Mod { modules, root }.render_once()).replace("\n\n", "\n"); + unwrap_or_exit!(templates::Mod { modules }.render_once()).replace("\n\n", "\n"); let existing_modules = if components_mod.is_file() { unwrap_or_exit!(read_to_string(&components_mod)) 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 1c4873856..8374c932a 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 @@ -1,5 +1,5 @@ use sailfish::TemplateOnce; -use crate::components::component; +use pgml_components::component; #[derive(TemplateOnce, Default)] #[template(path = "<%= component.path() %>/template.html")] 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 a3e4bc276..5acda169d 100644 --- a/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs +++ b/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs @@ -48,7 +48,6 @@ impl Stimulus { #[template(path = "frontend/templates/mod.rs.tpl")] pub struct Mod { pub modules: Vec, - pub root: bool, } #[derive(TemplateOnce)] diff --git a/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs.tpl b/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs.tpl index fe37ba782..c31eb533d 100644 --- a/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs.tpl +++ b/pgml-apps/cargo-pgml-components/src/frontend/templates/mod.rs.tpl @@ -1,10 +1,6 @@ // This file is automatically generated. // You shouldn't modify it manually. -<% if root { %> -pub mod component; -pub use component::{component, Component}; -<% } %> <% for component in modules.iter() { %> // <%= component.full_path() %> pub mod <%= component.name() %>; diff --git a/pgml-apps/cargo-pgml-components/src/main.rs b/pgml-apps/cargo-pgml-components/src/main.rs index fce62915f..a03d7069f 100644 --- a/pgml-apps/cargo-pgml-components/src/main.rs +++ b/pgml-apps/cargo-pgml-components/src/main.rs @@ -9,7 +9,6 @@ use std::path::Path; extern crate log; mod backend; -mod components; mod frontend; mod util; use util::{info, unwrap_or_exit}; @@ -106,7 +105,6 @@ fn validate_project(project_path: Option) { } unwrap_or_exit!(set_current_dir(path)); - components::install(); } /// Bundle SASS and JavaScript into neat bundle files. diff --git a/pgml-dashboard/Cargo.lock b/pgml-dashboard/Cargo.lock index f48f3617c..fce162ea5 100644 --- a/pgml-dashboard/Cargo.lock +++ b/pgml-dashboard/Cargo.lock @@ -2169,6 +2169,13 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +[[package]] +name = "pgml-components" +version = "0.1.0" +dependencies = [ + "sailfish", +] + [[package]] name = "pgml-dashboard" version = "2.7.6" @@ -2189,6 +2196,7 @@ dependencies = [ "num-traits", "once_cell", "parking_lot 0.12.1", + "pgml-components", "pgvector", "rand", "regex", diff --git a/pgml-dashboard/Cargo.toml b/pgml-dashboard/Cargo.toml index 64dc8e909..3313a16ff 100644 --- a/pgml-dashboard/Cargo.toml +++ b/pgml-dashboard/Cargo.toml @@ -44,3 +44,4 @@ zoomies = { git="https://github.com/HyperparamAI/zoomies.git", branch="master" } pgvector = { version = "0.2.2", features = [ "sqlx", "postgres" ] } console-subscriber = "*" glob = "*" +pgml-components = { path = "../packages/pgml-components" } diff --git a/pgml-dashboard/src/components/breadcrumbs/mod.rs b/pgml-dashboard/src/components/breadcrumbs/mod.rs index 9f711dd64..8f026b046 100644 --- a/pgml-dashboard/src/components/breadcrumbs/mod.rs +++ b/pgml-dashboard/src/components/breadcrumbs/mod.rs @@ -1,5 +1,5 @@ -use crate::components::component; use crate::components::NavLink; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce)] diff --git a/pgml-dashboard/src/components/component.rs b/pgml-dashboard/src/components/component.rs deleted file mode 100644 index e0504177c..000000000 --- a/pgml-dashboard/src/components/component.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![allow(dead_code, unused_macros, unused_imports)] -//! A basic UI component. Any other component can accept this -//! as a parameter and render it. - -use sailfish::TemplateOnce; - -#[derive(Default, Clone, TemplateOnce)] -#[template(path = "components/component.html")] -pub struct Component { - pub value: String, -} - -#[macro_export] -macro_rules! component { - ($name:tt) => { - impl From<$name> for crate::components::Component { - fn from(thing: $name) -> crate::components::Component { - use sailfish::TemplateOnce; - - crate::components::Component { - value: thing.render_once().unwrap(), - } - } - } - }; - - ($name:tt, $lifetime:lifetime) => { - impl<$lifetime> From<$name<$lifetime>> for crate::components::Component { - fn from(thing: $name<$lifetime>) -> crate::components::Component { - use sailfish::TemplateOnce; - - crate::components::Component { - value: thing.render_once().unwrap(), - } - } - } - }; -} - -pub use component; - -// Render any string. -impl From<&str> for Component { - fn from(value: &str) -> Component { - Component { - value: value.to_owned(), - } - } -} - -// Render any string. -impl From for Component { - fn from(value: String) -> Component { - Component { value } - } -} diff --git a/pgml-dashboard/src/components/confirm_modal/mod.rs b/pgml-dashboard/src/components/confirm_modal/mod.rs index e2d9b4ec5..1d3f81e59 100644 --- a/pgml-dashboard/src/components/confirm_modal/mod.rs +++ b/pgml-dashboard/src/components/confirm_modal/mod.rs @@ -1,4 +1,4 @@ -use crate::components::component; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce)] diff --git a/pgml-dashboard/src/components/dropdown/mod.rs b/pgml-dashboard/src/components/dropdown/mod.rs index 87835ca3c..a53394e1b 100644 --- a/pgml-dashboard/src/components/dropdown/mod.rs +++ b/pgml-dashboard/src/components/dropdown/mod.rs @@ -1,5 +1,5 @@ -use crate::components::component; -use crate::components::component::Component; +use pgml_components::component; +use pgml_components::Component; use sailfish::TemplateOnce; use crate::components::StaticNavLink; diff --git a/pgml-dashboard/src/components/github_icon/mod.rs b/pgml-dashboard/src/components/github_icon/mod.rs index d3dfe5b17..fb3f6a422 100644 --- a/pgml-dashboard/src/components/github_icon/mod.rs +++ b/pgml-dashboard/src/components/github_icon/mod.rs @@ -1,4 +1,4 @@ -use crate::components::component; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default)] diff --git a/pgml-dashboard/src/components/left_nav_menu/mod.rs b/pgml-dashboard/src/components/left_nav_menu/mod.rs index ef1d86c5a..2b3bf4fbe 100644 --- a/pgml-dashboard/src/components/left_nav_menu/mod.rs +++ b/pgml-dashboard/src/components/left_nav_menu/mod.rs @@ -1,5 +1,5 @@ -use crate::components::component; use crate::components::StaticNav; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce)] diff --git a/pgml-dashboard/src/components/left_nav_web_app/mod.rs b/pgml-dashboard/src/components/left_nav_web_app/mod.rs index 663761696..612bd5d13 100644 --- a/pgml-dashboard/src/components/left_nav_web_app/mod.rs +++ b/pgml-dashboard/src/components/left_nav_web_app/mod.rs @@ -1,4 +1,4 @@ -use crate::components::component; +use pgml_components::component; use sailfish::TemplateOnce; use crate::components::StaticNav; diff --git a/pgml-dashboard/src/components/mod.rs b/pgml-dashboard/src/components/mod.rs index 9008682f1..4a545b493 100644 --- a/pgml-dashboard/src/components/mod.rs +++ b/pgml-dashboard/src/components/mod.rs @@ -1,9 +1,6 @@ // This file is automatically generated. // You shouldn't modify it manually. -pub mod component; -pub use component::{component, Component}; - // src/components/breadcrumbs pub mod breadcrumbs; pub use breadcrumbs::Breadcrumbs; diff --git a/pgml-dashboard/src/components/modal/mod.rs b/pgml-dashboard/src/components/modal/mod.rs index 67167cd3e..3d62535bb 100644 --- a/pgml-dashboard/src/components/modal/mod.rs +++ b/pgml-dashboard/src/components/modal/mod.rs @@ -1,4 +1,4 @@ -use crate::components::{component, Component}; +use pgml_components::{component, Component}; use sailfish::TemplateOnce; /// A component that renders a Bootstrap modal. diff --git a/pgml-dashboard/src/components/nav/mod.rs b/pgml-dashboard/src/components/nav/mod.rs index a95374dfa..cbe505552 100644 --- a/pgml-dashboard/src/components/nav/mod.rs +++ b/pgml-dashboard/src/components/nav/mod.rs @@ -1,5 +1,5 @@ -use crate::components::component; use crate::components::nav_link::NavLink; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Clone, Default, Debug)] diff --git a/pgml-dashboard/src/components/navbar/mod.rs b/pgml-dashboard/src/components/navbar/mod.rs index 4dc023e34..63b9cb351 100644 --- a/pgml-dashboard/src/components/navbar/mod.rs +++ b/pgml-dashboard/src/components/navbar/mod.rs @@ -1,6 +1,6 @@ -use crate::components::component; use crate::models; use crate::utils::config; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce)] diff --git a/pgml-dashboard/src/components/navbar_web_app/mod.rs b/pgml-dashboard/src/components/navbar_web_app/mod.rs index e814fc15d..d28be5b98 100644 --- a/pgml-dashboard/src/components/navbar_web_app/mod.rs +++ b/pgml-dashboard/src/components/navbar_web_app/mod.rs @@ -1,6 +1,6 @@ -use crate::components::component; use crate::components::{StaticNav, StaticNavLink}; use crate::utils::config; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce)] diff --git a/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs b/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs index b1e33cc00..e8c5addb2 100644 --- a/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs +++ b/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs @@ -1,6 +1,6 @@ #![allow(unused_variables)] -use crate::components::component; -use crate::components::component::Component; +use pgml_components::component; +use pgml_components::Component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default, Clone)] diff --git a/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs b/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs index e7042f3e2..6084c812d 100644 --- a/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs +++ b/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs @@ -1,5 +1,5 @@ -use crate::components::component; use crate::components::navigation::tabs::Tab; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default)] diff --git a/pgml-dashboard/src/components/postgres_logo/mod.rs b/pgml-dashboard/src/components/postgres_logo/mod.rs index ee525c8a2..8f5c63aa9 100644 --- a/pgml-dashboard/src/components/postgres_logo/mod.rs +++ b/pgml-dashboard/src/components/postgres_logo/mod.rs @@ -1,4 +1,4 @@ -use crate::components::component; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default)] diff --git a/pgml-dashboard/src/components/profile_icon/mod.rs b/pgml-dashboard/src/components/profile_icon/mod.rs index 309694bec..fedfdec19 100644 --- a/pgml-dashboard/src/components/profile_icon/mod.rs +++ b/pgml-dashboard/src/components/profile_icon/mod.rs @@ -1,4 +1,4 @@ -use crate::components::component; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default)] diff --git a/pgml-dashboard/src/components/tables/large/row/mod.rs b/pgml-dashboard/src/components/tables/large/row/mod.rs index 5c3c2b3e3..1dea96e8b 100644 --- a/pgml-dashboard/src/components/tables/large/row/mod.rs +++ b/pgml-dashboard/src/components/tables/large/row/mod.rs @@ -1,5 +1,5 @@ -use crate::components::component; -use crate::components::component::Component; +use pgml_components::component; +use pgml_components::Component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default, Clone)] diff --git a/pgml-dashboard/src/components/tables/large/table/mod.rs b/pgml-dashboard/src/components/tables/large/table/mod.rs index 3054b0750..6059cc893 100644 --- a/pgml-dashboard/src/components/tables/large/table/mod.rs +++ b/pgml-dashboard/src/components/tables/large/table/mod.rs @@ -1,5 +1,5 @@ -use crate::components::component; use crate::components::tables::large::Row; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default)] diff --git a/pgml-dashboard/src/components/test_component/mod.rs b/pgml-dashboard/src/components/test_component/mod.rs index 3b29ed573..cabb85294 100644 --- a/pgml-dashboard/src/components/test_component/mod.rs +++ b/pgml-dashboard/src/components/test_component/mod.rs @@ -1,4 +1,4 @@ -use crate::components::component; +use pgml_components::component; use sailfish::TemplateOnce; #[derive(TemplateOnce, Default)] From ffc653b67b2b88358660eb18d22dfbbbf928fd5e Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Wed, 6 Sep 2023 13:56:58 -0700 Subject: [PATCH 3/3] bug --- .../src/frontend/templates/template.html.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 09ac5491b..0cb25aab1 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,5 +1,5 @@

<%%= value %> -

+ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy