{"id":20542190,"url":"https://github.com/weivea/ts-template","last_synced_at":"2025-07-03T02:02:11.244Z","repository":{"id":83302802,"uuid":"121115477","full_name":"weivea/ts-template","owner":"weivea","description":"基于模板字符串的node端模板引擎，嘿嘿嘿~","archived":false,"fork":false,"pushed_at":"2018-02-11T11:14:19.000Z","size":2,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T14:25:11.094Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weivea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-11T11:12:54.000Z","updated_at":"2018-06-13T13:44:04.000Z","dependencies_parsed_at":"2023-07-08T03:00:25.325Z","dependency_job_id":null,"html_url":"https://github.com/weivea/ts-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weivea/ts-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fts-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fts-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fts-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fts-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weivea","download_url":"https://codeload.github.com/weivea/ts-template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fts-template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263245241,"owners_count":23436510,"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":[],"created_at":"2024-11-16T01:29:43.791Z","updated_at":"2025-07-03T02:02:10.302Z","avatar_url":"https://github.com/weivea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-template\n\n嘿嘿嘿，一个基于模板字符串的模板引擎的最简实现~, 只适用于node环境，\n\n## usage 使用\n\n模板字符串的语法，发挥想象吧，嘿嘿嘿~\n\n```\n\n```\n\n\ntest.js\n\n```javascript\nconst RenderClass = require('ts-template');\n\nconst renderVm = new RenderClass({\n  rootName: 'root', // 数据跟字段 defaut: 'root'\n  baseDir: '' // 模板根目录 defaut: path.join(process.cwd(), 'view');\n  cache: true, // 是否缓存 defaut: true\n})\n\nrenderVm.render('test.html', data)\nrenderVm.renderString('\u003cdiv\u003e${root.a} + ${root.b} = ${root.a + root.b}\u003c/div\u003e', {\n  a:1,\n  b:2\n})\n\n```\n\ntest.html\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\n\u003chead\u003e\n  \u003cmeta charset=\"utf-8\"\u003e\n  \u003cmeta name=\"viewport\" content=\"initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no\"\u003e\n  \u003cmeta name=\"format-detection\" content=\"telephone=no\"\u003e\n  \u003ctitle\u003ets-template\u003c/title\u003e\n  \u003cstyle type=\"text/css\"\u003e\n    body {\n      background: rebeccapurple;\n    }\n  \u003c/style\u003e\n  \u003cscript\u003e\n    var a = ${root.a};\n  \u003c/script\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n  include模板:\n  ${await this.include('aa.html')}\n  \u003cdiv\u003e嘿嘿嘿\u003c/div\u003e\n  1341\u003cbr\u003e\n\n  转意:\n  ${e(root.b)}\n\n  自运行函数:\n  ${(() =\u003e { return 'adadfadfasdf' })()}\n\u003c/body\u003e\n\n\u003c/html\u003e\n```\n\n## extension 扩展\n\n```javascript\nconst RenderClass = require('ts-template');\nclass SubRenderClass extends RenderClass {\n  constructor(opt) {\n    super(opt)\n  }\n  // format函数\n  dateFormat(data, 'yyyy-MM-dd') {\n    // ...\n  }\n  // async 函数\n  async getFileData(fileName) {\n    return new Promise((resolve, reject) =\u003e {\n      fs.readFile(file, (err, data) =\u003e {\n        if (err) {\n          reject(err);\n        } else {\n          resolve(data.toString('utf-8'));\n        }\n      });\n    });\n  }\n} \nconst renderVm = new SubRenderClass({\n  rootName: 'root', // 数据跟字段 defaut: 'root'\n  baseDir: '' // 模板根目录 defaut: path.join(process.cwd(), 'view');\n  cache: true, // 是否缓存 defaut: true\n})\n\nrenderVm.renderString('\u003cdiv\u003e${_.dateFormat(root.time)}\u003c/div\u003e \u003cdiv\u003e${await _.getFileData(root.file)}\u003c/div\u003e', {\n  time: 1518344445732,\n  file: '/path/to/file.txt'\n})\n// 或者\nrenderVm.renderString('\u003cdiv\u003e${this.dateFormat(root.time)}\u003c/div\u003e \u003cdiv\u003e${await this.getFileData(root.file)}\u003c/div\u003e', {\n  time: 1518344445732,\n  file: '/path/to/file.txt'\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Fts-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweivea%2Fts-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Fts-template/lists"}