diff --git a/sui/core/build.go b/sui/core/build.go index a400d1e2..1c752e00 100644 --- a/sui/core/build.go +++ b/sui/core/build.go @@ -357,6 +357,7 @@ func (page *Page) replaceProps(sel *goquery.Selection) error { } data := Data{} for key, prop := range page.props { + key = ToCamelCase(key) data[key] = prop.Val } data["$props"] = data diff --git a/sui/core/utils.go b/sui/core/utils.go index 3c4f0c19..e4a505cb 100644 --- a/sui/core/utils.go +++ b/sui/core/utils.go @@ -91,3 +91,22 @@ func TranslationKeyPrefix(name string) string { name = strings.ReplaceAll(name, "]", "_") return fmt.Sprintf("trans_%s", name) } + +// ToCamelCase convert the string to camel case +func ToCamelCase(s string, split ...string) string { + splitter := "-" + if len(split) > 0 { + splitter = split[0] + } + + s = strings.ToLower(s) + parts := strings.Split(s, splitter) + for i, part := range parts { + if i == 0 { + continue + } + parts[i] = strings.ToUpper(part[:1]) + part[1:] + } + + return strings.Join(parts, "") +}