1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| package clib
import ( "fmt" "strings"
"github.com/muesli/gamut" "github.com/pkg/errors" "github.com/samber/lo" "github.com/valyala/fasthttp"
"{{{ .Package }}}/app" "{{{ .Package }}}/app/controller" "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/lib/telemetry" "{{{ .Package }}}/app/lib/theme" "{{{ .Package }}}/app/util" "{{{ .Package }}}/views" "{{{ .Package }}}/views/vtheme" )
func ThemeColor(rc *fasthttp.RequestCtx) { controller.Act("theme.color", rc, func(as *app.State, ps *cutil.PageState) (string, error) { col, err := cutil.RCRequiredString(rc, "color", false) if err != nil { return "", err } col = strings.ToLower(col) if !strings.HasPrefix(col, "#") { col = "#" + col } ps.Title = fmt.Sprintf("[%s] Theme", col) th := theme.ColorTheme(col, gamut.Hex(col)) ps.Data = th return controller.Render(rc, as, &vtheme.Edit{Theme: th, Icon: "app"}, ps, "Themes||/theme", col) }) }
func ThemeColorEdit(rc *fasthttp.RequestCtx) { controller.Act("theme.color.edit", rc, func(as *app.State, ps *cutil.PageState) (string, error) { color := string(rc.URI().QueryArgs().Peek("color")) if color == "" { return "", errors.New("must provide color in query string") } if !strings.HasPrefix(color, "#") { return "", errors.New("provided color must be a hex string") } t := theme.ColorTheme(strings.TrimPrefix(color, "#"), gamut.Hex(color)) ps.Title = "Edit theme [" + t.Key + "]" ps.Data = t page := &vtheme.Edit{Theme: t, Icon: "app", Exists: as.Themes.FileExists(t.Key)} return controller.Render(rc, as, page, ps, "Themes||/theme", t.Key) }) }
func ThemePalette(rc *fasthttp.RequestCtx) { controller.Act("theme.palette", rc, func(as *app.State, ps *cutil.PageState) (string, error) { pal, err := cutil.RCRequiredString(rc, "palette", false) if err != nil { return "", err } ps.Title = fmt.Sprintf("[%s] Themes", pal) _, span, _ := telemetry.StartSpan(ps.Context, "theme:load", ps.Logger) thms, err := theme.PaletteThemes(pal) span.Complete() if err != nil { return "", err } if string(rc.URI().QueryArgs().Peek("t")) == "go" { ps.Data = strings.Join(lo.Map(thms, func(t *theme.Theme, _ int) string { return t.ToGo() }), util.StringDefaultLinebreak) return controller.Render(rc, as, &views.Debug{}, ps, "Themes") } else { ps.Data = thms } return controller.Render(rc, as, &vtheme.Add{Palette: pal, Themes: thms}, ps, "Themes") }) }
func ThemePaletteEdit(rc *fasthttp.RequestCtx) { controller.Act("theme.palette.edit", rc, func(as *app.State, ps *cutil.PageState) (string, error) { palette, err := cutil.RCRequiredString(rc, "palette", false) if err != nil { return "", err } key, err := cutil.RCRequiredString(rc, "theme", false) if err != nil { return "", err } if key == theme.Default.Key { return controller.FlashAndRedir(false, "Unable to edit default theme", "/theme", rc, ps) } themes, err := theme.PaletteThemes(palette) if err != nil { return "", err } t := themes.Get(key) if t == nil { return "", errors.Errorf("invalid theme [%s] for palette [%s]", key, palette) } ps.Title = "Edit theme [" + t.Key + "]" ps.Data = t return controller.Render(rc, as, &vtheme.Edit{Theme: t, Icon: "app"}, ps, "Themes||/theme", t.Key) }) }
|