當前位置: 首頁>>代碼示例>>Golang>>正文


Golang typewriter.Type類代碼示例

本文整理匯總了Golang中github.com/clipperhouse/typewriter.Type的典型用法代碼示例。如果您正苦於以下問題:Golang Type類的具體用法?Golang Type怎麽用?Golang Type使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Type類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Write

func (g *ModelGenerator) Write(writer io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(g)

	if !found {
		return nil
	}

	// Fetch core template
	coreTemplates := templates.Where(func(t *typewriter.Template) bool {
		if t != nil && t.Name == "core" {
			return true
		}

		return false
	})
	if len(coreTemplates) == 0 {
		return errors.New("Unable to find 'core' template")
	}
	coreTemplate, err := coreTemplates[0].Parse()
	if err != nil {
		return errors.New("Unable to parse 'core' template")
	}

	// Fetch relation template
	relationTemplates := templates.Where(func(t *typewriter.Template) bool {
		if t != nil && t.Name == "relation" {
			return true
		}

		return false
	})
	if len(relationTemplates) == 0 {
		return errors.New("Unable to find 'relation' template")
	}
	relationTemplate, err := relationTemplates[0].Parse()
	if err != nil {
		return errors.New("Unable to parse 'relation' template")
	}

	cValues := coreValues{ModelClassName: t.Name}
	if err := coreTemplate.Execute(writer, cValues); err != nil {
		return err
	}

	for _, relation := range tag.Values {
		templateValues := relationValues{}

		templateValues.ModelClassName = t.Name
		templateValues.RelationIdentifierName = fmt.Sprintf("%vIdentifier", strings.Title(relation.Name))
		templateValues.RelationName = relation.Name
		templateValues.RelationClassName = strings.Title(relation.Name)

		if err := relationTemplate.Execute(writer, templateValues); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:sparkymat,項目名稱:clay,代碼行數:59,代碼來源:model_generator.go

示例2: Write

func (sw *SequenceGeneratorWriter) Write(w io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(sw)
	if !found {
		return nil
	}

	if _, err := w.Write([]byte(license)); err != nil {
		return err
	}

	generatorName := t.Name
	for _, v := range tag.Values {
		switch v.Name {
		case "Iterator":
			if len(v.TypeParameters) == 0 {
				return errors.New("No type parameters for Iterate tag")
			}
			typeParameters := v.TypeParameters
			v.TypeParameters = make([]typewriter.Type, 0)

			tmpl, err := templates.ByTagValue(t, v)
			if err != nil {
				return err
			}
			for _, typ := range typeParameters {
				typeName := typ.Pointer.String() + typ.Name
				if typeName == "*bigInt" {
					typeName = "*big.Int"
				} else if typeName == "*bigRat" {
					typeName = "*bigRat"
				}
				typeTitle := typeTitle[typeName]
				if typeTitle == "" {
					return fmt.Errorf("Unexpected type: %s", typeName)
				}
				tmpl.Execute(w, generatorModel{generatorName, typeName, typeTitle})
			}
			return nil
		default:
			return fmt.Errorf("Unrecognized tag: %s", v.Name)
		}
	}

	return nil
}
開發者ID:fernandokm,項目名稱:sequences,代碼行數:45,代碼來源:sequenceGeneratorWriter.go

示例3: Write

func (tw *writer) Write(w io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(tw)

	if !found {
		return nil
	}

	header := "// DO NOT MODIFY. Auto-generated code."
	if _, err := w.Write([]byte(header)); err != nil {
		return err
	}

	tmpl, err := templates.ByTag(t, tag)
	if err != nil {
		return err
	}

	if err := tmpl.Execute(w, t); err != nil {
		return err
	}
	return nil
}
開發者ID:svett,項目名稱:gen,代碼行數:22,代碼來源:writer.go

示例4: Write

func (sw *SymTableWriter) Write(w io.Writer, t typewriter.Type) error {
	tag, found := t.FindTag(sw)

	if !found {
		// nothing to be done
		return nil
	}

	log.Printf("Found tag %+v\n", tag)

	license := `// SymTableWriter is a modification of https://github.com/deckarep/golang-set
// The MIT License (MIT)
// Copyright (c) 2015 Yo-An Lin ([email protected])
`
	if _, err := w.Write([]byte(license)); err != nil {
		return err
	}

	log.Printf("Finding template by tag %+v\n", tag)
	tmpl, err := templates.ByTag(t, tag)
	if err != nil {
		return err
	}

	m := model{
		Type:          t,
		Name:          t.Name,
		TypeParameter: tag.Values[0].TypeParameters[0],
		Tag:           tag,
	}

	log.Println("Rendering templates")
	if err := tmpl.Execute(w, m); err != nil {
		return err
	}

	log.Println("Done!")
	return nil
}
開發者ID:se77en,項目名稱:c6,代碼行數:39,代碼來源:writer.go

示例5: Write

func (cw *ContainerWriter) Write(w io.Writer, typ typewriter.Type) error {
	containerTag, found := typ.FindTag(cw)

	if !found {
		return nil
	}

	if _, err := w.Write([]byte(license)); err != nil {
		return err
	}

	for _, tagValue := range containerTag.Values {
		if tmpl, err := templates.ByTagValue(typ, tagValue); err != nil {
			return err
		} else if m, err := typeAndTagValueToModel(typ, tagValue); err != nil {
			return err
		} else if err := tmpl.Execute(w, *m); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:nickmab,項目名稱:gen,代碼行數:23,代碼來源:containerwriter.go

示例6: Write

func (fw *Writer) Write(w io.Writer, typ typewriter.Type) error {
	tag, found := typ.FindTag(fw)

	if !found {
		return nil
	}

	tmpl, err := templates.ByTag(typ, tag)
	if err != nil {
		return err
	}

	m := model{
		Type:      typ,
		SliceName: SliceName(typ),
	}

	if err := tmpl.Execute(w, m); err != nil {
		return err
	}

	return nil
}
開發者ID:publicgoodsw,項目名稱:flags,代碼行數:23,代碼來源:writer.go

示例7: Write

func (sw *SliceWriter) Write(w io.Writer, typ typewriter.Type) error {
	tag, found := typ.FindTag(sw)

	if !found {
		return nil
	}

	if includeSortImplementation(tag.Values) {
		s := `// Sort implementation is a modification of http://golang.org/pkg/sort/#Sort
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found at http://golang.org/LICENSE.

`
		w.Write([]byte(s))
	}

	// start with the slice template
	tmpl, err := templates.ByTag(typ, tag)

	if err != nil {
		return err
	}

	m := model{
		Type:      typ,
		SliceName: SliceName(typ),
	}

	if err := tmpl.Execute(w, m); err != nil {
		return err
	}

	for _, v := range tag.Values {
		var tp typewriter.Type

		if len(v.TypeParameters) > 0 {
			tp = v.TypeParameters[0]
		}

		m := model{
			Type:          typ,
			SliceName:     SliceName(typ),
			TypeParameter: tp,
			TagValue:      v,
		}

		tmpl, err := templates.ByTagValue(typ, v)

		if err != nil {
			return err
		}

		if err := tmpl.Execute(w, m); err != nil {
			return err
		}
	}

	if includeSortInterface(tag.Values) {
		tmpl, err := sortInterface.Parse()

		if err != nil {
			return err
		}

		if err := tmpl.Execute(w, m); err != nil {
			return err
		}
	}

	if includeSortImplementation(tag.Values) {
		tmpl, err := sortImplementation.Parse()

		if err != nil {
			return err
		}

		if err := tmpl.Execute(w, m); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:clamoriniere1A,項目名稱:sliceP,代碼行數:84,代碼來源:slicewriter.go


注:本文中的github.com/clipperhouse/typewriter.Type類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。