mirror of
https://github.com/Bornholm/formidable.git
synced 2025-07-23 14:01:33 +02:00
chore: tailwindcss theme + goreleaser basic recipe
This commit is contained in:
@ -3,17 +3,33 @@
|
||||
<table width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="left" nowrap=""></td>
|
||||
<td align="left" nowrap="">
|
||||
<strong>{{ .Schema.Title }}</strong>
|
||||
<em>{{ .Schema.Description }}</em>
|
||||
</td>
|
||||
<td align="right" nowrap="">
|
||||
<input type="submit" name="submit" value="Enregistrer" />
|
||||
<input
|
||||
class="bg-green-600 text-white my-4 px-4 py-2 rounded-md text-xl font-medium hover:bg-green-700 transition duration-300"
|
||||
type="submit"
|
||||
name="submit" value="Enregistrer" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
<strong>{{ .Schema.Title }}</strong>
|
||||
<em>{{ .Schema.Description }}</em>
|
||||
<hr />
|
||||
{{ if .Error }}
|
||||
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative">
|
||||
<strong class="font-bold">There is some(s) error(s) !</strong>
|
||||
<br />
|
||||
<span class="block">{{ .Error.Message }}</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ if .SuccessMessage }}
|
||||
<div class="bg-green-100 border border-green-600 text-green-600 px-4 py-3 rounded relative">
|
||||
<strong class="font-bold">Success !</strong>
|
||||
<br />
|
||||
<span class="block">{{ .SuccessMessage }}</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{template "form_item" .}}
|
||||
</form>
|
||||
{{end}}
|
@ -9,13 +9,16 @@
|
||||
{{ $itemProperty := printf "%d" $index }}
|
||||
{{ $itemSchema := getItemSchema $root.Schema }}
|
||||
{{ $formItemData := formItemData $root $itemProperty $itemSchema }}
|
||||
|
||||
<tr>
|
||||
{{ template "form_row" $formItemData }}
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<input type="submit" name="del:{{ $fullProperty }}/{{$index}}" value="Supprimer" />
|
||||
<td></td>
|
||||
<td colspan="2">
|
||||
<input type="submit"
|
||||
class="bg-red-600 text-white mb-2 px-3 py-1 rounded-md text-sm font-medium hover:bg-red-700 transition duration-300"
|
||||
name="del:{{ $fullProperty }}/{{$index}}"
|
||||
value="Supprimer" />
|
||||
<hr />
|
||||
</td>
|
||||
</tr>
|
||||
@ -23,7 +26,11 @@
|
||||
<tr>
|
||||
<td colspan="2"></td>
|
||||
<td align="right">
|
||||
<input type="submit" name="add:{{ $fullProperty }}/-" value="Ajouter" />
|
||||
<input
|
||||
class="bg-blue-500 text-white mb-2 mt-2 px-3 py-1 rounded-md text-sm font-medium hover:bg-blue-700 transition duration-300"
|
||||
type="submit"
|
||||
name="add:{{ $fullProperty }}/-"
|
||||
value="Ajouter" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -1,12 +1,22 @@
|
||||
{{define "form_input_boolean"}}
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
{{ $checked := getValue .Defaults .Values $fullProperty }}
|
||||
<label for="yes:{{ $fullProperty }}">
|
||||
Yes
|
||||
<input type="radio" id="yes:{{ $fullProperty }}" name="bool:{{ $fullProperty }}" value="yes" {{if $checked}}checked="yes"{{end}} />
|
||||
<label for="yes:{{ $fullProperty }}" class="inline-flex items-center mt-3">
|
||||
<input type="radio"
|
||||
class="h-5 w-5 text-gray-600"
|
||||
id="yes:{{ $fullProperty }}"
|
||||
name="bool:{{ $fullProperty }}"
|
||||
value="yes"
|
||||
{{if $checked}}checked="yes"{{end}} />
|
||||
<span class="ml-2 text-gray-700">Yes</span>
|
||||
</label>
|
||||
<label for="no:{{ $fullProperty }}">
|
||||
No
|
||||
<input type="radio" id="no:{{ $fullProperty }}" name="bool:{{ $fullProperty }}" value="no" {{if not $checked}}checked{{end}} />
|
||||
<label for="no:{{ $fullProperty }}" class="inline-flex items-center mt-3 ml-3">
|
||||
<input type="radio"
|
||||
class="h-5 w-5 text-gray-600"
|
||||
id="no:{{ $fullProperty }}"
|
||||
name="bool:{{ $fullProperty }}"
|
||||
value="no"
|
||||
{{if not $checked}}checked{{end}} />
|
||||
<span class="ml-2 text-gray-700">No</span>
|
||||
</label>
|
||||
{{end}}
|
@ -1,5 +1,8 @@
|
||||
{{define "form_input_number"}}
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
{{ $value := getValue .Defaults .Values $fullProperty }}
|
||||
<input type="number" name="{{ $fullProperty }}" value="{{ $value }}" />
|
||||
<input type="number"
|
||||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
|
||||
name="num:{{ $fullProperty }}"
|
||||
value="{{ $value }}" />
|
||||
{{end}}
|
@ -1,5 +1,9 @@
|
||||
{{define "form_input_string"}}
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
{{ $value := getValue .Defaults .Values $fullProperty }}
|
||||
<input type="text" name="{{ $fullProperty }}" id="{{ $fullProperty }}" value="{{ $value }}" />
|
||||
<input type="text"
|
||||
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
|
||||
name="{{ $fullProperty }}"
|
||||
id="{{ $fullProperty }}"
|
||||
value="{{ $value }}" />
|
||||
{{end}}
|
@ -2,12 +2,12 @@
|
||||
{{ $fullProperty := getFullProperty .Parent .Property }}
|
||||
<tr>
|
||||
<td align="left" nowrap="">
|
||||
<label for="{{ $fullProperty }}">
|
||||
<strong>
|
||||
<label for="{{ $fullProperty }}" class="block font-medium text-gray-900">
|
||||
<strong class="text-lg">
|
||||
{{ if .Schema.Title }}{{ .Schema.Title }}{{ else }}{{ .Property }}{{ end }}
|
||||
</strong>
|
||||
<br />
|
||||
<span>{{ .Schema.Description }}</span>
|
||||
<span class="text-sm">{{ .Schema.Description }}</span>
|
||||
</label>
|
||||
</td>
|
||||
<td align="left" nowrap="">
|
||||
@ -16,7 +16,7 @@
|
||||
<td>
|
||||
{{ $err := getPropertyError .Error $fullProperty }}
|
||||
{{if $err}}
|
||||
<em>{{ $err.Message }}</em>
|
||||
<em class="text-red-700 px-4 py-3">{{ $err.Message }}</em>
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -1,10 +1,5 @@
|
||||
{{define "head"}}
|
||||
<head>
|
||||
<title>Formidable</title>
|
||||
<style>
|
||||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
{{end}}
|
@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<html class="w-full h-full">
|
||||
{{ template "head" . }}
|
||||
<body>
|
||||
<link rel="stylesheet" href="assets/dist/main.css" />
|
||||
<body class="bg-gray-100 w-full h-full p-3">
|
||||
{{ template "form" . }}
|
||||
</body>
|
||||
</html>
|
@ -7,6 +7,7 @@ import (
|
||||
"html/template"
|
||||
"io"
|
||||
"io/fs"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"forge.cadoles.com/wpetit/formidable/internal/jsonpointer"
|
||||
@ -17,24 +18,22 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed layouts/* blocks/*
|
||||
files embed.FS
|
||||
layouts map[string]*template.Template
|
||||
blocks map[string]string
|
||||
)
|
||||
|
||||
func Load() error {
|
||||
func Load(files embed.FS, baseDir string) error {
|
||||
if blocks == nil {
|
||||
blocks = make(map[string]string)
|
||||
}
|
||||
|
||||
blockFiles, err := fs.ReadDir(files, "blocks")
|
||||
blockFiles, err := fs.ReadDir(files, path.Join(baseDir, "blocks"))
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
for _, f := range blockFiles {
|
||||
templateData, err := fs.ReadFile(files, "blocks/"+f.Name())
|
||||
templateData, err := fs.ReadFile(files, path.Join(baseDir, "blocks/"+f.Name()))
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
@ -42,13 +41,13 @@ func Load() error {
|
||||
blocks[f.Name()] = string(templateData)
|
||||
}
|
||||
|
||||
layoutFiles, err := fs.ReadDir(files, "layouts")
|
||||
layoutFiles, err := fs.ReadDir(files, path.Join(baseDir, "layouts"))
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
for _, f := range layoutFiles {
|
||||
templateData, err := fs.ReadFile(files, "layouts/"+f.Name())
|
||||
templateData, err := fs.ReadFile(files, path.Join(baseDir, "layouts/"+f.Name()))
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
@ -116,12 +115,13 @@ func mergeHelpers(helpers ...template.FuncMap) template.FuncMap {
|
||||
}
|
||||
|
||||
type FormItemData struct {
|
||||
Parent *FormItemData
|
||||
Schema *jsonschema.Schema
|
||||
Property string
|
||||
Error *jsonschema.ValidationError
|
||||
Values interface{}
|
||||
Defaults interface{}
|
||||
Parent *FormItemData
|
||||
Schema *jsonschema.Schema
|
||||
Property string
|
||||
Error *jsonschema.ValidationError
|
||||
Values interface{}
|
||||
Defaults interface{}
|
||||
SuccessMessage string
|
||||
}
|
||||
|
||||
func customHelpers(tpl *template.Template) template.FuncMap {
|
||||
|
Reference in New Issue
Block a user