parent
349aa0dd5d
commit
74760707dd
@ -0,0 +1,27 @@ |
||||
<small> |
||||
{{ if .MetaData.Yield }} |
||||
Servings: <span class="p-yield">{{ .MetaData.Yield }}</span> |
||||
{{ if .MetaData.Duration }}, {{end}} |
||||
|
||||
{{ end }} |
||||
|
||||
{{ if .MetaData.Duration }} |
||||
Prep Time: <time class="dt-duration" value="{{ .MetaData.Duration }}"> |
||||
{{ .MetaData.Duration }} |
||||
</time> |
||||
{{ end }} |
||||
</small> |
||||
<br> <br> |
||||
|
||||
<h2>Ingredients</h2> |
||||
|
||||
<ul> |
||||
{{ range $ingredient := .MetaData.Ingredients }} |
||||
<li class="p-ingredient"> |
||||
{{ $ingredient }} |
||||
</li> |
||||
{{ end }} |
||||
</ul> |
||||
|
||||
<h2>Instructions</h2> |
||||
{{.MetaData.Content | markdown }} |
@ -0,0 +1,72 @@ |
||||
package forms |
||||
|
||||
import ( |
||||
"fmt" |
||||
"reflect" |
||||
"strings" |
||||
) |
||||
|
||||
type Widget interface { |
||||
Html() string |
||||
ParseValue(value string, output reflect.Value) error |
||||
} |
||||
|
||||
type TextWidget struct { |
||||
FormField |
||||
} |
||||
|
||||
func (s *TextWidget) Html() string { |
||||
html := "" |
||||
html += fmt.Sprintf("<input type=\"text\" name=\"%v\" value=\"%v\">\n", s.Name, s.Value.String()) |
||||
return html |
||||
} |
||||
|
||||
func (s *TextWidget) ParseValue(value string, output reflect.Value) error { |
||||
output.SetString(value) |
||||
return nil |
||||
} |
||||
|
||||
type TextareaWidget struct { |
||||
FormField |
||||
} |
||||
|
||||
func (s *TextareaWidget) Html() string { |
||||
html := "" |
||||
html += fmt.Sprintf("<textarea name=\"%v\" rows=\"20\">%v</textarea>\n", s.Name, s.Value.String()) |
||||
return html |
||||
} |
||||
|
||||
func (s *TextareaWidget) ParseValue(value string, output reflect.Value) error { |
||||
output.SetString(value) |
||||
return nil |
||||
} |
||||
|
||||
type TextListWidget struct { |
||||
FormField |
||||
} |
||||
|
||||
func (s *TextListWidget) Html() string { |
||||
valueList := s.Value.Interface().([]string) |
||||
value := strings.Join(valueList, "\n") |
||||
|
||||
html := "" |
||||
html += fmt.Sprintf("<textarea name=\"%v\" rows=\"20\">%v</textarea>\n", s.Name, value) |
||||
return html |
||||
} |
||||
|
||||
func (s *TextListWidget) ParseValue(value string, output reflect.Value) error { |
||||
list := strings.Split(value, "\n") |
||||
// trim entries
|
||||
for i, item := range list { |
||||
list[i] = strings.TrimSpace(item) |
||||
} |
||||
// remove empty entries
|
||||
for i := len(list) - 1; i >= 0; i-- { |
||||
if list[i] == "" { |
||||
list = append(list[:i], list[i+1:]...) |
||||
} |
||||
} |
||||
|
||||
output.Set(reflect.ValueOf(list)) |
||||
return nil |
||||
} |
Loading…
Reference in new issue