Skip to content

Commit

Permalink
Merge pull request #61 from mterwill/collapse
Browse files Browse the repository at this point in the history
Adjust template to auto-collapse generated code in GitHub
  • Loading branch information
sagikazarmark committed Jun 29, 2021
2 parents b40d2f8 + f392a03 commit bb5a2f3
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- Adjust generated code comment to auto-collapse in GitHub diffs

## [0.7.2] - 2021-05-12

Expand Down
2 changes: 1 addition & 1 deletion example/generated/Twitch/Twirp/Example/Haberdasher.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/generated/Twitch/Twirp/Example/TwirpError.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions protoc-gen-twirp_php/internal/gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

const twirpVersion = "v5.3.0"

var globalTemplates = template.Must(template.New("").Funcs(TxtFuncMap()).ParseFS(global.FS(), "*.php"))
var serviceTemplates = template.Must(template.New("").Funcs(TxtFuncMap()).ParseFS(service.FS(), "*.php"))
var globalTemplates = template.Must(template.New("").Funcs(TxtFuncMap()).ParseFS(global.FS(), "*.php.tmpl"))
var serviceTemplates = template.Must(template.New("").Funcs(TxtFuncMap()).ParseFS(service.FS(), "*.php.tmpl"))

type serviceFileData struct {
File *protogen.File
Expand Down Expand Up @@ -43,6 +43,7 @@ func Generate(plugin *protogen.Plugin, version string) error {
php.ServiceName(file, svc),
strings.Replace(tpl.Name(), "_Service_", "", -1),
)
fileName = strings.TrimSuffix(fileName, ".tmpl")

generatedFile := plugin.NewGeneratedFile(fileName, "")

Expand All @@ -64,6 +65,7 @@ func Generate(plugin *protogen.Plugin, version string) error {
for namespace := range namespaces {
for _, tpl := range globalTemplates.Templates() {
fileName := fmt.Sprintf("%s/%s", php.PathFromNamespace(namespace), tpl.Name())
fileName = strings.TrimSuffix(fileName, ".tmpl")

generatedFile := plugin.NewGeneratedFile(fileName, "")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
# Generated by the protocol buffer compiler (protoc-gen-twirp_php {{ .Version }}). DO NOT EDIT!
# Generated by the protocol buffer compiler. DO NOT EDIT! (protoc-gen-twirp_php {{ .Version }})

declare(strict_types=1);

Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-twirp_php/templates/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/fs"
)

//go:embed *.php
//go:embed *.php.tmpl
var files embed.FS

// FS returns a filesystem with the templates.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
# Generated by the protocol buffer compiler (protoc-gen-twirp_php {{ .Version }}). DO NOT EDIT!
# Generated by the protocol buffer compiler. DO NOT EDIT! (protoc-gen-twirp_php {{ .Version }})
# source: {{ .File.Proto.Name }}

declare(strict_types=1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
# Generated by the protocol buffer compiler (protoc-gen-twirp_php {{ .Version }}). DO NOT EDIT!
# Generated by the protocol buffer compiler. DO NOT EDIT! (protoc-gen-twirp_php {{ .Version }})
# source: {{ .File.Proto.Name }}

declare(strict_types=1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
# Generated by the protocol buffer compiler (protoc-gen-twirp_php {{ .Version }}). DO NOT EDIT!
# Generated by the protocol buffer compiler. DO NOT EDIT! (protoc-gen-twirp_php {{ .Version }})
# source: {{ .File.Proto.Name }}

declare(strict_types=1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
# Generated by the protocol buffer compiler (protoc-gen-twirp_php {{ .Version }}). DO NOT EDIT!
# Generated by the protocol buffer compiler. DO NOT EDIT! (protoc-gen-twirp_php {{ .Version }})
# source: {{ .File.Proto.Name }}

declare(strict_types=1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
# Generated by the protocol buffer compiler (protoc-gen-twirp_php {{ .Version }}). DO NOT EDIT!
# Generated by the protocol buffer compiler. DO NOT EDIT! (protoc-gen-twirp_php {{ .Version }})
# source: {{ .File.Proto.Name }}

declare(strict_types=1);
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-twirp_php/templates/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/fs"
)

//go:embed *.php
//go:embed *.php.tmpl
var files embed.FS

// FS returns a filesystem with the templates.
Expand Down

0 comments on commit bb5a2f3

Please sign in to comment.