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 | |
| parent | 3036abbc4af1e85e3f3d473c9facdeefb94916c7 (diff) | |
| download | lain-4c25ae85823466edd3ad2ed58781240ce3964cdf.tar.xz lain-4c25ae85823466edd3ad2ed58781240ce3964cdf.zip | |
static tag
| -rw-r--r-- | tags/static.go | 29 | ||||
| -rw-r--r-- | tags/tags.go | 1 |
2 files changed, 30 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 +} diff --git a/tags/tags.go b/tags/tags.go index 9a20b55..6229c20 100644 --- a/tags/tags.go +++ b/tags/tags.go @@ -15,6 +15,7 @@ func Initialize() { tags := []templateTag{ {"url", url}, + {"static", static}, } for _, t := range tags { |
