Exemplo n.º 1
0
//Adds an attribute name and value.
func (this Attrs) Add(field string, value string) {
	converted, ok := common.StringToAttribute(field)
	if !ok {
		panic("Field " + field + "is not a valid attribute") // TODO: fix this with proper error handling?
	}
	this.add(converted, value)
}
Exemplo n.º 2
0
func appendAttrs(list ast.StmtList, attrs Attrs) ast.StmtList {
	for _, name := range attrs.SortedNames() {
		attribute, ok := common.StringToAttribute(name)
		if !ok {
			// TODO fix this
		}

		value := attrs[attribute]
		// TODO: Fix This
		// Test fails if the below is uncommented out.
		// The problem however, lies with the test, as in the documentation, all string values must be enclosed in double quotes

		// var value string
		// if attribute.TakesColor() || attribute.TakesString() {
		// 	value = fmt.Sprintf("%q", attrs[attribute])
		// } else  {
		// 	value = attrs[attribute]
		// }

		stmt := &ast.Attr{
			Field: ast.Id(name),
			Value: ast.Id(value),
		}
		list = append(list, stmt)
	}
	return list
}
Exemplo n.º 3
0
func (this *stmtVisitor) attr(stmt *ast.Attr) ast.Visitor {
	attribute, ok := common.StringToAttribute(stmt.Field.String())
	if !ok {
		// TODO: fix this
	}
	this.g.AddAttr(this.graphName, attribute.String(), stmt.Value.String())
	return this
}
Exemplo n.º 4
0
func fromStringMap(input map[string]string) (Attrs, error) {
	attrs := NewAttrs()
	for k, v := range input {
		attr, ok := common.StringToAttribute(k)
		if !ok {
			err := errors.New("Attribute " + k + " is not valid")
			return attrs, err
		}
		attrs[attr] = v
	}
	return attrs, nil
}