예제 #1
0
파일: util.go 프로젝트: subosito/nexmo
func StructToMap(it interface{}) url.Values {
	un.BoolFlag = []string{"0", "1"}

	val := un.StructToMap(it)

	// parameterize key names
	for k, v := range val {
		n := inflect.Dasherize(k)

		if k != n {
			val.Del(k)
			val[n] = v
		}
	}

	return val
}
예제 #2
0
func renderv8(o *v8.Object, format string) string {
	var s string
	if format == "html" {
		switch o.GetProperty("nodeType").ToInteger() {
		case 1:
			parts := []string{o.GetProperty("tagName").ToString()}

			attributes := o.GetProperty("attributes").ToObject()
			attributeNames := attributes.GetPropertyNames()
			if attributeNames.Length() > 0 {
				for x := 0; x < attributeNames.Length(); x++ {
					key := attributeNames.GetElement(x).ToString()
					k := attributes.GetProperty(key)
					if k.IsUndefined() || k.IsNull() {
						continue
					}
					value := attributes.GetProperty(key).ToString()
					parts = append(parts, fmt.Sprintf(`%s="%s"`, key, value))
				}
			}

			style := o.GetProperty("style").ToObject()
			styleNames := style.GetPropertyNames()
			if styleNames.Length() > 0 {
				var styles []string
				for x := 0; x < styleNames.Length(); x++ {
					key := styleNames.GetElement(x).ToString()
					k := style.GetProperty(key)
					if k.IsUndefined() || k.IsNull() {
						continue
					}
					value := style.GetProperty(key).ToString()

					switch {
					case strings.HasPrefix(key, "webkit"):
						key = "-" + inflect.Dasherize(key)
						fallthrough
					default:
						styles = append(styles, fmt.Sprintf(`%s:%s`, key, value))
					case key == "cssText":
						styles = append(styles, value)
					}
				}

				parts = append(parts, fmt.Sprintf(`style="%s"`, strings.Join(styles, ";")))
			}

			s = fmt.Sprintf("<%s>", strings.Join(parts, " "))
			children := o.GetProperty("children").ToArray()
			if children.Length() > 0 {
				for x := 0; x < children.Length(); x++ {
					s += renderv8(children.GetElement(x).ToObject(), format)
				}
			}
			s += fmt.Sprintf("</%s>", parts[0])
		case 3:
			s += o.GetProperty("data").ToString()
		}
	}
	return s
}