Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pgml-components] Add template-only option & remove boilerplate#1403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
levkk merged 1 commit intomasterfromlevkk-pgml-components-boilerplate
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
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
2 changes: 1 addition & 1 deletionpackages/cargo-pgml-components/Cargo.lock
View file
Open in desktop

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

2 changes: 1 addition & 1 deletionpackages/cargo-pgml-components/Cargo.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-pgml-components"
version = "0.1.24"
version = "0.1.25"
edition = "2021"
authors = ["PostgresML <team@postgresml.org>"]
license = "MIT"
Expand Down
18 changes: 11 additions & 7 deletionspackages/cargo-pgml-components/src/frontend/components.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,7 +86,7 @@ impl From<&Path> for Component {
}

/// 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);
Expand DownExpand Up@@ -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();
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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() %> {}
}
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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;
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -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() {}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
<div data-controller="<%= component.controller_name() %>">
<h3 class="text-center h3">
<%%= value %>
</h3>

</div>
20 changes: 16 additions & 4 deletionspackages/cargo-pgml-components/src/main.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,7 +89,14 @@ enum Commands {
#[derive(Subcommand, Debug)]
enum AddCommands {
/// Add a new component.
Component { name: String },
Component {
/// Name of the new component.
name: String,

/// Generate only the HTML template. Don't generate SCSS and JavaScript.
#[arg(short, long, default_value = "false")]
template_only: bool,
},
}

#[derive(Subcommand, Debug)]
Expand All@@ -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(),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp