Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
petaki committed Oct 11, 2024
2 parents ca88bf4 + f748a70 commit be28424
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions inertia.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (

// Inertia type.
type Inertia struct {
url string
rootTemplate string
version string
sharedProps map[string]interface{}
sharedFuncMap template.FuncMap
templateFS fs.FS
ssrURL string
ssrClient *http.Client
url string
rootTemplate string
version string
sharedProps map[string]interface{}
sharedFuncMap template.FuncMap
parsedTemplate *template.Template
templateFS fs.FS
ssrURL string
ssrClient *http.Client
}

// New function.
Expand Down Expand Up @@ -231,13 +232,30 @@ func (i *Inertia) isInertiaRequest(r *http.Request) bool {
}

func (i *Inertia) createRootTemplate() (*template.Template, error) {
if i.parsedTemplate != nil {
return i.parsedTemplate, nil
}

ts := template.New(filepath.Base(i.rootTemplate)).Funcs(i.sharedFuncMap)

var tpl *template.Template
var err error

if i.templateFS != nil {
return ts.ParseFS(i.templateFS, i.rootTemplate)
tpl, err = ts.ParseFS(i.templateFS, i.rootTemplate)
if err != nil {
return nil, err
}
} else {
tpl, err = ts.ParseFiles(i.rootTemplate)
if err != nil {
return nil, err
}
}

return ts.ParseFiles(i.rootTemplate)
i.parsedTemplate = tpl

return i.parsedTemplate, nil
}

func (i *Inertia) ssr(page *Page) (*Ssr, error) {
Expand Down

0 comments on commit be28424

Please sign in to comment.