{"id":13451241,"url":"https://github.com/jdiamond/Nustache","last_synced_at":"2025-03-23T18:32:06.928Z","repository":{"id":37851846,"uuid":"1027621","full_name":"jdiamond/Nustache","owner":"jdiamond","description":"Logic-less templates for .NET","archived":false,"fork":false,"pushed_at":"2023-05-31T18:47:28.000Z","size":4205,"stargazers_count":600,"open_issues_count":22,"forks_count":126,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-03-16T15:11:23.226Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","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/jdiamond.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2010-10-27T03:44:29.000Z","updated_at":"2025-02-14T02:41:04.000Z","dependencies_parsed_at":"2024-01-02T22:49:59.163Z","dependency_job_id":null,"html_url":"https://github.com/jdiamond/Nustache","commit_stats":{"total_commits":248,"total_committers":34,"mean_commits":7.294117647058823,"dds":0.5120967741935484,"last_synced_commit":"9d7d84ed0ec73996683663521dbc133f5c7a680a"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdiamond%2FNustache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdiamond%2FNustache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdiamond%2FNustache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdiamond%2FNustache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdiamond","download_url":"https://codeload.github.com/jdiamond/Nustache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245126966,"owners_count":20565192,"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-07-31T07:00:50.419Z","updated_at":"2025-03-23T18:32:06.887Z","avatar_url":"https://github.com/jdiamond.png","language":"C#","readme":"# Nustache - Logic-less templates for .NET\r\n\r\n[![Nustache.Core](https://img.shields.io/appveyor/ci/romanx/nustache/master.svg)](https://ci.appveyor.com/project/Romanx/nustache)\r\n[![Nustache.Core](https://img.shields.io/github/stars/jdiamond/Nustache.svg)](https://github.com/jdiamond/Nustache/stargazers)\r\n\r\n- Nustache.Core: [![Nustache.Core](https://img.shields.io/nuget/dt/Nustache.svg)](https://www.nuget.org/packages/Nustache/)\r\n- Nustache.Mvc3: [![Nustache.Mvc3](https://img.shields.io/nuget/dt/Nustache.Mvc3.svg)](https://www.nuget.org/packages/Nustache.Mvc3/)\r\n- Nustache.Compliation: [![Nustache.Compliation](https://img.shields.io/nuget/dt/Nustache.Compilation.svg)](https://www.nuget.org/packages/Nustache.Compilation/)\r\n\r\n### NEW NOTICE - 2015-03-29:\r\n\r\nHello, as you may have noticed this repository has been silent for awhile. I worked on it awhile ago \r\nwhen I had a problem but didn't contribute any more. \r\n\r\nI'm planning to commit some time to looking at outstanding pull-requests and issues and try get the \r\nproject moving again. With that in mind feel free to open issues and contribute pull requests.\r\n- *Romanx*\r\n\r\n### NOTICE (JDiamond):\r\n\r\nI haven't used Nustache in a while and don't have enough bandwidth to responsibly maintain it.\r\nIf you depend on Nustache and want committ access, please contact me!\r\n\r\nFor a list of implementations (other than .NET) and editor plugins, see\r\nhttp://mustache.github.com/.\r\n\r\n## Installation:\r\n\r\n- Pull from GitHub or download the repository and build it.\r\n- Or, install via NuGet (search for Nustache).\r\n- If you're using MVC, you'll want to build/install the Nustache.Mvc3 project,\r\n  too.\r\n\r\n## Usage:\r\n\r\n### For non-MVC projects:\r\n\r\n- Add a reference to Nustache.Core.dll (done for you if you used NuGet).\r\n- Import the Nustache.Core namespace.\r\n- Use one of the static, helper methods on the Render class.\r\n\r\n```C#\r\nvar html = Render.FileToString(\"foo.template\", myData);\r\n```\r\n\r\n- Data can be object, IDictionary, or DataTable.\r\n- If you need more control, use Render.Template.\r\n- See the source and tests for more information.\r\n- For compiled templates:\r\n\r\n```C#\r\nvar template = new Template();\r\ntemplate.Load(new StringReader(templateText));\r\nvar compiled = template.Compile\u003cFoo\u003e(null);\r\n\r\nvar html = compiled(fooInstance);\r\n```\r\n\r\n### For MVC projects:\r\n\r\n- Add a reference to Nustache.Mvc3.dll (done for you if you used NuGet).\r\n- Add NustacheViewEngine to the global list of view engines.\r\n- See Global.asax.cs in the Nustache.Mvc3.Example project for an example.\r\n\r\n### nustache.exe:\r\n\r\n- Command-line wrapper around Render.FileToFile.\r\n- Parameters are templatePath, dataPath, and outputPath.\r\n- Reads JSON or XML from dataPath for data.\r\n  - If extension is .js or .json, assumes JSON. Must wrap with { }.\r\n  - If extension is .xml, assumes XML. Initial context is the document element.\r\n\r\n    ```\r\n\tnustache.exe foo.template myData.json foo.html\r\n\t```\r\n\r\n- External templates are assumed to be in the same folder as the template\r\n  mentioned in templatePath.\r\n- Extension is also assumed to be the same as the template in templatePath.\r\n\r\n## Syntax:\r\n\r\n- The same as Mustache with some extensions.\r\n- Support for defining internal templates:\r\n\r\n```\r\n{{\u003cfoo}}This is the foo template.{{/foo}}\r\nThe above doesn't get rendered until it's included\r\nlike this:\r\n{{\u003efoo}}\r\n```\r\n\r\nYou can define templates inside sections. They override\r\ntemplates defined in outer sections which override\r\nexternal templates.\r\n\r\n### Helpers usage:\r\n\r\nHelpers may be useful to:\r\n- Apply custom format on the values to be rendered\r\n- To call extension methods\r\n- ...\r\n\r\n**Example:**\r\nFollowing line should print time like *13:21:10* instead of default format of `DateTime`. \r\n```\r\n{{FormatDateTime FooDateTime format=\"HH:mm:ss\"}}\r\n```\r\nTo get this working use following code before rendering.\r\n```csharp\r\nNustache.Core.Helpers.Register(\"FormatDateTime\", FormatDateTime);\r\n```\r\nAnd implement the function `FormatDateTime`, which could look like this:\r\n```csharp\r\nstatic void FormatDateTime(RenderContext context, IList\u003cobject\u003e arguments, IDictionary\u003cstring, object\u003e options, RenderBlock fn, RenderBlock inverse)\r\n{\r\n\tif (arguments != null \u0026\u0026 arguments.Count \u003e 0 \u0026\u0026 arguments[0] != null \u0026\u0026 arguments[0] is DateTime)\r\n\t{\r\n\t\tDateTime datetime = (DateTime)arguments[0];\r\n\t\tif (options != null \u0026\u0026 options.ContainsKey(\"format\"))\r\n\t\t\tcontext.Write(datetime.ToString(options[\"format\"] as string));\r\n\t\telse\r\n\t\t\tcontext.Write(datetime.ToString());\r\n\t}\r\n}\r\n```\r\nHelpers syntax in nustache is `HelperName [arguments] [options]`. Difference between `arguments` and `options` is that the `options` specifie the tuples `key=value` while arguments are simple values. If value (from arguments or options) is not closed within double quotes it gets evaluated (e.g. `FooDateTime` is evaluated to value of the member called `FooDateTime`, and therefore the `argument[0]` is of `DateTime` type. On the other hand the string `\"HH:mm:ss\"` is not evaluated.\r\n\u003eAll `arguments` and `options` are separated by spaces and even closed in double-quotes they cannot contain spaces. `arguments` and `options` may be mixed (equation sign marks it is `option` instead of `argument`). \r\n## Development:\r\n\r\n- Build with VS2012 or MSBuild.\r\n- To run the tests that use Mustache specs, run this command from your\r\n  Nustache clone:\r\n\r\n```\r\ngit submodule update --init\r\n```\r\n","funding_links":[],"categories":["Text-Template","Template Engine","模板引擎","C# #"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdiamond%2FNustache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdiamond%2FNustache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdiamond%2FNustache/lists"}