Skip to content

Commit

Permalink
refactor: remove old pkg package
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Aug 14, 2024
1 parent 6074074 commit e5bd03e
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 181 deletions.
8 changes: 5 additions & 3 deletions attrib.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package htmx

import (
"fmt"

"github.com/zeiss/pkg/conv"
)

// HxEventType represents the type of htmx event.
Expand All @@ -25,7 +27,7 @@ const (

// HxBoost sets the hx-boost attribute to enable or disable boosting.
func HxBoost(v bool) Node {
return Attribute("hx-boost", AsStr(v))
return Attribute("hx-boost", conv.String(v))
}

// HxGet sets the hx-get attribute to specify the URL for GET requests.
Expand All @@ -40,7 +42,7 @@ func HxPost(url string) Node {

// HxPushUrl sets the hx-push-url attribute to enable or disable URL pushing.
func HxPushUrl(v bool) Node {
return Attribute("hx-boost", AsStr(v))
return Attribute("hx-boost", conv.String(v))
}

// HxTarget sets the hx-target attribute to specify the target element for the response.
Expand Down Expand Up @@ -170,7 +172,7 @@ func HxDisabledElt(target string) Node {

// HxValidate sets the hx-validate attribute to enable or disable form validation.
func HxValidate(v bool) Node {
return Attribute("hx-validate", AsStr(v))
return Attribute("hx-validate", conv.String(v))
}

// HxInclude sets the hx-include attribute to specify the target element for inclusion.
Expand Down
9 changes: 6 additions & 3 deletions components/collapsible/collapsible.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package collapsible

import htmx "github.com/zeiss/fiber-htmx"
import (
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/pkg/conv"
)

// CollapseProps is a component that can be expanded and collapsed.
type CollapseProps struct {
Expand All @@ -18,15 +21,15 @@ func Collapse(props CollapseProps, children ...htmx.Node) htmx.Node {
},
props.ClassNames,
),
htmx.Attribute("tabindex", htmx.IntAsString(props.TabIndex)),
htmx.Attribute("tabindex", conv.String(props.TabIndex)),
htmx.Group(children...),
)
}

// CollapseArrow is a component that can be expanded and collapsed.
func CollapseArrow(p CollapseProps, children ...htmx.Node) htmx.Node {
return htmx.Div(
htmx.Attribute("tabindex", htmx.IntAsString(p.TabIndex)),
htmx.Attribute("tabindex", conv.String(p.TabIndex)),
htmx.Merge(
htmx.ClassNames{
"collapse": true,
Expand Down
5 changes: 3 additions & 2 deletions components/dropdowns/dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dropdowns

import (
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/pkg/conv"
)

// DropdownProps represents the properties for a dropdown element.
Expand Down Expand Up @@ -31,7 +32,7 @@ type DropdownButtonProps struct {
// DropdownButton generates a dropdown summary element based on the provided properties.
func DropdownButton(p DropdownButtonProps, children ...htmx.Node) htmx.Node {
return htmx.Div(
htmx.TabIndex(htmx.IntAsString(p.TabIndex)),
htmx.TabIndex(conv.String(p.TabIndex)),
htmx.Role("button"),
htmx.Merge(
htmx.ClassNames{
Expand All @@ -55,7 +56,7 @@ type DropdownMenuItemsProps struct {
func DropdownMenuItems(p DropdownMenuItemsProps, children ...htmx.Node) htmx.Node {
return htmx.Ul(
htmx.TabIndex(
htmx.IntAsString(p.TabIndex),
conv.String(p.TabIndex),
),
htmx.Merge(
htmx.ClassNames{
Expand Down
29 changes: 16 additions & 13 deletions components/progress/progress.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package progress

import htmx "github.com/zeiss/fiber-htmx"
import (
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/pkg/conv"
)

// ProgressProps is a struct that contains the props of the progress component
type ProgressProps struct {
Expand All @@ -19,8 +22,8 @@ func Progress(p ProgressProps, children ...htmx.Node) htmx.Node {
},
p.ClassNames,
),
htmx.Attribute("max", htmx.IntAsString(p.Max)),
htmx.Attribute("value", htmx.IntAsString(p.Value)),
htmx.Attribute("max", conv.String(p.Max)),
htmx.Attribute("value", conv.String(p.Value)),
htmx.Group(children...),
)
}
Expand All @@ -36,8 +39,8 @@ func ProgressPrimary(p ProgressProps, children ...htmx.Node) htmx.Node {
},
p.ClassNames,
),
htmx.Attribute("max", htmx.IntAsString(p.Max)),
htmx.Attribute("value", htmx.IntAsString(p.Value)),
htmx.Attribute("max", conv.String(p.Max)),
htmx.Attribute("value", conv.String(p.Value)),
htmx.Group(children...),
)
}
Expand All @@ -53,8 +56,8 @@ func ProgressSecondary(p ProgressProps, children ...htmx.Node) htmx.Node {
},
p.ClassNames,
),
htmx.Attribute("max", htmx.IntAsString(p.Max)),
htmx.Attribute("value", htmx.IntAsString(p.Value)),
htmx.Attribute("max", conv.String(p.Max)),
htmx.Attribute("value", conv.String(p.Value)),
htmx.Group(children...),
)
}
Expand All @@ -70,8 +73,8 @@ func ProgressSuccess(p ProgressProps, children ...htmx.Node) htmx.Node {
},
p.ClassNames,
),
htmx.Attribute("max", htmx.IntAsString(p.Max)),
htmx.Attribute("value", htmx.IntAsString(p.Value)),
htmx.Attribute("max", conv.String(p.Max)),
htmx.Attribute("value", conv.String(p.Value)),
htmx.Group(children...),
)
}
Expand All @@ -87,8 +90,8 @@ func ProgressInfo(p ProgressProps, children ...htmx.Node) htmx.Node {
},
p.ClassNames,
),
htmx.Attribute("max", htmx.IntAsString(p.Max)),
htmx.Attribute("value", htmx.IntAsString(p.Value)),
htmx.Attribute("max", conv.String(p.Max)),
htmx.Attribute("value", conv.String(p.Value)),
htmx.Group(children...),
)
}
Expand All @@ -103,8 +106,8 @@ func ProgressWarning(p ProgressProps, children ...htmx.Node) htmx.Node {
"progress-warning": true,
},
),
htmx.Attribute("max", htmx.IntAsString(p.Max)),
htmx.Attribute("value", htmx.IntAsString(p.Value)),
htmx.Attribute("max", conv.String(p.Max)),
htmx.Attribute("value", conv.String(p.Value)),
htmx.Group(children...),
)
}
Expand Down
3 changes: 2 additions & 1 deletion comps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/pkg/conv"
)

func BenchmarkElement(b *testing.B) {
Expand All @@ -32,7 +33,7 @@ func ExampleElement_tag() {
}

func ExampleAttribute_bool() {
_ = htmx.Attribute("disabled", htmx.AsStr(true)).Render(os.Stdout)
_ = htmx.Attribute("disabled", conv.String(true)).Render(os.Stdout)
// Output: disabled="true"
}

Expand Down
2 changes: 1 addition & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"time"

"github.com/katallaxie/pkg/server"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/bundle"
"github.com/zeiss/fiber-htmx/components/alerts"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/zeiss/fiber-htmx/components/toasts"
"github.com/zeiss/fiber-htmx/components/utils"
"github.com/zeiss/fiber-htmx/sse"
"github.com/zeiss/pkg/server"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
Expand Down
7 changes: 4 additions & 3 deletions htmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gofiber/fiber/v2"
authz "github.com/zeiss/fiber-authz"
"github.com/zeiss/pkg/conv"
)

// The contextKey type is unexported to prevent collisions with context keys defined in
Expand Down Expand Up @@ -112,7 +113,7 @@ func HxTriggers(c *fiber.Ctx, target string) {

// Boosted returns true if the request is boosted.
func Boosted(c *fiber.Ctx) bool {
return AsBool(c.Get(HxRequestHeaderBoosted.String()))
return conv.Bool(c.Get(HxRequestHeaderBoosted.String()))
}

// CurrentURL returns the current URL.
Expand All @@ -122,7 +123,7 @@ func CurrentURL(c *fiber.Ctx) string {

// HistoryRestoreRequest returns true if the request is a history restore request.
func HistoryRestoreRequest(c *fiber.Ctx) bool {
return AsBool(c.Get(HxRequestHeaderHistoryRestoreRequest.String()))
return conv.Bool(c.Get(HxRequestHeaderHistoryRestoreRequest.String()))
}

// Prompt returns the prompt.
Expand All @@ -132,7 +133,7 @@ func Prompt(c *fiber.Ctx) string {

// Request returns true if the request is an htmx request.
func Request(c *fiber.Ctx) bool {
return AsBool(c.Get(HxRequestHeaderRequest.String()))
return conv.Bool(c.Get(HxRequestHeaderRequest.String()))
}

// Targets is a helper function to get the target.
Expand Down
4 changes: 2 additions & 2 deletions sse/sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
"github.com/katallaxie/pkg/server"
"github.com/valyala/fasthttp"
"github.com/zeiss/pkg/server"
)

var _ Event = (*EventImpl)(nil)
Expand Down Expand Up @@ -98,7 +98,7 @@ func (b *BroadcastManagerImpl) Remove(client Client) {
func (b *BroadcastManagerImpl) Start(ctx context.Context, ready server.ReadyFunc, run server.RunFunc) func() error {
return func() error {
if b.poolSize < 1 {
return server.NewError(fmt.Errorf("pool size must be greater than 0"))
return server.NewServerError(fmt.Errorf("pool size must be greater than 0"))
}

b.startWorkers(ctx)
Expand Down
9 changes: 6 additions & 3 deletions swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"strings"
"time"

"github.com/zeiss/pkg/cast"
"github.com/zeiss/pkg/conv"
)

var (
Expand Down Expand Up @@ -181,15 +184,15 @@ func (s *Swap) String() string {
}

if s.transition != nil {
parts = append(parts, fmt.Sprintf("transition:%s", AsStr(*s.transition)))
parts = append(parts, fmt.Sprintf("transition:%s", conv.String(cast.Value(s.transition))))
}

if s.ignoreTitle != nil {
parts = append(parts, fmt.Sprintf("ignoreTitle:%s", AsStr(*s.ignoreTitle)))
parts = append(parts, fmt.Sprintf("ignoreTitle:%s", conv.String(cast.Value(s.ignoreTitle))))
}

if s.focusScroll != nil {
parts = append(parts, fmt.Sprintf("focus-scroll:%s", AsStr(*s.focusScroll)))
parts = append(parts, fmt.Sprintf("focus-scroll:%s", conv.String(cast.Value(s.focusScroll))))
}

if s.timing != nil {
Expand Down
Loading

0 comments on commit e5bd03e

Please sign in to comment.