-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support nested templates #49
Conversation
classfile.go
Outdated
@@ -82,6 +82,14 @@ func (p *App) Static__2(pattern string, fs http.FileSystem, allowRedirect ...boo | |||
p.StaticHttp(pattern, fs, allowRedirect...) | |||
} | |||
|
|||
// load go templates | |||
func (p *App) LoadTemplate(pattern ...string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want users to load templates manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users do not need to manually load, but they can choose to use this function to change pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.Scene:
complex structured projects, such as:
- /home_yap.html
- /user/info_yap.html
- /user/edit_yap.html
- /article/list_yap.html
- /article/view_yap.html
- /layout/consumer_yap.html
- /layout/admin_yap.html
The template structure of the user is relatively complex, so the default loading scheme is not what the user wants. Therefore, the user can set the pattern by using this function
LoadTempalte("*_yap. html", "/**/*_yap. html")
or loading all .templ
(custom file)
LoadTemplate("*.templ", "/**/*.templ")
2.Other framework approaches
This feature is supported by mains/tream frameworks such as go template and gin themselves
So it is indispensable
go template: https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/text/template/helper.go;l=138
gin: https://github.com/gin-gonic/gin/blob/v1.9.1/gin.go#L252
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xushiwei PTAL
d3fe721
to
86cff4d
Compare
@xushiwei PTAL |
demo/blog/yap/article_yap.html
Outdated
<head> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't change existed demo. Add new demo instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
template.go
Outdated
@@ -29,11 +33,16 @@ import ( | |||
// as unexported by all other clients. | |||
type Template struct { | |||
*template.Template | |||
// yap fs directory | |||
fs fs.FS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why template should have a fs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #49 +/- ##
=======================================
Coverage 89.79% 89.79%
=======================================
Files 10 10
Lines 98 98
=======================================
Hits 88 88
Misses 10 10 ☔ View full report in Codecov by Sentry. |
"Id": ctx.Param("id"), | ||
}) | ||
}) | ||
y.Run(":8888") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golangci-lint] Error return value of y.Run
is not checked (errcheck)
If you have any questions about this comment, feel free to raise an issue here:
Task: Support nest html template with ParseFiles
default: Template loaded on first access to HTML(pattern: *_yap.html)