🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use shared pgml_components library
  • Loading branch information
levkk committed Sep 6, 2023
commit a59fd57c2bd7a959138a2595526197ee1c39e715
60 changes: 51 additions & 9 deletions packages/pgml-components/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<String> for Component {
fn from(value: String) -> Component {
Component { value }
}
}
2 changes: 1 addition & 1 deletion pgml-apps/cargo-pgml-components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-pgml-components"
version = "0.1.14"
version = "0.1.15"
edition = "2021"
authors = ["PostgresML <team@postgresml.org>"]
license = "MIT"
Expand Down

This file was deleted.

56 changes: 0 additions & 56 deletions pgml-apps/cargo-pgml-components/src/components/component.rs

This file was deleted.

32 changes: 0 additions & 32 deletions pgml-apps/cargo-pgml-components/src/components/mod.rs

This file was deleted.

8 changes: 4 additions & 4 deletions pgml-apps/cargo-pgml-components/src/frontend/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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");
}
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use sailfish::TemplateOnce;
use crate::components::component;
use pgml_components::component;

#[derive(TemplateOnce, Default)]
#[template(path = "<%= component.path() %>/template.html")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl Stimulus {
#[template(path = "frontend/templates/mod.rs.tpl")]
pub struct Mod {
pub modules: Vec<ComponentModel>,
pub root: bool,
}

#[derive(TemplateOnce)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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() %>;
Expand Down
2 changes: 0 additions & 2 deletions pgml-apps/cargo-pgml-components/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -106,7 +105,6 @@ fn validate_project(project_path: Option<String>) {
}

unwrap_or_exit!(set_current_dir(path));
components::install();
}

/// Bundle SASS and JavaScript into neat bundle files.
Expand Down
8 changes: 8 additions & 0 deletions pgml-dashboard/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pgml-dashboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/breadcrumbs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::component;
use crate::components::NavLink;
use pgml_components::component;
use sailfish::TemplateOnce;

#[derive(TemplateOnce)]
Expand Down
56 changes: 0 additions & 56 deletions pgml-dashboard/src/components/component.rs

This file was deleted.

2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/confirm_modal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::components::component;
use pgml_components::component;
use sailfish::TemplateOnce;

#[derive(TemplateOnce)]
Expand Down
4 changes: 2 additions & 2 deletions pgml-dashboard/src/components/dropdown/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/github_icon/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::components::component;
use pgml_components::component;
use sailfish::TemplateOnce;

#[derive(TemplateOnce, Default)]
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/left_nav_menu/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::components::component;
use crate::components::StaticNav;
use pgml_components::component;
use sailfish::TemplateOnce;

#[derive(TemplateOnce)]
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/left_nav_web_app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::components::component;
use pgml_components::component;
use sailfish::TemplateOnce;

use crate::components::StaticNav;
Expand Down
3 changes: 0 additions & 3 deletions pgml-dashboard/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/modal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::components::{component, Component};
use pgml_components::{component, Component};
use sailfish::TemplateOnce;

/// A component that renders a Bootstrap modal.
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/nav/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion pgml-dashboard/src/components/navbar/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::components::component;
use crate::models;
use crate::utils::config;
use pgml_components::component;
use sailfish::TemplateOnce;

#[derive(TemplateOnce)]
Expand Down
Loading