diff options
| author | Bobby <[email protected]> | 2025-12-23 10:57:19 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-12-23 10:57:19 +0530 |
| commit | 4c25ae85823466edd3ad2ed58781240ce3964cdf (patch) | |
| tree | c9752dfdbac623bc559f5ef87f89c62f2f830daa /tags/static.go | |
| parent | 3036abbc4af1e85e3f3d473c9facdeefb94916c7 (diff) | |
| download | lain-4c25ae85823466edd3ad2ed58781240ce3964cdf.tar.xz lain-4c25ae85823466edd3ad2ed58781240ce3964cdf.zip | |
static tag
Diffstat (limited to 'tags/static.go')
| -rw-r--r-- | tags/static.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tags/static.go b/tags/static.go new file mode 100644 index 0000000..c11f09d --- /dev/null +++ b/tags/static.go @@ -0,0 +1,29 @@ +package tags + +import ( + "github.com/flosch/pongo2/v6" +) + +func init() { + pongo2.RegisterTag("static", static) +} + +func static(doc *pongo2.Parser, start *pongo2.Token, arguments *pongo2.Parser) (pongo2.INodeTag, *pongo2.Error) { + pathToken := arguments.MatchType(pongo2.TokenString) + if pathToken == nil { + return nil, arguments.Error("Expected a string path", nil) + } + + return &tagStaticNode{ + path: pathToken.Val, + }, nil +} + +type tagStaticNode struct { + path string +} + +func (node *tagStaticNode) Execute(ctx *pongo2.ExecutionContext, writer pongo2.TemplateWriter) *pongo2.Error { + writer.WriteString("/static/" + node.path) + return nil +} |
