|
1 | | -# Handlebars.Net.Extension |
| 1 | +# Handlebars.Net.Extension.NewtonsoftJson |
2 | 2 |
|
3 | | -Template repository for Handlebars.Net extensions |
4 | 3 |
|
5 | | -#### How to use: |
6 | | -- Create new repo using template |
7 | | -- Find all `<!-- Replace with correct value -->` and replace with valid values |
8 | | -- Make additional changes that are required by the extensions |
| 4 | +#### [](https://github.com/Handlebars-Net/Handlebars.Net.Extension.NewtonsoftJson/actions?query=workflow%3ACI) [](https://www.nuget.org/packages/Handlebars.Net.Extension.NewtonsoftJson/) [](http://handlebars-net.github.io/Handlebars.Net.Extension.NewtonsoftJson/dev/bench/) |
9 | 5 |
|
10 | | -Notes: |
11 | | -- The template is designed to be used as part of Handlebars-Net organization. |
12 | | -Usage outside of the organization may require additional changes |
| 6 | +--- |
| 7 | + |
| 8 | +[](https://sonarcloud.io/dashboard?id=Handlebars-Net_Handlebars.Net.Extension.NewtonsoftJson) [](https://sonarcloud.io/dashboard?id=Handlebars-Net_Handlebars.Net.Extension.NewtonsoftJson) [](https://sonarcloud.io/dashboard?id=Handlebars-Net_Handlebars.Net.Extension.NewtonsoftJson) |
| 9 | + |
| 10 | +[](https://sonarcloud.io/dashboard?id=Handlebars-Net_Handlebars.Net.Extension.NewtonsoftJson) [](https://sonarcloud.io/dashboard?id=Handlebars-Net_Handlebars.Net.Extension.NewtonsoftJson) [](https://sonarcloud.io/dashboard?id=Handlebars-Net_Handlebars.Net.Extension.NewtonsoftJson) |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +[](https://github.com/Handlebars-Net/Handlebars.Net.Extension.NewtonsoftJson/labels/question) |
| 15 | +[](https://github.com/Handlebars-Net/Handlebars.Net.Extension.NewtonsoftJson/labels/help%20wanted) |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Purpose |
| 20 | + |
| 21 | +Adds proper [Newtonsoft.Json](https://www.newtonsoft.com/json) support to Handlebars.Net |
| 22 | + |
| 23 | +### Install |
| 24 | +```cmd |
| 25 | +dotnet add package Handlebars.Net.Extension.NewtonsoftJson |
| 26 | +``` |
| 27 | + |
| 28 | +### Usage |
| 29 | +```c# |
| 30 | +var handlebars = Handlebars.Create(); |
| 31 | +handlebars.Configuration.UseNewtonsoftJson(); |
| 32 | +``` |
| 33 | + |
| 34 | +### Example |
| 35 | +```c# |
| 36 | +[Fact] |
| 37 | +public void JsonTestObjects() |
| 38 | +{ |
| 39 | + var model = JObject.Parse("{\"Key1\": \"Val1\", \"Key2\": \"Val2\"}"); |
| 40 | + |
| 41 | + var source = "{{#each this}}{{@key}}{{@value}}{{/each}}"; |
| 42 | + |
| 43 | + var handlebars = Handlebars.Create(); |
| 44 | + handlebars.Configuration.UseNewtonsoftJson(); |
| 45 | + |
| 46 | + var template = handlebars.Compile(source); |
| 47 | + |
| 48 | + var output = template(model); |
| 49 | + |
| 50 | + Assert.Equal("Key1Val1Key2Val2", output); |
| 51 | +} |
| 52 | +``` |
13 | 53 |
|
14 | | -#### If you want your extension to be moved under Handlebars-Net organization: |
15 | | -- Add [@zjklee](https://github.com/zjklee) as admin for the repo |
16 | | -- Contact [@zjklee](https://github.com/zjklee) |
|
0 commit comments