diff --git a/cstyle/transformers/flex/main.go b/cstyle/transformers/flex/main.go
index 7629b80..14a33c3 100644
--- a/cstyle/transformers/flex/main.go
+++ b/cstyle/transformers/flex/main.go
@@ -14 +14 @@ func Init() cstyle.Transformer {
- return n.CStyle["flex"] != ""
+ return n.Style["flex"] != ""
@@ -17 +17 @@ func Init() cstyle.Transformer {
- flex, _ := parseFlex(n.CStyle["flex"])
+ flex, _ := parseFlex(n.Style["flex"])
@@ -19,3 +19,3 @@ func Init() cstyle.Transformer {
- n.CStyle["flex-basis"] = flex.FlexBasis
- n.CStyle["flex-grow"] = flex.FlexGrow
- n.CStyle["flex-shrink"] = flex.FlexShrink
+ n.Style["flex-basis"] = flex.FlexBasis
+ n.Style["flex-grow"] = flex.FlexGrow
+ n.Style["flex-shrink"] = flex.FlexShrink
package flexprep
import (
"fmt"
"grim/cstyle"
"grim/element"
"strconv"
"strings"
)
func Init() cstyle.Transformer {
return cstyle.Transformer{
Selector: func(n *element.Node) bool {
return n.CStyle["flex"] != ""
},
Handler: func(n *element.Node, c *cstyle.CSS) *element.Node {
flex, _ := parseFlex(n.CStyle["flex"])
n.CStyle["flex-basis"] = flex.FlexBasis
n.CStyle["flex-grow"] = flex.FlexGrow
n.CStyle["flex-shrink"] = flex.FlexShrink
return n
},
}
}
type FlexProperties struct {
FlexGrow string
FlexShrink string
FlexBasis string
}
func parseFlex(flex string) (FlexProperties, error) {
parts := strings.Fields(flex)
prop := FlexProperties{
FlexGrow: "1", // default value
FlexShrink: "1", // default value
FlexBasis: "0%", // default value
}
switch len(parts) {
case 1:
if strings.HasSuffix(parts[0], "%") || strings.HasSuffix(parts[0], "px") || strings.HasSuffix(parts[0], "em") {
prop.FlexBasis = parts[0]
} else if _, err := strconv.ParseFloat(parts[0], 64); err == nil {
prop.FlexGrow = parts[0]
prop.FlexShrink = "1"
prop.FlexBasis = "0%"
} else {
return prop, fmt.Errorf("invalid flex value: %s", parts[0])
}
case 2:
prop.FlexGrow = parts[0]
prop.FlexShrink = parts[1]
prop.FlexBasis = "0%"
case 3:
prop.FlexGrow = parts[0]
prop.FlexShrink = parts[1]
prop.FlexBasis = parts[2]
default:
return prop, fmt.Errorf("invalid number of values for flex property")
}
return prop, nil
}