Skip to content
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

Merged
merged 5 commits into from
Mar 12, 2024
Merged

Conversation

LiusCraft
Copy link
Contributor

@LiusCraft LiusCraft commented Feb 1, 2024

Task: Support nest html template with ParseFiles

default: Template loaded on first access to HTML(pattern: *_yap.html)

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) {
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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:

  1. /home_yap.html
  2. /user/info_yap.html
  3. /user/edit_yap.html
  4. /article/list_yap.html
  5. /article/view_yap.html
  6. /layout/consumer_yap.html
  7. /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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xushiwei PTAL

@LiusCraft
Copy link
Contributor Author

@xushiwei PTAL

<head>
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.79%. Comparing base (f75b3de) to head (b2081d7).
Report is 23 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

"Id": ctx.Param("id"),
})
})
y.Run(":8888")
Copy link

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:

@xushiwei xushiwei merged commit c9d0020 into goplus:main Mar 12, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants