Added float attribute type
This commit is contained in:
parent
cd2230f625
commit
296f7c71da
@ -342,10 +342,10 @@ func Hidden() hatmill.Attrib {
|
||||
}
|
||||
|
||||
// High creates a "high" attribute
|
||||
func High(value string) hatmill.Attrib {
|
||||
func High(value float32) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "high",
|
||||
Value: value,
|
||||
Value: strconv.FormatFloat(float64(value), 'G', -1, 32),
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,10 +468,10 @@ func Loop() hatmill.Attrib {
|
||||
}
|
||||
|
||||
// Low creates a "low" attribute
|
||||
func Low(value string) hatmill.Attrib {
|
||||
func Low(value float32) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "low",
|
||||
Value: value,
|
||||
Value: strconv.FormatFloat(float64(value), 'G', -1, 32),
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,10 +484,10 @@ func Manifest(value string) hatmill.Attrib {
|
||||
}
|
||||
|
||||
// Max creates a "max" attribute
|
||||
func Max(value string) hatmill.Attrib {
|
||||
func Max(value float32) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "max",
|
||||
Value: value,
|
||||
Value: strconv.FormatFloat(float64(value), 'G', -1, 32),
|
||||
}
|
||||
}
|
||||
|
||||
@ -516,10 +516,10 @@ func Method(value string) hatmill.Attrib {
|
||||
}
|
||||
|
||||
// Min creates a "min" attribute
|
||||
func Min(value string) hatmill.Attrib {
|
||||
func Min(value float32) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "min",
|
||||
Value: value,
|
||||
Value: strconv.FormatFloat(float64(value), 'G', -1, 32),
|
||||
}
|
||||
}
|
||||
|
||||
@ -568,10 +568,10 @@ func Open() hatmill.Attrib {
|
||||
}
|
||||
|
||||
// Optimum creates a "optimum" attribute
|
||||
func Optimum(value string) hatmill.Attrib {
|
||||
func Optimum(value float32) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "optimum",
|
||||
Value: value,
|
||||
Value: strconv.FormatFloat(float64(value), 'G', -1, 32),
|
||||
}
|
||||
}
|
||||
|
||||
|
10
defs.json
10
defs.json
@ -43,7 +43,7 @@
|
||||
{"name": "headers", "type": "string"},
|
||||
{"name": "height", "type": "int"},
|
||||
{"name": "hidden", "type": "bool"},
|
||||
{"name": "high", "type": "string"},
|
||||
{"name": "high", "type": "float"},
|
||||
{"name": "href", "type": "string"},
|
||||
{"name": "hreflang", "type": "string"},
|
||||
{"name": "http-equiv", "type": "string"},
|
||||
@ -59,20 +59,20 @@
|
||||
{"name": "language", "type": "string"},
|
||||
{"name": "list", "type": "string"},
|
||||
{"name": "loop", "type": "bool"},
|
||||
{"name": "low", "type": "string"},
|
||||
{"name": "low", "type": "float"},
|
||||
{"name": "manifest", "type": "string"},
|
||||
{"name": "max", "type": "string"},
|
||||
{"name": "max", "type": "float"},
|
||||
{"name": "maxlength", "type": "int"},
|
||||
{"name": "media", "type": "string"},
|
||||
{"name": "method", "type": "string"},
|
||||
{"name": "min", "type": "string"},
|
||||
{"name": "min", "type": "float"},
|
||||
{"name": "minlength", "type": "int"},
|
||||
{"name": "multiple", "type": "bool"},
|
||||
{"name": "muted", "type": "bool"},
|
||||
{"name": "name", "type": "string"},
|
||||
{"name": "novalidate", "type": "bool"},
|
||||
{"name": "open", "type": "bool"},
|
||||
{"name": "optimum", "type": "string"},
|
||||
{"name": "optimum", "type": "float"},
|
||||
{"name": "pattern", "type": "string"},
|
||||
{"name": "ping", "type": "string"},
|
||||
{"name": "placeholder", "type": "string"},
|
||||
|
@ -182,18 +182,14 @@ func Example() {
|
||||
userInput := "<script>launchMissiles();</script>"
|
||||
|
||||
document := he.Html()(
|
||||
he.Head()(
|
||||
he.Meta(ha.HttpEquiv("refresh"), ha.Content("5")),
|
||||
),
|
||||
he.Body()(
|
||||
he.Div()(
|
||||
he.Img(ha.Src("./me.jpg"), ha.Id("profile-photo")),
|
||||
hatmill.Text(html.EscapeString(userInput)),
|
||||
he.Div(ha.Disabled(), ha.CustomData("coolness", "awesome"))(),
|
||||
he.Textarea(ha.Height(25))(),
|
||||
),
|
||||
he.Img(ha.Src("./photo.jpg")),
|
||||
hatmill.Text(html.EscapeString(userInput)),
|
||||
he.Div(ha.Disabled(), ha.CustomData("coolness", "awesome"))(),
|
||||
he.Textarea(ha.Rows(25))(),
|
||||
he.Meter(ha.Min(-1.3), ha.Max(5.5E12))(),
|
||||
),
|
||||
)
|
||||
hatmill.WriteDocument(os.Stdout, document)
|
||||
// Output: <!DOCTYPE html><html><head><meta http-equiv='refresh' content='5'></head><body><div><img src='./me.jpg' id='profile-photo'><script>launchMissiles();</script><div disabled data-coolness='awesome'></div><textarea height='25'></textarea></div></body></html>
|
||||
// Output: <!DOCTYPE html><html><body><img src='./photo.jpg'><script>launchMissiles();</script><div disabled data-coolness='awesome'></div><textarea rows='25'></textarea><meter min='-1.3' max='5.5E+12'></meter></body></html>
|
||||
}
|
||||
|
@ -57,6 +57,18 @@ var attribTypes = map[string]AttribTypeInfo{
|
||||
`,
|
||||
Imports: []string{"strconv"},
|
||||
},
|
||||
|
||||
"float": {
|
||||
Template: `// %[1]s creates a "%[2]s" attribute
|
||||
func %[1]s(value float32) hatmill.Attrib {
|
||||
return hatmill.Attrib{
|
||||
Key: "%[2]s",
|
||||
Value: strconv.FormatFloat(float64(value), 'G', -1, 32),
|
||||
}
|
||||
}
|
||||
`,
|
||||
Imports: []string{"strconv"},
|
||||
},
|
||||
}
|
||||
|
||||
// Def represents a top-level definition and its required imports.
|
||||
|
Loading…
Reference in New Issue
Block a user