Example #1
0
func WritePython(data *Data) {
	MakeLibraryDir("python")
	RunTemplate := ChooseTemplate("python")

	RunTemplate("gitignore", ".gitignore", data)
	RunTemplate("setup.py", "setup.py", data)
	RunTemplate("readme.md", "README.md", data)

	MakeDir(inflect.Underscore(data.Pkg.Name))
	RunTemplate("lib/__init__.py", "__init__.py", data)
	RunTemplate("lib/client.py", "client.py", data)

	MakeDir("error")
	RunTemplate("lib/error/__init__.py", "__init__.py", data)
	RunTemplate("lib/error/client_error.py", "client_error.py", data)
	MoveDir("..")

	MakeDir("http_client")
	RunTemplate("lib/http_client/__init__.py", "__init__.py", data)
	RunTemplate("lib/http_client/auth_handler.py", "auth_handler.py", data)
	RunTemplate("lib/http_client/error_handler.py", "error_handler.py", data)
	RunTemplate("lib/http_client/request_handler.py", "request_handler.py", data)
	RunTemplate("lib/http_client/response.py", "response.py", data)
	RunTemplate("lib/http_client/response_handler.py", "response_handler.py", data)
	MoveDir("..")

	MakeDir("api")
	RunTemplate("lib/api/__init__.py", "__init__.py", data)

	for _, v := range data.Api.Classes {
		data.Active = &v
		RunTemplate("lib/api/api.py", inflect.Underscore(v.Name)+".py", data)
		data.Active = nil
	}
}
Example #2
0
func WritePython(data *Data) {
	MakeLibraryDir("python")
	RunTemplate := ChooseTemplate("python")

	RunTemplate("gitignore", ".gitignore", data)
	RunTemplate("setup.py", "setup.py", data)
	RunTemplate("readme.md", "README.md", data)

	MakeDir(inflect.Underscore(data.Pkg.Name))
	RunTemplate("lib/__init__.py", "__init__.py", data)
	RunTemplate("lib/client.py", "client.py", data)

	MakeDir("error")
	RunTemplate("lib/error/__init__.py", "__init__.py", data)
	RunTemplate("lib/error/client_error.py", "client_error.py", data)
	MoveDir("..")

	MakeDir("http_client")
	RunTemplate("lib/http_client/__init__.py", "__init__.py", data)
	RunTemplate("lib/http_client/auth_handler.py", "auth_handler.py", data)
	RunTemplate("lib/http_client/error_handler.py", "error_handler.py", data)
	RunTemplate("lib/http_client/request_handler.py", "request_handler.py", data)
	RunTemplate("lib/http_client/response.py", "response.py", data)
	RunTemplate("lib/http_client/response_handler.py", "response_handler.py", data)
	MoveDir("..")

	MakeDir("api")
	RunTemplate("lib/api/__init__.py", "__init__.py", data)

	for k, v := range data.Api["class"].(map[string]interface{}) {
		data.Api["active"] = ActiveClassInfo(k, v)
		RunTemplate("lib/api/api.py", inflect.Underscore(k)+".py", data)
		delete(data.Api, "active")
	}
}
func CreateIndexByField(v reflect.StructField) *Index {
	keyName := inflect.Underscore(v.Name)
	typeName := v.Type.Name()
	index := &Index{Name: keyName}
	if typeName == "IUniqueKeys" {
		index.IsUnique = true
	}
	tags := strings.Split(v.Tag.Get("columns"), ",")

	for i, _ := range tags {
		tags[i] = inflect.Underscore(tags[i])
	}
	index.ColumnNames = tags
	return index
}
Example #4
0
// gets a resource name from a controller name, returning an error if the controller name is invalid.
// an example input -> output is "ExampleController" -> "example"
// an error would occur from input "Example"
func getResourceName(controllerName string) (string, error) {
	if !strings.HasSuffix(controllerName, "Controller") {
		return "", errors.New("goroutes: controller name must have suffix \"Controller\"")
	}
	controllerName = controllerName[:len(controllerName)-len("Controller")]
	controllerNameUnderscore := inflect.Underscore(controllerName)
	if controllerNameUnderscore == "new" || controllerNameUnderscore == "edit" || !controllerNameValidator.MatchString(controllerName) {
		return "", errors.New("goroutes: controller name must not be NewController, EditController or include invalid characters")
	}
	return controllerNameUnderscore, nil
}
Example #5
0
// SanitizeDBFieldName is exported for testing purposes
func SanitizeDBFieldName(name string) string {
	name = inflect.Underscore(name)
	if strings.HasSuffix(name, "_i_d") {
		name = strings.TrimSuffix(name, "_i_d")
		name = name + "_id"
	}
	if name == "i_d" {
		name = "id"

	}
	return name
}
Example #6
0
func WriteRuby(data *Data) {
	MakeLibraryDir("ruby")
	RunTemplate := ChooseTemplate("ruby")

	name := data.Pkg["name"].(string)

	RunTemplate("gitignore", ".gitignore", data)
	RunTemplate("gemspec", data.Pkg["package"].(string)+".gemspec", data)
	RunTemplate("readme.md", "README.md", data)

	MakeDir("lib")
	RunTemplate("lib/name.rb", data.Pkg["package"].(string)+".rb", data)

	MakeDir(inflect.Underscore(name))
	RunTemplate("lib/client.rb", "client.rb", data)
	RunTemplate("lib/http_client.rb", "http_client.rb", data)
	RunTemplate("lib/error.rb", "error.rb", data)

	MakeDir("error")
	RunTemplate("lib/error/client_error.rb", "client_error.rb", data)
	MoveDir("..")

	MakeDir("http_client")
	RunTemplate("lib/http_client/auth_handler.rb", "auth_handler.rb", data)
	RunTemplate("lib/http_client/error_handler.rb", "error_handler.rb", data)
	RunTemplate("lib/http_client/request_handler.rb", "request_handler.rb", data)
	RunTemplate("lib/http_client/response.rb", "response.rb", data)
	RunTemplate("lib/http_client/response_handler.rb", "response_handler.rb", data)
	MoveDir("..")

	MakeDir("api")

	for k, v := range data.Api["class"].(map[string]interface{}) {
		data.Api["active"] = ActiveClassInfo(k, v)
		RunTemplate("lib/api/api.rb", inflect.Underscore(k)+".rb", data)
		delete(data.Api, "active")
	}
}
Example #7
0
func WriteRuby(data *Data) {
	MakeLibraryDir("ruby")
	RunTemplate := ChooseTemplate("ruby")

	RunTemplate("gitignore", ".gitignore", data)
	RunTemplate("gemspec", data.Pkg.Package+".gemspec", data)
	RunTemplate("readme.md", "README.md", data)

	MakeDir("lib")
	RunTemplate("lib/name.rb", data.Pkg.Package+".rb", data)

	MakeDir(inflect.Underscore(data.Pkg.Name))
	RunTemplate("lib/client.rb", "client.rb", data)
	RunTemplate("lib/http_client.rb", "http_client.rb", data)
	RunTemplate("lib/error.rb", "error.rb", data)
	RunTemplate("lib/version.rb", "version.rb", data)

	MakeDir("error")
	RunTemplate("lib/error/client_error.rb", "client_error.rb", data)
	MoveDir("..")

	MakeDir("http_client")
	RunTemplate("lib/http_client/auth_handler.rb", "auth_handler.rb", data)
	RunTemplate("lib/http_client/error_handler.rb", "error_handler.rb", data)
	RunTemplate("lib/http_client/request_handler.rb", "request_handler.rb", data)
	RunTemplate("lib/http_client/response.rb", "response.rb", data)
	RunTemplate("lib/http_client/response_handler.rb", "response_handler.rb", data)
	MoveDir("..")

	MakeDir("api")

	for _, v := range data.Api.Classes {
		data.Active = &v
		RunTemplate("lib/api/api.rb", inflect.Underscore(v.Name)+".rb", data)
		data.Active = nil
	}
}
Example #8
0
func WriteNode(data *Data) {
	MakeLibraryDir("node")
	RunTemplate := ChooseTemplate("node")

	RunTemplate("gitignore", ".gitignore", data)
	RunTemplate("package.json", "package.json", data)
	RunTemplate("readme.md", "README.md", data)

	MakeDir("lib")
	RunTemplate("lib/index.js", "index.js", data)

	MakeDir(inflect.Underscore(data.Pkg.Name))
	RunTemplate("lib/client.js", "client.js", data)

	MakeDir("error")
	RunTemplate("lib/error/index.js", "index.js", data)
	RunTemplate("lib/error/client_error.js", "client_error.js", data)
	MoveDir("..")

	MakeDir("http_client")
	RunTemplate("lib/http_client/index.js", "index.js", data)
	RunTemplate("lib/http_client/auth_handler.js", "auth_handler.js", data)
	RunTemplate("lib/http_client/error_handler.js", "error_handler.js", data)
	RunTemplate("lib/http_client/request_handler.js", "request_handler.js", data)
	RunTemplate("lib/http_client/response.js", "response.js", data)
	RunTemplate("lib/http_client/response_handler.js", "response_handler.js", data)
	MoveDir("..")

	MakeDir("api")

	for k, v := range data.Api["class"].(map[string]interface{}) {
		data.Api["active"] = ActiveClassInfo(k, v)
		RunTemplate("lib/api/api.js", inflect.Underscore(k)+".js", data)
		delete(data.Api, "active")
	}
}
Example #9
0
func WriteNode(data *Data) {
	MakeLibraryDir("node")
	RunTemplate := ChooseTemplate("node")

	RunTemplate("gitignore", ".gitignore", data)
	RunTemplate("package.json", "package.json", data)
	RunTemplate("readme.md", "README.md", data)

	MakeDir("lib")
	RunTemplate("lib/index.js", "index.js", data)

	MakeDir(inflect.Underscore(data.Pkg.Name))
	RunTemplate("lib/client.js", "client.js", data)

	MakeDir("error")
	RunTemplate("lib/error/index.js", "index.js", data)
	RunTemplate("lib/error/client_error.js", "client_error.js", data)
	MoveDir("..")

	MakeDir("http_client")
	RunTemplate("lib/http_client/index.js", "index.js", data)
	RunTemplate("lib/http_client/auth_handler.js", "auth_handler.js", data)
	RunTemplate("lib/http_client/error_handler.js", "error_handler.js", data)
	RunTemplate("lib/http_client/request_handler.js", "request_handler.js", data)
	RunTemplate("lib/http_client/response.js", "response.js", data)
	RunTemplate("lib/http_client/response_handler.js", "response_handler.js", data)
	MoveDir("..")

	MakeDir("api")

	for _, v := range data.Api.Classes {
		data.Active = &v
		RunTemplate("lib/api/api.js", inflect.Underscore(v.Name)+".js", data)
		data.Active = nil
	}
}
Example #10
0
func collectFields(fields map[string]string, struc *types.Struct) {
	// TODO:
	for i := 0; i < struc.NumFields(); i++ {
		f, tag := struc.Field(i), struc.Tag(i)

		switch {
		case f.Anonymous():
			if named, ok := f.Type().(*types.Named); ok {
				if struc_, ok := named.Underlying().(*types.Struct); ok {
					collectFields(fields, struc_)
				}
			}

		case strings.Contains(tag, `pretty:""`):
			fields[f.Name()] = inflect.Underscore(f.Name())
		}
	}
}
Example #11
0
File: main.go Project: dylanmei/rsc
// Generate API metadata, drives the metadata writer.
func generateAngular(descriptor *gen.ApiDescriptor, pkgDir string) ([]string, error) {
	var files []string
	for _, name := range descriptor.ResourceNames {
		res := descriptor.Resources[name]
		codegen := path.Join(pkgDir, inflect.Underscore(name)+".js")
		f, err := os.Create(codegen)
		if err != nil {
			return files, err
		}
		c, err := writers.NewAngularWriter()
		if err != nil {
			return files, err
		}
		kingpin.FatalIfError(c.WriteResource(res, f), "")
		f.Close()
		files = append(files, codegen)
	}
	return files, nil
}
func CreateColumnByField(value interface{}, field reflect.StructField) *Column {
	column := NewColumn(inflect.Underscore(field.Name)).As(value)
	if field.Tag.Get("pk") == "true" {
		column.PrimaryKey()
	}
	if field.Tag.Get("unique") == "true" {
		column.Unique()
	}
	if field.Tag.Get("autoincrement") == "true" {
		column.AutoIncrement()
	}
	if sizeVal := field.Tag.Get("size"); sizeVal != "" {
		n, err := strconv.ParseUint(sizeVal, 10, 64)
		if err != nil {
			panic(err)
		}
		column.Size(n)
	}
	return column
}
Example #13
0
// FieldToColumn converts a Go struct field name to a database table column
// name. It is mainly CamelCase -> snake_case, with some special cases, and is
// overridable.
func FieldToColumn(field string) string {
	if len(field) < 4 {
		return strings.ToLower(field)
	}
	return inflect.Underscore(field)
}
Example #14
0
// Underscore returns the field name as a lowercase string in snake case
func (f *RelationalFieldDefinition) Underscore() string {
	return inflect.Underscore(f.Name)
}
Example #15
0
// TableName returns the TableName of the struct.
func (f RelationalModelDefinition) TableName() string {
	return inflect.Underscore(inflect.Pluralize(f.ModelName))
}
Example #16
0
func (job *GenStringJob) Filenames() (string, string) {
	return "gen_string_job.tmpl", inflect.Underscore(job.Name) + "_string.go"
}
Example #17
0
// lowerUnderScoreCase returns upper & underscore case version of a word
// with all characters changed to upper case
func upperUnderScoreCase(s string) string {
	return strings.ToUpper(inflect.Underscore(s))
}
Example #18
0
// lowerUnderScoreCase returns lower & underscore case version of a word
func lowerUnderScoreCase(s string) string {
	return strings.ToLower(inflect.Underscore(s))
}