Add generator for add_update templates
This commit is contained in:
parent
94da7ad65f
commit
d547cf320e
4 changed files with 48 additions and 105 deletions
|
@ -61,17 +61,21 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
filename := filepath.Join(*outDir, name+".html.tpl")
|
||||
oFn, err := os.Create(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer oFn.Close()
|
||||
if _, err := os.Stat(filename); err != nil {
|
||||
oFn, err := os.Create(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer oFn.Close()
|
||||
|
||||
log.Printf("Generating html template %s for model %s...", filename, name)
|
||||
log.Printf("Generating html template %s for model %s...", filename, name)
|
||||
|
||||
err = tpl.Execute(oFn, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
err = tpl.Execute(oFn, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
log.Printf("Template %s already exists. Skipping.", filename)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -1,57 +1,25 @@
|
|||
{{"{{ define \"content\" }}"}}
|
||||
|
||||
<div class="container">
|
||||
|
||||
<nav aria-label="breadcrumb">
|
||||
{{"{{if .Options.Get \"update\"}}"}}
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/{{.Models}}?{{"{{query \"tpl_layout\" \"base\" \"tpl_content\" "}}"{{.Models}}"}}">{{.Model}}</a></li>
|
||||
<li class="breadcrumb-item active"><a href="#">Aggiorna {{.Model}}</a></li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
{{"{{else}}"}}
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/{{.Models}}?{{"{{query \"tpl_layout\" \"base\" \"tpl_content\" "}}"{{.Models}}"}}">{{.Model}}</a></li>
|
||||
<li class="active"><a href="#">Aggiungi</a></li>
|
||||
</ol>
|
||||
{{"{{end}}"}}
|
||||
{{"{{$update := .Options.Get \"update\"}}"}}
|
||||
|
||||
{{"{{if .Options.Get \"update\"}}"}}
|
||||
<div class="karmen-info-header">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h1>Aggiorna {{.Model}}</h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{"{{else}}"}}
|
||||
<h1 class="karmen-info-header">Crea nuovo {{.Model}}</h1>
|
||||
{{"{{end}}"}}
|
||||
{{"{{if $update}}"}}
|
||||
|
||||
{{"{{if .Options.Get \"update\"}}"}}
|
||||
<form id="form_{{.Models}}_add_update" action="/{{.Models}}/{{"{{.Data.ID}}"}}/update" method="POST" role="form" data-toggle="validator">
|
||||
{{"{{else}}"}}
|
||||
<form id="form_{{.Models}}_add_update" action="/{{.Models}}/add/" method="POST" role="form" data-toggle="validator">
|
||||
{{"{{end}}"}}
|
||||
{{"{{template \"breadcrumb\" toSlice "}}"{{.Models}}" (all "{{.Model}}") (.Data|string) (.Data.ID|show "{{.Model}}") {{"\"Aggiorna\" \"current\"}}"}}
|
||||
{{"{{else}}"}}
|
||||
{{"{{template \"breadcrumb\" toSlice "}}"{{.Models}}" (all "{{.Model}}") {{"\"Aggiungi\" \"current\"}}"}}
|
||||
{{"{{end}}"}}
|
||||
|
||||
{{"{{template \"add_update_header\" dict \"update\" $update \"addTitle\" \"Crea nuovo ELEMENTO\" \"updateTitle\" (printf \"Aggiorna ELEMENTO %s\" (.Data|string))}}"}}
|
||||
{{"{{$form := \"form_add_update\"}}"}}
|
||||
<form
|
||||
class="needs-validation"
|
||||
{{" action=\"{{if $update}}{{.Data.ID|update "}}"{{.Model}}"{{"}}{{else}}"}}{{"{{create "}}"{{.Model}}"{{"}}{{end}}\""}}
|
||||
method="POST"
|
||||
role="form"
|
||||
{{" id={{$form}}>"}}
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="control-label" for="{{.Model}}_name">Nome</label>
|
||||
<input type="text" name="Name" class="form-control" id="{{.Model}}_name" placeholder="Nome" {{"{{if .Options.Get \"update\"}}"}} value="{{"{{.Data.Name}}"}}" {{"{{end}}"}} required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">Salva</button>
|
||||
{{"{{if .Options.Get \"update\"}}"}}
|
||||
<a href="/{{.Models}}/{{"{{.Data.ID}}"}}?{{"{{query \"tpl_layout\" \"base\" \"tpl_content\" "}}"{{.Models}}{{"_show\"}}"}}" class="btn btn-default">Annulla</a>
|
||||
{{"{{else}}"}}
|
||||
<a href="/{{.Models}}?{{"{{query \"tpl_layout\" \"base\" \"tpl_content\" "}}"{{.Models}}"{{"}}"}}" class="btn btn-default">Annulla</a>
|
||||
{{"{{end}}"}}
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
{{"{{ end }}"}}
|
||||
|
|
|
@ -1,57 +1,28 @@
|
|||
{{ define "content" }}
|
||||
|
||||
<div class="container">
|
||||
|
||||
<nav aria-label="breadcrumb">
|
||||
{{if .Options.Get "update"}}
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/Questions?{{query "tpl_layout" "base" "tpl_content" "Questions"}}">Question</a></li>
|
||||
<li class="breadcrumb-item active"><a href="#">Aggiorna Question</a></li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
{{else}}
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/Questions?{{query "tpl_layout" "base" "tpl_content" "Questions"}}">Question</a></li>
|
||||
<li class="active"><a href="#">Aggiungi</a></li>
|
||||
</ol>
|
||||
{{end}}
|
||||
{{$update := .Options.Get "update"}}
|
||||
|
||||
{{if .Options.Get "update"}}
|
||||
<div class="karmen-info-header">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h1>Aggiorna Question</h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{else}}
|
||||
<h1 class="karmen-info-header">Crea nuovo Question</h1>
|
||||
{{end}}
|
||||
{{if $update}}
|
||||
|
||||
{{if .Options.Get "update"}}
|
||||
<form id="form_Questions_add_update" action="/Questions/{{.Data.ID}}/update" method="POST" role="form" data-toggle="validator">
|
||||
{{else}}
|
||||
<form id="form_Questions_add_update" action="/Questions/add/" method="POST" role="form" data-toggle="validator">
|
||||
{{end}}
|
||||
{{template "breadcrumb" toSlice "Questions" (all "Question") (.Data|string) (.Data.ID|show "Question") "Aggiorna" "current"}}
|
||||
{{else}}
|
||||
{{template "breadcrumb" toSlice "Questions" (all "Question") "Aggiungi" "current"}}
|
||||
{{end}}
|
||||
|
||||
{{template "add_update_header" dict "update" $update "addTitle" "Crea nuovo ELEMENTO" "updateTitle" (printf "Aggiorna ELEMENTO %s" (.Data|string))}}
|
||||
{{$form := "form_add_update"}}
|
||||
<form
|
||||
class="needs-validation"
|
||||
action="{{if $update}}{{.Data.ID|update "Question"}}{{else}}{{create "Question"}}{{end}}"
|
||||
method="POST"
|
||||
role="form"
|
||||
id={{$form}}>
|
||||
|
||||
{{$options := ` { name: "Text",id: "question_text",label: "Testo della domanda",placeholder: "Inserire il testo della domanda",type: "text",required: "true"} `}}
|
||||
{{template "input" dict "options" ($options|yaml) "value" (.Data|field "Text") "update" $update}}
|
||||
|
||||
<div class="form-group has-feedback">
|
||||
<label class="control-label" for="Question_name">Nome</label>
|
||||
<input type="text" name="Name" class="form-control" id="Question_name" placeholder="Nome" {{if .Options.Get "update"}} value="{{.Data.Name}}" {{end}} required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">Salva</button>
|
||||
{{if .Options.Get "update"}}
|
||||
<a href="/Questions/{{.Data.ID}}?{{query "tpl_layout" "base" "tpl_content" "Questions_show"}}" class="btn btn-default">Annulla</a>
|
||||
{{else}}
|
||||
<a href="/Questions?{{query "tpl_layout" "base" "tpl_content" "Questions"}}" class="btn btn-default">Annulla</a>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in a new issue