|
|
import marimo |
|
|
|
|
|
__generated_with = "0.19.9" |
|
|
app = marimo.App( |
|
|
width="medium", |
|
|
app_title="Context Template Drafting Marimo Notebook", |
|
|
) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(): |
|
|
import marimo as mo |
|
|
from wigglystuff import SortableList |
|
|
from jsonpath import JSONPath |
|
|
import json |
|
|
|
|
|
return JSONPath, json, mo |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(): |
|
|
from FUNCTIONS.json_template_drafting_functions import ( |
|
|
json_to_marimo_ui, |
|
|
create_download_button, |
|
|
) |
|
|
|
|
|
return create_download_button, json_to_marimo_ui |
|
|
|
|
|
|
|
|
@app.cell(hide_code=True) |
|
|
def _(mo): |
|
|
mo.md(r""" |
|
|
### **Intro** |
|
|
|
|
|
This marimo notebook allows you to upload a **.json** file *(with or without values)* and get a fillable version of the template structure that you can fill out and download as a completed template. ***Upload a file by clicking on the area below or draging and dropping a file onto it.*** |
|
|
""") |
|
|
return |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(mo): |
|
|
file_upload = mo.ui.file( |
|
|
filetypes=[".json"], |
|
|
label="**Upload JSON Template** (*Click and Select or Drag & Drop*)", |
|
|
kind="area", |
|
|
) |
|
|
file_upload |
|
|
return (file_upload,) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(file_upload, json): |
|
|
example_preview = ( |
|
|
json.loads(file_upload.contents()) |
|
|
if file_upload.value is not None and file_upload.contents() is not None |
|
|
else None |
|
|
) |
|
|
return (example_preview,) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(example_preview, file_upload, mo): |
|
|
( |
|
|
mo.accordion({"Preview Example (after loading file)": example_preview}) |
|
|
if file_upload.value is not None and file_upload.contents() is not None |
|
|
else mo.md("*Upload a JSON File to Preview the Template*") |
|
|
) |
|
|
return |
|
|
|
|
|
|
|
|
@app.cell(hide_code=True) |
|
|
def _(mo): |
|
|
mo.md(r""" |
|
|
### **Edit the values** |
|
|
|
|
|
Within the template below you can edit the values of the different inputs and when you define a filename and press **Download** it will save the **.json** file locally on your computer. ***Above you can also see a collapsable preview with filled out values if your template had any*** |
|
|
""") |
|
|
return |
|
|
|
|
|
@app.cell |
|
|
def _(mo): |
|
|
replicate_values = mo.ui.checkbox( |
|
|
label="**Prefill Values From Template** *(if present)*" |
|
|
) |
|
|
replicate_values |
|
|
return (replicate_values,) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(file_upload, json_to_marimo_ui): |
|
|
json_form = json_to_marimo_ui(file_upload, replicate_values=replicate_values.value) |
|
|
json_form |
|
|
return (json_form,) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(JSONPath, json_form): |
|
|
client_name_in_template = ( |
|
|
(JSONPath("$..client_name").parse(json_form.value) or [""])[0] |
|
|
.lower() |
|
|
.replace(" ", "_") |
|
|
if json_form.value is not None |
|
|
else "" |
|
|
) |
|
|
return (client_name_in_template,) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(client_name_in_template, mo): |
|
|
save_file_name = mo.ui.text( |
|
|
label="**Download File Name:**", |
|
|
value=client_name_in_template if client_name_in_template else "", |
|
|
full_width=True, |
|
|
placeholder="add_file_name", |
|
|
) |
|
|
return (save_file_name,) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(create_download_button, json_form, save_file_name): |
|
|
download_output = create_download_button( |
|
|
json_form.value, |
|
|
filename_prefix=( |
|
|
save_file_name.value |
|
|
if save_file_name.value is not None |
|
|
else "downloaded_template_output" |
|
|
), |
|
|
) |
|
|
return (download_output,) |
|
|
|
|
|
|
|
|
@app.cell |
|
|
def _(download_output, mo, save_file_name): |
|
|
download_stack = mo.vstack( |
|
|
[save_file_name, download_output], justify="space-around", gap=1 |
|
|
) |
|
|
download_stack |
|
|
return |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
app.run() |
|
|
|