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
|
// High creates a "high" attribute
|
||||||
func High(value string) hatmill.Attrib {
|
func High(value float32) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "high",
|
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
|
// Low creates a "low" attribute
|
||||||
func Low(value string) hatmill.Attrib {
|
func Low(value float32) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "low",
|
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
|
// Max creates a "max" attribute
|
||||||
func Max(value string) hatmill.Attrib {
|
func Max(value float32) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "max",
|
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
|
// Min creates a "min" attribute
|
||||||
func Min(value string) hatmill.Attrib {
|
func Min(value float32) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "min",
|
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
|
// Optimum creates a "optimum" attribute
|
||||||
func Optimum(value string) hatmill.Attrib {
|
func Optimum(value float32) hatmill.Attrib {
|
||||||
return hatmill.Attrib{
|
return hatmill.Attrib{
|
||||||
Key: "optimum",
|
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": "headers", "type": "string"},
|
||||||
{"name": "height", "type": "int"},
|
{"name": "height", "type": "int"},
|
||||||
{"name": "hidden", "type": "bool"},
|
{"name": "hidden", "type": "bool"},
|
||||||
{"name": "high", "type": "string"},
|
{"name": "high", "type": "float"},
|
||||||
{"name": "href", "type": "string"},
|
{"name": "href", "type": "string"},
|
||||||
{"name": "hreflang", "type": "string"},
|
{"name": "hreflang", "type": "string"},
|
||||||
{"name": "http-equiv", "type": "string"},
|
{"name": "http-equiv", "type": "string"},
|
||||||
@ -59,20 +59,20 @@
|
|||||||
{"name": "language", "type": "string"},
|
{"name": "language", "type": "string"},
|
||||||
{"name": "list", "type": "string"},
|
{"name": "list", "type": "string"},
|
||||||
{"name": "loop", "type": "bool"},
|
{"name": "loop", "type": "bool"},
|
||||||
{"name": "low", "type": "string"},
|
{"name": "low", "type": "float"},
|
||||||
{"name": "manifest", "type": "string"},
|
{"name": "manifest", "type": "string"},
|
||||||
{"name": "max", "type": "string"},
|
{"name": "max", "type": "float"},
|
||||||
{"name": "maxlength", "type": "int"},
|
{"name": "maxlength", "type": "int"},
|
||||||
{"name": "media", "type": "string"},
|
{"name": "media", "type": "string"},
|
||||||
{"name": "method", "type": "string"},
|
{"name": "method", "type": "string"},
|
||||||
{"name": "min", "type": "string"},
|
{"name": "min", "type": "float"},
|
||||||
{"name": "minlength", "type": "int"},
|
{"name": "minlength", "type": "int"},
|
||||||
{"name": "multiple", "type": "bool"},
|
{"name": "multiple", "type": "bool"},
|
||||||
{"name": "muted", "type": "bool"},
|
{"name": "muted", "type": "bool"},
|
||||||
{"name": "name", "type": "string"},
|
{"name": "name", "type": "string"},
|
||||||
{"name": "novalidate", "type": "bool"},
|
{"name": "novalidate", "type": "bool"},
|
||||||
{"name": "open", "type": "bool"},
|
{"name": "open", "type": "bool"},
|
||||||
{"name": "optimum", "type": "string"},
|
{"name": "optimum", "type": "float"},
|
||||||
{"name": "pattern", "type": "string"},
|
{"name": "pattern", "type": "string"},
|
||||||
{"name": "ping", "type": "string"},
|
{"name": "ping", "type": "string"},
|
||||||
{"name": "placeholder", "type": "string"},
|
{"name": "placeholder", "type": "string"},
|
||||||
|
@ -182,18 +182,14 @@ func Example() {
|
|||||||
userInput := "<script>launchMissiles();</script>"
|
userInput := "<script>launchMissiles();</script>"
|
||||||
|
|
||||||
document := he.Html()(
|
document := he.Html()(
|
||||||
he.Head()(
|
|
||||||
he.Meta(ha.HttpEquiv("refresh"), ha.Content("5")),
|
|
||||||
),
|
|
||||||
he.Body()(
|
he.Body()(
|
||||||
he.Div()(
|
he.Img(ha.Src("./photo.jpg")),
|
||||||
he.Img(ha.Src("./me.jpg"), ha.Id("profile-photo")),
|
hatmill.Text(html.EscapeString(userInput)),
|
||||||
hatmill.Text(html.EscapeString(userInput)),
|
he.Div(ha.Disabled(), ha.CustomData("coolness", "awesome"))(),
|
||||||
he.Div(ha.Disabled(), ha.CustomData("coolness", "awesome"))(),
|
he.Textarea(ha.Rows(25))(),
|
||||||
he.Textarea(ha.Height(25))(),
|
he.Meter(ha.Min(-1.3), ha.Max(5.5E12))(),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
hatmill.WriteDocument(os.Stdout, document)
|
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"},
|
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.
|
// Def represents a top-level definition and its required imports.
|
||||||
|
Loading…
Reference in New Issue
Block a user