Skip to content

Commit

Permalink
Add template example
Browse files Browse the repository at this point in the history
Signed-off-by: Jingwen Peng <pengsrc@yunify.com>
  • Loading branch information
pengsrc committed Dec 3, 2016
1 parent dac848c commit 203cad5
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions templates/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi there, this is an example read me file!
42 changes: 42 additions & 0 deletions templates/example/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"template": {
"format": "Go"
},
"output": {
"file_naming": {
"style": "snake_case",
"extension": ".go"
}
},
"template_files": {
"shared": {
"file_path": "shared.tmpl"
},
"service": {
"file_path": "service.tmpl",
"output_file_naming": {
"prefix": "qs_",
"suffix": "_service"
}
},
"sub_service": {
"file_path": "sub_service.tmpl",
"output_file_naming": {
"prefix": "qs_",
"suffix": "_sub_service"
}
},
"types": {
"file_path": "types.tmpl",
"output_file_naming": {
"prefix": "qs_",
"suffix": ""
}
}
},
"supporting_files": [
"utils.go",
"utils_test.go",
"README.md"
]
}
67 changes: 67 additions & 0 deletions templates/example/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Manifest file for a bunch of templates.
# The manifest file can be in JSON or YAML format.

# Template configurations
template:
# Template files format
# Validate formats: Go
# Default: Go
format: Go

# Output
output:
file_naming:
# Naming style to use in the output file.
# Available styles: snake_case, camel_case
# Default: snake_case
# Example: bucket_acl (snake_case), BucketACL (camel_case)
style: snake_case
extension: .go

# Template files to read and execute.
# Currently, there's are three of them.
template_files:
# Shared template file.
# This file will be concatenated with each other template to provide shared
# nested template definitions.
shared:
# Relative file path to load the shared template file.
# Default: shared.tmpl
file_path: shared.tmpl

# Service template file.
# In this case, a file named "qs_qingstor_service.go" will be generated.
service:
# Relative file path to load service template file.
# Default: service.tmpl
file_path: service.tmpl
# Naming options for output file.
output_file_naming:
prefix: qs_
suffix: _service

# Service template file.
# In this case, multiple files named like "qs_bucket_sub_service.go"
# will be generated.
sub_service:
# Relative file path to load sub service template file.
# Default: sub_service.tmpl
file_path: sub_service.tmpl
output_file_naming:
prefix: qs_
suffix: _sub_service
# Types template file.
# In this case, a file named "qs_types.go" will be generated.
types:
# Relative file path to load types template file.
# Default: types.tmpl
file_path: types.tmpl
output_file_naming:
prefix: qs_
suffix:

# Supporting files to copy directly.
supporting_files:
- utils.go
- utils_test.go
- README.md
4 changes: 4 additions & 0 deletions templates/example/service.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{$service := .Data.Service}}

// {{$service.Name | camelCase}}
// API Version {{$service.APIVersion}}
1 change: 1 addition & 0 deletions templates/example/shared.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Shared Parts
4 changes: 4 additions & 0 deletions templates/example/sub_service.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{$service := .Data.Service}}
{{$subService := index .Data.SubServices .CurrentSubServiceID}}

// {{$subService.Name | camelCase}}
5 changes: 5 additions & 0 deletions templates/example/types.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{$customizedTypes := .Data.CustomizedTypes}}

{{range $_, $customizedType := $customizedTypes}}
// {{$customizedType | camelCase}}
{{end}}
5 changes: 5 additions & 0 deletions templates/example/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example

func Utils() string {
return "Hi there, this is an example code file!"
}
12 changes: 12 additions & 0 deletions templates/example/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package example

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestUtils(t *testing.T) {
assert.True(t, strings.HasPrefix(Utils(), "Hi there"))
}

0 comments on commit 203cad5

Please sign in to comment.