{"id":13505064,"url":"https://github.com/Kitura/Kitura-TemplateEngine","last_synced_at":"2025-03-29T22:31:26.276Z","repository":{"id":47659867,"uuid":"52851385","full_name":"Kitura/Kitura-TemplateEngine","owner":"Kitura","description":"Kitura Template Engine protocol ","archived":false,"fork":false,"pushed_at":"2021-08-19T09:20:46.000Z","size":381,"stargazers_count":15,"open_issues_count":2,"forks_count":9,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-05-13T14:59:32.384Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kitura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-01T05:44:31.000Z","updated_at":"2024-05-13T14:59:32.385Z","dependencies_parsed_at":"2022-09-14T09:13:01.120Z","dependency_job_id":null,"html_url":"https://github.com/Kitura/Kitura-TemplateEngine","commit_stats":null,"previous_names":["ibm-swift/kitura-templateengine"],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-TemplateEngine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-TemplateEngine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-TemplateEngine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-TemplateEngine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kitura","download_url":"https://codeload.github.com/Kitura/Kitura-TemplateEngine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246254077,"owners_count":20747946,"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-08-01T00:00:57.765Z","updated_at":"2025-03-29T22:31:24.761Z","avatar_url":"https://github.com/Kitura.png","language":"Swift","funding_links":[],"categories":["Monitoring"],"sub_categories":["Templating"],"readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"http://kitura.io/\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/Kitura/Kitura/master/Sources/Kitura/resources/kitura-bird.svg?sanitize=true\" height=\"100\" alt=\"Kitura\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://kitura.github.io/Kitura-TemplateEngine/index.html\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/apidoc-KituraTemplateEngine-1FBCE4.svg?style=flat\" alt=\"APIDoc\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://travis-ci.org/Kitura/Kitura-TemplateEngine.svg?branch=master\" alt=\"Build Status - Master\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/os-macOS-green.svg?style=flat\" alt=\"macOS\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/os-linux-green.svg?style=flat\" alt=\"Linux\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Apache2-blue.svg?style=flat\" alt=\"Apache 2\"\u003e\n    \u003ca href=\"http://swift-at-ibm-slack.mybluemix.net/\"\u003e\n    \u003cimg src=\"http://swift-at-ibm-slack.mybluemix.net/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n# Kitura-TemplateEngine\nThe Kitura template engine abstraction layer.\n\nKitura-TemplateEngine provides a `TemplateEngine` protocol to unify the APIs of multiple template engines and integrate them with Kitura's content generation APIs. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page with integrated Swift code.\n\n- Inspired by http://expressjs.com/en/guide/using-template-engines.html.\n\n## List of Plugins:\nKitura-TemplateEngine is an easy to learn, consumable framework that comes with a set of implemented plugins:\n\n* [Kitura-StencilTemplateEngine](https://github.com/Kitura/Kitura-StencilTemplateEngine)\n* [Kitura-MustacheTemplateEngine](https://github.com/Kitura/Kitura-MustacheTemplateEngine)\n* [Kitura-Markdown](https://github.com/Kitura/Kitura-Markdown)\n\n## Usage\n\n We don't expect you to need to import Kitura-TemplateEngine, as it will automatically be pulled in as a dependency by the above plugins (you can see an example of this in [Examples](#examples) below) - unless you are implementing a new plugin for Kitura-TemplateEngine. If you do need to directly add Kitura-TemplateEngine as a dependency you can do so as follows:\n\n#### Add dependencies\n\nAdd the `Kitura-TemplateEngine` package to the dependencies within your application’s `Package.swift` file. Substitute `\"x.x.x\"` with the latest `Kitura-TemplateEngine` [release](https://github.com/Kitura/Kitura-TemplateEngine/releases).\n\n```swift\n.package(url: \"https://github.com/Kitura/Kitura-TemplateEngine.git\", from: \"x.x.x\")\n```\n\nAdd `KituraTemplateEngine` to your target's dependencies:\n\n```swift\n.target(name: \"example\", dependencies: [\"KituraTemplateEngine\"]),\n```\n\n#### Import package\n\n```swift\nimport KituraTemplateEngine\n```\n\n## Examples\nThe following code examples use the [Kitura-StencilTemplateEngine](https://github.com/Kitura/Kitura-StencilTemplateEngine), however, because this is an abstraction layer, Stencil could be substituted for any supported template engine.\n\nIf you are using Stencil, within your `Package.swift` file you will need to:\n\n - Define \"https://github.com/Kitura/Kitura-StencilTemplateEngine.git\" as a dependency.\n - Add \"KituraStencil\" to the targets for Application.\n\n You will also need to add `KituraStencil` to the file where you're writing your Swift code:\n ```swift\nimport KituraStencil\n```\n\nThe following code initializes a [Stencil](https://github.com/kylef/Stencil) template engine and adds it to the [Kitura](https://github.com/Kitura/Kitura) router.\nThis will render files with the template engine's default file extension, in this example these would be `.stencil` files.\n```swift\nrouter.add(templateEngine: StencilTemplateEngine())\n```\n\nHere we show how to render files which don't have the same default file extension as the chosen template engine. In this example `useDefaultFileExtension` is set to false, so the default file extension (`.stencil` in this case) will not be rendered and files with the extension `.example` will be rendered.\n\n```swift\nrouter.add(templateEngine: StencilTemplateEngine(), forFileExtensions: [\".example\"], useDefaultFileExtension: false)\n```\n\nIf there are any files with file extensions which do not match any of the template engines which have been added to the router, the router will render the file using the default template engine. You can set the default template engine for the router as follows:\n```swift\nrouter.setDefault(templateEngine: StencilTemplateEngine())\n```\n\nThe following example will render the Stencil template `example.stencil` and add it to our router's response. The template file will be retrieved from the default location, which is the `Views` folder. The context variable allows you to pass data through to the template engine and must be valid JSON.\n```swift\nrouter.get(\"/example\") { request, response, next in\n    var context: [String: Any] = [\"key\" : \"value\"]\n    try response.render(\"example.stencil\", context: context)\n    next()\n}\n```\n\n## API Documentation\nFor more information visit our [API reference](https://kitura.github.io/Kitura-TemplateEngine/index.html).\n\n## Community\n\nWe love to talk server-side Swift, and Kitura. Join our [Slack](http://swift-at-ibm-slack.mybluemix.net/) to meet the team!\n\n## License\nThis library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/Kitura/Kitura-TemplateEngine/blob/master/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKitura%2FKitura-TemplateEngine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKitura%2FKitura-TemplateEngine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKitura%2FKitura-TemplateEngine/lists"}