Skip to content

Commit c799c18

Browse files
committed
Migrate ticked templates to ui components
1 parent 0131af5 commit c799c18

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

examples/ticked/assets/templates/admin/events.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ <h1>Audit Events</h1>
2828
{{range .Events}}
2929
<div class="event-row">
3030
<span class="event-time">{{.CreatedAt.Format "15:04:05"}}</span>
31-
<span class="event-type"><span class="badge badge-event">{{.EventType}}</span></span>
31+
<span class="event-type">{{with chip .EventType}}{{.Render}}{{end}}</span>
3232
<span class="event-item-id" title="{{.ItemID}}">{{if .ItemID}}{{.ItemID}}{{else}}-{{end}}</span>
33-
<span class="event-source"><span class="badge badge-role">{{.Source}}</span></span>
33+
<span class="event-source">{{with chip .Source}}{{with .Info}}{{.Render}}{{end}}{{end}}</span>
3434
</div>
3535
{{else}}
3636
<div class="empty-state">No events recorded yet.</div>

examples/ticked/assets/templates/admin/user.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ <h1>User Details</h1>
3737
<span class="detail-label">Status:</span>
3838
<span class="detail-value">
3939
{{if .User.Active}}
40-
<span class="badge badge-active">Active</span>
40+
{{with chip "Active"}}{{with .Success}}{{.Render}}{{end}}{{end}}
4141
{{else}}
42-
<span class="badge badge-inactive">Inactive</span>
42+
{{with chip "Inactive"}}{{with .Danger}}{{.Render}}{{end}}{{end}}
4343
{{end}}
4444
</span>
4545
</div>
4646
<div class="detail-row">
4747
<span class="detail-label">Roles:</span>
4848
<span class="detail-value">
4949
{{if .User.Roles}}
50-
{{range .User.Roles}}<span class="badge badge-role">{{.}}</span> {{end}}
50+
{{range .User.Roles}}{{with chip .}}{{with .Info}}{{.Render}}{{end}}{{end}} {{end}}
5151
{{else}}
5252
<span class="text-muted">No roles assigned</span>
5353
{{end}}
@@ -67,16 +67,16 @@ <h2>Manage Roles</h2>
6767
<label for="roles">Roles (comma-separated):</label>
6868
<input type="text" id="roles" name="roles" value="{{.RolesString}}" placeholder="admin, user">
6969
</div>
70-
<button type="submit" class="btn-primary">Update Roles</button>
70+
{{with btnSubmit "Update Roles"}}{{with .Primary}}{{.Render}}{{end}}{{end}}
7171
</form>
7272

7373
<h2>Account Status</h2>
7474
<form hx-post="/admin/toggle-user" hx-target="body" hx-swap="innerHTML">
7575
<input type="hidden" name="id" value="{{.User.ID}}">
7676
{{if .User.Active}}
77-
<button type="submit" class="btn-danger">Deactivate User</button>
77+
{{with btnSubmit "Deactivate User"}}{{with .Danger}}{{.Render}}{{end}}{{end}}
7878
{{else}}
79-
<button type="submit" class="btn-success">Activate User</button>
79+
{{with btnSubmit "Activate User"}}{{with .Success}}{{.Render}}{{end}}{{end}}
8080
{{end}}
8181
</form>
8282
</div>

examples/ticked/assets/templates/todos/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h1>My Todo List</h1>
3030
hx-on::after-request="this.reset()"
3131
class="add-form">
3232
<input type="text" name="text" placeholder="What needs to be done?" required autofocus maxlength="500">
33-
<button type="submit" class="btn-primary">Add</button>
33+
{{with btnSubmit "Add"}}{{with .Primary}}{{.Render}}{{end}}{{end}}
3434
</form>
3535

3636
<div id="items-list" class="items-list">

examples/ticked/internal/web/handler_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/hatmaxkit/hatmax/auth"
1515
"github.com/hatmaxkit/hatmax/examples/ticked/internal/feat/audit"
1616
"github.com/hatmaxkit/hatmax/examples/ticked/internal/feat/list"
17-
"github.com/hatmaxkit/hatmax/kit"
17+
"github.com/hatmaxkit/hatmax/ui"
1818
"github.com/hatmaxkit/hatmax/log"
1919
"github.com/hatmaxkit/hatmax/web"
2020
)
@@ -41,7 +41,7 @@ func (f *fakeAuditStore) List(ctx context.Context, limit int) ([]audit.Record, e
4141

4242
func TestHandlerRegisterRoutes(t *testing.T) {
4343
logger := log.NewTestLogger("error")
44-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
44+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
4545

4646
h := &Handler{
4747
tmpl: tmplMgr,
@@ -104,7 +104,7 @@ func TestHandleIndex(t *testing.T) {
104104

105105
func TestHandleSigninForm(t *testing.T) {
106106
logger := log.NewTestLogger("error")
107-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
107+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
108108
tmplMgr.Start(context.Background())
109109

110110
h := &Handler{
@@ -124,7 +124,7 @@ func TestHandleSigninForm(t *testing.T) {
124124

125125
func TestHandleSignupForm(t *testing.T) {
126126
logger := log.NewTestLogger("error")
127-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
127+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
128128
tmplMgr.Start(context.Background())
129129

130130
h := &Handler{
@@ -144,7 +144,7 @@ func TestHandleSignupForm(t *testing.T) {
144144

145145
func TestHandleSignin_EmptyFields(t *testing.T) {
146146
logger := log.NewTestLogger("error")
147-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
147+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
148148
tmplMgr.Start(context.Background())
149149

150150
h := &Handler{
@@ -183,7 +183,7 @@ func TestHandleSignin_EmptyFields(t *testing.T) {
183183

184184
func TestHandleSignup_EmptyFields(t *testing.T) {
185185
logger := log.NewTestLogger("error")
186-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
186+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
187187
tmplMgr.Start(context.Background())
188188

189189
h := &Handler{
@@ -264,7 +264,7 @@ func TestHandleListItems_NoUser(t *testing.T) {
264264

265265
func TestHandleListItems_WithUser(t *testing.T) {
266266
logger := log.NewTestLogger("error")
267-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
267+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
268268
tmplMgr.Start(context.Background())
269269

270270
h := &Handler{
@@ -339,7 +339,7 @@ func TestHandleAddItem_EmptyText(t *testing.T) {
339339

340340
func TestHandleAddItem_Success(t *testing.T) {
341341
logger := log.NewTestLogger("error")
342-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
342+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
343343
tmplMgr.Start(context.Background())
344344

345345
h := &Handler{
@@ -411,7 +411,7 @@ func TestHandleDeleteItem_NoUser(t *testing.T) {
411411

412412
func TestHandleDashboard(t *testing.T) {
413413
logger := log.NewTestLogger("error")
414-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
414+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
415415
tmplMgr.Start(context.Background())
416416

417417
h := &Handler{
@@ -435,7 +435,7 @@ func TestHandleDashboard(t *testing.T) {
435435

436436
func TestHandleListUsers(t *testing.T) {
437437
logger := log.NewTestLogger("error")
438-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
438+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
439439
tmplMgr.Start(context.Background())
440440

441441
h := &Handler{
@@ -483,7 +483,7 @@ func TestHandleGetUser_MissingID(t *testing.T) {
483483

484484
func TestHandleGetUser_Success(t *testing.T) {
485485
logger := log.NewTestLogger("error")
486-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
486+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
487487
tmplMgr.Start(context.Background())
488488

489489
h := &Handler{
@@ -604,7 +604,7 @@ func TestHandleToggleUser_SelfDeactivate(t *testing.T) {
604604

605605
func TestHandleListEvents(t *testing.T) {
606606
logger := log.NewTestLogger("error")
607-
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(kit.FuncMap()))
607+
tmplMgr := web.NewTemplateManager(testAssetsFS, logger, web.WithFuncMap(ui.FuncMap()))
608608
tmplMgr.Start(context.Background())
609609

610610
h := &Handler{

examples/ticked/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
authfeat "github.com/hatmaxkit/hatmax/examples/ticked/internal/feat/auth"
1818
listfeat "github.com/hatmaxkit/hatmax/examples/ticked/internal/feat/list"
1919
tickedweb "github.com/hatmaxkit/hatmax/examples/ticked/internal/web"
20-
"github.com/hatmaxkit/hatmax/kit"
20+
"github.com/hatmaxkit/hatmax/ui"
2121
"github.com/hatmaxkit/hatmax/log"
2222
"github.com/hatmaxkit/hatmax/middleware"
2323
"github.com/hatmaxkit/hatmax/pubsub/postgres"
@@ -50,7 +50,7 @@ func main() {
5050

5151
database := db.New(assetsFS, "postgres", cfg, logger)
5252
migrator := db.NewMigrator(database, assetsFS, "postgres", logger)
53-
tmplMgr := web.NewTemplateManager(assetsFS, logger, web.WithFuncMap(kit.FuncMap()))
53+
tmplMgr := web.NewTemplateManager(assetsFS, logger, web.WithFuncMap(ui.FuncMap()))
5454
broker := postgres.NewBroker(database, postgres.DefaultConfig(), logger)
5555

5656
auditStore := auditfeat.NewPostgresStore(database)

0 commit comments

Comments
 (0)