Skip to content

Commit

Permalink
scaffold improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad committed Jan 23, 2025
1 parent 8954733 commit a017dd8
Show file tree
Hide file tree
Showing 107 changed files with 2,171 additions and 437 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ axum-extra = { version = "0.10", features = ["cookie"] }
regex = { workspace = true }
fs-err = "2.11.0"
# mailer
tera = "1.19.1"
tera = { workspace = true }
thousands = "0.2.0"
heck = { workspace = true }
cruet = "0.13.0"
Expand Down Expand Up @@ -160,6 +160,7 @@ bb8 = { version = "0.8.1", optional = true }
scraper = { version = "0.21.0", features = ["deterministic"], optional = true }

[workspace.dependencies]
tera = { version = "1.19.1" }
colored = { version = "2" }
chrono = { version = "0.4", features = ["serde"] }
tracing = "0.1.40"
Expand Down
4 changes: 3 additions & 1 deletion loco-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ path = "src/lib.rs"
[dependencies]

cruet = "0.14.0"
rrgen = "0.5.5"
# rrgen = "0.5.5"
rrgen = { git = "https://github.com/jondot/rrgen" }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
Expand All @@ -24,6 +25,7 @@ tracing = { workspace = true }
chrono = { workspace = true }
colored = { workspace = true }
heck = { workspace = true }
tera = { workspace = true }

clap = { version = "4.4.7", features = ["derive"] }
duct = "0.13"
Expand Down
6 changes: 6 additions & 0 deletions loco-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod model;
#[cfg(feature = "with-db")]
mod scaffold;
pub mod template;
mod template_engine;
#[cfg(test)]
mod testutil;

Expand Down Expand Up @@ -270,6 +271,11 @@ pub struct AppInfo {
pub app_name: String,
}

#[must_use]
pub fn new_generator() -> RRgen {
RRgen::default().add_template_engine(template_engine::new())
}

/// Generate a component
///
/// # Errors
Expand Down
36 changes: 15 additions & 21 deletions loco-gen/src/mappings.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"field_types": [
{
"name": "uuid",
"name": "uuid^",
"rust": "Uuid",
"schema": "uuid_uniq",
"col_type": "UuidUniq"
},
{
"name": "uuid_col",
"name": "uuid",
"rust": "Option<Uuid>",
"schema": "uuid_null",
"col_type": "UuidNull"
},
{
"name": "uuid_col!",
"name": "uuid!",
"rust": "Uuid",
"schema": "uuid",
"col_type": "Uuid"
Expand Down Expand Up @@ -286,13 +286,13 @@
},
{
"name": "ts",
"rust": "Option<DateTime>",
"rust": "Option<DateTimeUtc>",
"schema": "timestamp_null",
"col_type": "TimestampNull"
},
{
"name": "ts!",
"rust": "DateTime",
"rust": "DateTimeUtc",
"schema": "timestamp",
"col_type": "Timestamp"
},
Expand Down Expand Up @@ -434,13 +434,11 @@
{
"name": "array!",
"rust": {
"string": "Vec<String>",
"float": "Vec<f32>",
"int": "Vec<i32>",
"small_int": "Vec<i16>",
"big_int": "Vec<i64>",
"double": "Vec<f64>",
"bool": "Vec<bool>"
"string": "Option<Vec<String>>",
"float": "Option<Vec<f32>>",
"int": "Option<Vec<i32>>",
"double": "Option<Vec<f64>>",
"bool": "Option<Vec<bool>>"
},
"schema": "array",
"col_type": "array",
Expand All @@ -452,8 +450,6 @@
"string": "Option<Vec<String>>",
"float": "Option<Vec<f32>>",
"int": "Option<Vec<i32>>",
"small_int": "Option<Vec<i16>>",
"big_int": "Option<Vec<i64>>",
"double": "Option<Vec<f64>>",
"bool": "Option<Vec<bool>>"
},
Expand All @@ -464,13 +460,11 @@
{
"name": "array^",
"rust": {
"string": "Vec<String>",
"float": "Vec<f32>",
"int": "Vec<i32>",
"small_int": "Vec<i16>",
"big_int": "Vec<i64>",
"double": "Vec<f64>",
"bool": "Vec<bool>"
"string": "Option<Vec<String>>",
"float": "Option<Vec<f32>>",
"int": "Option<Vec<i32>>",
"double": "Option<Vec<f64>>",
"bool": "Option<Vec<bool>>"
},
"schema": "array",
"col_type": "array_uniq",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: loco-gen/src/template_engine.rs
expression: "format!(\"Crete form\\n\\r{create_form}\\n\\rEdit Form\\n\\r{edit_form}\")"
---
Crete form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>

</div>
Edit Form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>

</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: loco-gen/src/template_engine.rs
expression: "format!(\"Crete form\\n\\r{create_form}\\n\\rEdit Form\\n\\r{edit_form}\")"
---
Crete form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" max="179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" id="array!" name="array!" type="number" value="{{val}}" required custom_type="array" />
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" max="179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" id="array!" name="array!" type="number" value="" required custom_type="array" />
{%- endif -%}
</div>
</div>
Edit Form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" max="179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" id="array!" name="array!" type="number" value="{{val}}" required custom_type="array" />
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" max="179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" id="array!" name="array!" type="number" value="{{item.array!}}" required custom_type="array" />
{%- endif -%}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: loco-gen/src/template_engine.rs
expression: "format!(\"Crete form\\n\\r{create_form}\\n\\rEdit Form\\n\\r{edit_form}\")"
---
Crete form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-340282350000000000000000000000000000000" max="340282350000000000000000000000000000000" id="array!" name="array!" type="number" value="{{val}}" required custom_type="array" step="0.1" />
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-340282350000000000000000000000000000000" max="340282350000000000000000000000000000000" id="array!" name="array!" type="number" value="" required custom_type="array" step="0.1" />
{%- endif -%}
</div>
</div>
Edit Form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-340282350000000000000000000000000000000" max="340282350000000000000000000000000000000" id="array!" name="array!" type="number" value="{{val}}" required custom_type="array" step="0.1" />
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-340282350000000000000000000000000000000" max="340282350000000000000000000000000000000" id="array!" name="array!" type="number" value="{{item.array!}}" required custom_type="array" step="0.1" />
{%- endif -%}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: loco-gen/src/template_engine.rs
expression: "format!(\"Crete form\\n\\r{create_form}\\n\\rEdit Form\\n\\r{edit_form}\")"
---
Crete form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-2147483648" max="2147483647" id="array!" name="array!" type="number" value="{{val}}" required custom_type="array" />
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-2147483648" max="2147483647" id="array!" name="array!" type="number" value="" required custom_type="array" />
{%- endif -%}
</div>
</div>
Edit Form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-2147483648" max="2147483647" id="array!" name="array!" type="number" value="{{val}}" required custom_type="array" />
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" min="-2147483648" max="2147483647" id="array!" name="array!" type="number" value="{{item.array!}}" required custom_type="array" />
{%- endif -%}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: loco-gen/src/template_engine.rs
expression: "format!(\"Crete form\\n\\r{create_form}\\n\\rEdit Form\\n\\r{edit_form}\")"
---
Crete form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" name="array!" type="text" value="{{val}}" required custom_type="array"/>
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" name="array!" type="text" value="" required custom_type="array"/>
{%- endif -%}
</div>
</div>
Edit Form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array!</label>
<button type="button" class="text-xs py-1 px-3 rounded-lg bg-gray-900 text-white add-more" data-group="array!">Add More</button>
<div id="array!-inputs" class="space-y-2">
{% if item.array! %}
{% for val in item.array! %}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" name="array!" type="text" value="{{val}}" required custom_type="array"/>
{% endfor -%}
{%- else -%}
<input class="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm md:text-sm" name="array!" type="text" value="{{item.array!}}" required custom_type="array"/>
{%- endif -%}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: loco-gen/src/template_engine.rs
expression: "format!(\"Crete form\\n\\r{create_form}\\n\\rEdit Form\\n\\r{edit_form}\")"
---
Crete form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array^</label>

</div>
Edit Form
<div class="space-y-2">
<label class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" for=":r2l:-form-item">array^</label>

</div>
Expand Down
Loading

0 comments on commit a017dd8

Please sign in to comment.