Skip to content

Commit

Permalink
refactor: move files
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Aug 19, 2024
1 parent 29c1c27 commit dd6b91a
Show file tree
Hide file tree
Showing 27 changed files with 64 additions and 48 deletions.
2 changes: 1 addition & 1 deletion adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/util"
"github.com/casbin/ent-adapter/ent"
"github.com/casbin/ent-adapter/examples/ent"
"github.com/stretchr/testify/assert"
)

Expand Down
6 changes: 3 additions & 3 deletions template/casbin.tmpl → casbin.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ /* Tell Intellij/GoLand to enable the autocompletion based on the *gen.Graph type. */ }}
{{ /* gotype: entgo.io/ent/entc/gen.Graph */ }}
{{/* Tell Intellij/GoLand to enable the autocompletion based on the *gen.Graph type. */}}
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}

{{ define "casbin" }}

{{ /* Add the base header for the generated file */ }}
{{/* Add the base header for the generated file */}}
{{ $pkg := base $.Config.Package }}
{{ template "header" $ }}

Expand Down
4 changes: 2 additions & 2 deletions ent/casbin.go → examples/ent/casbin.go

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

2 changes: 1 addition & 1 deletion ent/casbinrule.go → examples/ent/casbinrule.go

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

File renamed without changes.

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.

4 changes: 2 additions & 2 deletions ent/casbinrule_query.go → examples/ent/casbinrule_query.go

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.

4 changes: 2 additions & 2 deletions ent/client.go → examples/ent/client.go

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

2 changes: 1 addition & 1 deletion ent/ent.go → examples/ent/ent.go

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

6 changes: 3 additions & 3 deletions ent/enttest/enttest.go → examples/ent/enttest/enttest.go

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

3 changes: 3 additions & 0 deletions examples/ent/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//go:generate go run main.go

package ent
2 changes: 1 addition & 1 deletion ent/hook/hook.go → examples/ent/hook/hook.go

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

4 changes: 2 additions & 2 deletions ent/generate.go → examples/ent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

"entgo.io/ent/entc"
"entgo.io/ent/entc/gen"
"github.com/casbin/ent-adapter/template"
"github.com/casbin/ent-adapter"
)

func main() {
err := entc.Generate("./schema",
&gen.Config{},
entc.Extensions(&template.CasbinExtension{}),
entc.Extensions(&entadapter.CasbinExtension{}),
)
if err != nil {
log.Fatal("running ent codegen:", err)
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ent/mutation.go → examples/ent/mutation.go

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

File renamed without changes.
4 changes: 2 additions & 2 deletions ent/runtime.go → examples/ent/runtime.go

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

2 changes: 1 addition & 1 deletion ent/runtime/runtime.go → examples/ent/runtime/runtime.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package schema

import (
"entgo.io/ent"
"github.com/casbin/ent-adapter/template"
"github.com/casbin/ent-adapter"
)

// CasbinRule holds the schema definition for the CasbinRule entity.
Expand All @@ -12,6 +12,6 @@ type CasbinRule struct {

func (CasbinRule) Mixin() []ent.Mixin {
return []ent.Mixin{
template.CasbinRuleMixin{},
entadapter.CasbinRuleMixin{},
}
}
File renamed without changes.
29 changes: 29 additions & 0 deletions extension.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package entadapter

import (
"fmt"
"path/filepath"
"runtime"

"entgo.io/ent/entc"
"entgo.io/ent/entc/gen"
)

type CasbinExtension struct {
entc.DefaultExtension
}

func (*CasbinExtension) Templates() []*gen.Template {
_, filename, _, ok := runtime.Caller(0)
if !ok {
_ = fmt.Errorf("error retrieving current file path")
}

dir := filepath.Dir(filename)

relativePath := filepath.Join(dir, "casbin.tmpl")

return []*gen.Template{
gen.MustParse(gen.NewTemplate("casbin").ParseFiles(relativePath)),
}
}
2 changes: 1 addition & 1 deletion template/mixin.go → mixin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package template
package entadapter

import (
"entgo.io/ent"
Expand Down
16 changes: 0 additions & 16 deletions template/extension.go

This file was deleted.

0 comments on commit dd6b91a

Please sign in to comment.