{"id":25693727,"url":"https://github.com/zbysir/vpl","last_synced_at":"2025-04-24T06:51:39.441Z","repository":{"id":45360532,"uuid":"305651906","full_name":"zbysir/vpl","owner":"zbysir","description":"Vuejs-syntax like template-engine for Go","archived":false,"fork":false,"pushed_at":"2021-12-18T04:16:34.000Z","size":565,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T08:01:52.225Z","etag":null,"topics":["go","golang","govue","template-engine","vue"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zbysir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-20T09:10:41.000Z","updated_at":"2024-10-27T14:09:02.000Z","dependencies_parsed_at":"2022-09-01T05:21:06.234Z","dependency_job_id":null,"html_url":"https://github.com/zbysir/vpl","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbysir%2Fvpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbysir%2Fvpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbysir%2Fvpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbysir%2Fvpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbysir","download_url":"https://codeload.github.com/zbysir/vpl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250580712,"owners_count":21453531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","govue","template-engine","vue"],"created_at":"2025-02-24T23:47:39.619Z","updated_at":"2025-04-24T06:51:39.421Z","avatar_url":"https://github.com/zbysir.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vpl\n[![Go Report Card](https://goreportcard.com/badge/github.com/zbysir/vpl)](https://goreportcard.com/report/github.com/zbysir/vpl)\n\nVpl is a [Vuejs](https://vuejs.org)-syntax like template-engine for Golang.\n\n- Componentization\n- Powerful template syntax for the modern html\n- Supports Js(Es5) expressions\n- A little faster (I tried my best to optimize :)\n\n## Installation\n```\ngo get github.com/zbysir/vpl\n```\n\n## Getting Started\nWrite the `main.go` file as follows\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"github.com/zbysir/vpl\"\n)\n\nfunc main() {\n\tv := vpl.New()\n\n\terr := v.ComponentTxt(\"app\", `\n\u003c!DOCTYPE html\u003e\n\u003chtml :lang=\"lang\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003ctitle\u003e{{title}}\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\n\u003cdiv :id=\"id\" style=\"font-size: 20px\" :style=\"{color: color}\"\u003e\n  \u003cspan v-if=\"color=='red'\"\u003e\n    color is red\n  \u003c/span\u003e\n  \u003cspan v-else\u003e\n    color is {{color}}\n  \u003c/span\u003e\n\u003c/div\u003e\n\n\u003c/body\u003e\n\u003c/html\u003e\n`)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tprops := vpl.NewProps()\n\tprops.AppendMap(map[string]interface{}{\n\t\t\"title\": \"hello vpl\",\n\t\t\"color\": \"red\",\n\t\t\"id\": \"content\",\n\t\t\"lang\": \"en\",\n\t})\n\n\thtml, err := v.RenderComponent(\"app\", \u0026vpl.RenderParam{\n\t\tGlobal: nil,\n\t\tCtx:    context.Background(),\n\t\tProps:  props,\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tprint(html)\n\t// Output: \u003c!DOCTYPE html\u003e\u003chtml lang=\"en\"\u003e\u003chead\u003e\u003cmeta charset=\"UTF-8\"\u003e\u003ctitle\u003ehello vpl\u003c/title\u003e\u003c/head\u003e\u003cbody\u003e\u003cdiv style=\"color: red; font-size: 20px;\"\u003e\u003cspan\u003ecolor is red\u003c/span\u003e\u003c/div\u003e\u003c/body\u003e\u003c/html\u003e\n}\n\n```\n\nThen run it.\n\n\u003e More examples in `/example` and `/test`\n\n### Description of the parameters\nYou only need to understand a few parameters.\n\n#### vpl.Props\n```\nprops := vpl.NewProps()\n// use Append to add a variable\nprops.Append(\"lang\", \"en\")\n\n// use AppendMap to add multiple variables \nprops.AppendMap(map[string]interface{}{\n    \"title\": \"hello vpl\",\n    \"color\": \"red\",\n})\n```\n\n#### vpl.RenderParam\n\n```\nvpl.RenderParam{\n    Global: nil, // Defined Global Variable in this rendering.\n    Props:  props, // Parameters of the rendering component.\n}\n```\n\n### Admonition\n\nAll data used by Vpl must be a golang base types, such as `int64`, `int`, `float32`, `float64`, `[]interface`, `map[string]interface{}`.\n\nThe following example is wrong:\n```go\nprops.Append(\"list\", [3]int{1, 2, 3})\n```\nYou should use `[]interface` type instead of `[3]int`:\n```\nprops.Append(\"list\", []interface{}{1, 2, 3})\n```\n\nFor convenience, vpl provides vpl.Copy function to convert a complex structure to a structure containing only basic types.\n```\nprops.Append(\"list\", vpl.Copy([3]int{1, 2, 3}))\n```\n\nDon't worry too much about performance, it is only executed once in each render.\n\n## With Go features\nLet's add some go features to vpl.\n\n### Parallel\nThe advantage of go is concurrency, can vpl use it?\n\nYES! Use the `\u003cparallel\u003e` component.\n\nLet's see this example:\n```vue\n\u003cdiv\u003e\n    \u003cdiv\u003e\n        \u003c!-- Some things took 1s --\u003e\n        {{ sleep(1) }} \n    \u003c/div\u003e\n    \u003cdiv\u003e\n        \u003c!-- Some things took 2s --\u003e\n        {{ sleep(2) }} \n    \u003c/div\u003e\n\u003c/div\u003e\n```\nIt will take 3s if the template is executed in order. You can wrap them with `parallel` component to parallel them.\n\n```vue\n\u003cdiv\u003e\n    \u003cparallel\u003e\n        \u003cdiv\u003e\n            \u003c!-- Some things took 1s --\u003e\n            {{ sleep(1) }} \n        \u003c/div\u003e\n    \u003c/parallel\u003e\n    \u003cparallel\u003e\n        \u003cdiv\u003e\n            \u003c!-- Some things took 2s --\u003e\n            {{ sleep(2) }} \n        \u003c/div\u003e\n    \u003c/parallel\u003e\n\u003c/div\u003e\n```\nIt only takes 2s now.\n\n## Docs\n- [Syntax Reference](./doc/syntax.md)\n- [Golang API](./doc/api.md)\n- [Vpl Internals](./doc/internal.md)\n\n## IntelliJ Plugin\nJust use the Vuejs plugin.\n\n## Dependencies\n- github.com/robertkrimen/otto: It is used to parse Js expression.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbysir%2Fvpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbysir%2Fvpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbysir%2Fvpl/lists"}