Upgrade to Bulma 1.0.2.

This commit is contained in:
mikestefanello 2025-02-18 19:19:09 -05:00
parent 3eab2f5562
commit acbc5e4bf6
7 changed files with 21 additions and 43 deletions

View file

@ -3,7 +3,6 @@ package funcmap
import ( import (
"fmt" "fmt"
"html/template" "html/template"
"reflect"
"strings" "strings"
"github.com/Masterminds/sprig" "github.com/Masterminds/sprig"
@ -29,7 +28,6 @@ func NewFuncMap(web *echo.Echo) template.FuncMap {
funcs := sprig.FuncMap() funcs := sprig.FuncMap()
// Include all the custom functions // Include all the custom functions
funcs["hasField"] = fm.hasField
funcs["file"] = fm.file funcs["file"] = fm.file
funcs["link"] = fm.link funcs["link"] = fm.link
funcs["url"] = fm.url funcs["url"] = fm.url
@ -37,18 +35,6 @@ func NewFuncMap(web *echo.Echo) template.FuncMap {
return funcs return funcs
} }
// hasField checks if an interface contains a given field
func (fm *funcMap) hasField(v any, name string) bool {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
if rv.Kind() != reflect.Struct {
return false
}
return rv.FieldByName(name).IsValid()
}
// file appends a cache buster to a given filepath so it can remain cached until the app is restarted // file appends a cache buster to a given filepath so it can remain cached until the app is restarted
func (fm *funcMap) file(filepath string) string { func (fm *funcMap) file(filepath string) string {
return fmt.Sprintf("/%s/%s?v=%s", config.StaticPrefix, filepath, CacheBuster) return fmt.Sprintf("/%s/%s?v=%s", config.StaticPrefix, filepath, CacheBuster)

View file

@ -12,22 +12,11 @@ import (
func TestNewFuncMap(t *testing.T) { func TestNewFuncMap(t *testing.T) {
f := NewFuncMap(echo.New()) f := NewFuncMap(echo.New())
assert.NotNil(t, f["hasField"])
assert.NotNil(t, f["link"]) assert.NotNil(t, f["link"])
assert.NotNil(t, f["file"]) assert.NotNil(t, f["file"])
assert.NotNil(t, f["url"]) assert.NotNil(t, f["url"])
} }
func TestHasField(t *testing.T) {
type example struct {
name string
}
var e example
f := new(funcMap)
assert.True(t, f.hasField(e, "name"))
assert.False(t, f.hasField(e, "abcd"))
}
func TestLink(t *testing.T) { func TestLink(t *testing.T) {
f := new(funcMap) f := new(funcMap)

View file

@ -75,7 +75,8 @@ func (h *Files) Page(ctx echo.Context) error {
func (h *Files) Submit(ctx echo.Context) error { func (h *Files) Submit(ctx echo.Context) error {
file, err := ctx.FormFile("file") file, err := ctx.FormFile("file")
if err != nil { if err != nil {
return err msg.Danger(ctx, "A file is required.")
return h.Page(ctx)
} }
src, err := file.Open() src, err := file.Open()

View file

@ -13,7 +13,7 @@
{{end}} {{end}}
{{define "css"}} {{define "css"}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css">
{{end}} {{end}}
{{define "js"}} {{define "js"}}

View file

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en" data-theme="light">
<head> <head>
{{template "metatags" .}} {{template "metatags" .}}
{{template "css" .}} {{template "css" .}}

View file

@ -1,11 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" style="height:100%;"> <html lang="en" data-theme="light">
<head> <head>
{{template "metatags" .}} {{template "metatags" .}}
{{template "css" .}} {{template "css" .}}
{{template "js" .}} {{template "js" .}}
</head> </head>
<body class="has-background-light" style="min-height:100%;"> <body>
<nav class="navbar is-dark"> <nav class="navbar is-dark">
<div class="container"> <div class="container">
<div class="navbar-brand" hx-boost="true"> <div class="navbar-brand" hx-boost="true">

View file

@ -31,20 +31,22 @@
{{template "field-errors" (.Form.GetFieldErrors "Email")}} {{template "field-errors" (.Form.GetFieldErrors "Email")}}
</div> </div>
<div class="control"> <div class="control field">
<label class="label">Department</label> <label class="label">Department</label>
<label class="radio"> <div class="radios">
<input type="radio" name="department" value="sales" {{if eq .Form.Department "sales"}}checked{{end}}/> <label class="radio">
Sales <input type="radio" name="department" value="sales" {{if eq .Form.Department "sales"}}checked{{end}}/>
</label> Sales
<label class="radio"> </label>
<input type="radio" name="department" value="marketing" {{if eq .Form.Department "marketing"}}checked{{end}}/> <label class="radio">
Marketing <input type="radio" name="department" value="marketing" {{if eq .Form.Department "marketing"}}checked{{end}}/>
</label> Marketing
<label class="radio"> </label>
<input type="radio" name="department" value="hr" {{if eq .Form.Department "hr"}}checked{{end}}/> <label class="radio">
HR <input type="radio" name="department" value="hr" {{if eq .Form.Department "hr"}}checked{{end}}/>
</label> HR
</label>
</div>
{{template "field-errors" (.Form.GetFieldErrors "Department")}} {{template "field-errors" (.Form.GetFieldErrors "Department")}}
</div> </div>