{"id":32149274,"url":"https://github.com/loopwerk/sagastencilrenderer","last_synced_at":"2025-10-21T09:51:38.992Z","repository":{"id":63916699,"uuid":"342732654","full_name":"loopwerk/SagaStencilRenderer","owner":"loopwerk","description":"A renderer for Saga that uses Stencil to turn a RenderingContext into a String","archived":false,"fork":false,"pushed_at":"2025-07-31T19:22:27.000Z","size":458,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-21T09:51:35.450Z","etag":null,"topics":["saga-plugin"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/loopwerk.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":"2021-02-27T00:11:21.000Z","updated_at":"2025-07-31T19:22:31.000Z","dependencies_parsed_at":"2023-01-14T13:45:53.436Z","dependency_job_id":null,"html_url":"https://github.com/loopwerk/SagaStencilRenderer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/loopwerk/SagaStencilRenderer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopwerk%2FSagaStencilRenderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopwerk%2FSagaStencilRenderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopwerk%2FSagaStencilRenderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopwerk%2FSagaStencilRenderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopwerk","download_url":"https://codeload.github.com/loopwerk/SagaStencilRenderer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopwerk%2FSagaStencilRenderer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280240304,"owners_count":26296527,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["saga-plugin"],"created_at":"2025-10-21T09:51:38.005Z","updated_at":"2025-10-21T09:51:38.986Z","avatar_url":"https://github.com/loopwerk.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SagaStencilRenderer\nA renderer for [Saga](https://github.com/loopwerk/Saga) that uses [Stencil](https://github.com/stencilproject/Stencil) to turn a RenderingContext into a String.\n\nIt comes with a free function named `stencil` which takes an HTML template and a Stencil `Environment`, and returns a function that goes from `RenderingContext` to `String`, which can then be plugged into Saga's writers.\n\n## Example\nPackage.swift\n\n``` swift\n// swift-tools-version:5.5\n\nimport PackageDescription\n\nlet package = Package(\n  name: \"Example\",\n  platforms: [\n    .macOS(.v12)\n  ],\n  dependencies: [\n    .package(url: \"https://github.com/loopwerk/Saga\", from: \"1.0.0\"),\n    .package(url: \"https://github.com/loopwerk/SagaParsleyMarkdownReader\", from: \"0.5.0\"),\n    .package(url: \"https://github.com/loopwerk/SagaStencilRenderer\", from: \"0.4.0\")\n  ],\n  targets: [\n    .target(\n      name: \"Example\",\n      dependencies: [\n        \"Saga\",\n        \"SagaParsleyMarkdownReader\",\n        \"SagaStencilRenderer\"\n      ]\n    ),\n  ]\n)\n```\n\nmain.swift:\n\n```swift\nimport Foundation\nimport Saga\nimport PathKit\nimport SagaParsleyMarkdownReader\nimport SagaStencilRenderer\nimport Stencil\n\n@main\nstruct Run {\n  static func main() async throws {\n    let saga = try Saga(input: \"content\", output: \"deploy\")\n\n    try await saga\n      // All the Markdown files will be parsed to html.\n      .register(\n        readers: [.parsleyMarkdownReader()],\n        itemWriteMode: .keepAsFile,\n        writers: [\n          .itemWriter(stencil(\"page.html\", environment: getEnvironment(root: saga.rootPath)))\n        ]\n      )\n\n      // Run the steps we registered above\n      .run()\n\n      // All the remaining files that were not parsed to markdown, so for example images, raw html files and css,\n      // are copied as-is to the output folder.\n      .staticFiles()\n  }\n}\n\nfunc getEnvironment(root: Path) -\u003e Environment {\n  Environment(loader: FileSystemLoader(paths: [root + \"templates\"]))\n}\n```\n\nPlease check out the [Example app](https://github.com/loopwerk/SagaStencilRenderer/tree/main/Example) to play around.\n\n\n## Extending the Stencil Environment\nYou can extend the `Environment` with your own tags and filters, see the [official Stencil docs](https://stencil.fuller.li/en/latest/custom-template-tags-and-filters.html).\n\nFor example:\n\n```swift\nfunc getEnvironment(root: Path) -\u003e Environment {\n  let ext = Extension()\n  \n  ext.registerFilter(\"url\") { (value: Any?) in\n    guard let item = value as? AnyItem else {\n      return \"\"\n    }\n    var url = \"/\" + item.relativeDestination.string\n    if url.hasSuffix(\"/index.html\") {\n      url.removeLast(10)\n    }\n    return url\n  }\n\n  return Environment(loader: FileSystemLoader(paths: [root + \"templates\"]), extensions: [ext])\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopwerk%2Fsagastencilrenderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopwerk%2Fsagastencilrenderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopwerk%2Fsagastencilrenderer/lists"}