Skip to content

Commit

Permalink
Add section blacklist for JObject to stop iteration (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanx authored Aug 11, 2019
1 parent 2431c1a commit f2beabf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/Stubble.Extensions.JsonNet/JsonNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static RendererSettingsBuilder AddJsonNet(this RendererSettingsBuilder bu
builder.AddValueGetter(getter.Key, getter.Value);
}

builder.AddSectionBlacklistType(typeof(JObject));

return builder;
}

Expand Down
54 changes: 27 additions & 27 deletions src/Stubble.Extensions.JsonNet/Stubble.Extensions.JsonNet.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Copyright>Copyright © 2015</Copyright>
<Authors>Alex McAuliffe</Authors>
<LangVersion>7.3</LangVersion>
<Description>Extensions to Stubble adding ValueGetters for Newtonsoft Json.Net</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageTags>template;mustache;text;generation;fast;newtonsoft;json.net;extension;stubble-extension</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/StubbleOrg/Stubble.Extensions.JsonNet</RepositoryUrl>
<PackageIconUrl>https://raw.githubusercontent.com/StubbleOrg/Stubble/master/assets/extension-logo-64.png</PackageIconUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Stubble.Core" Version="1.0.112" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Nerdbank.GitVersioning" Version="2.1.65" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Copyright>Copyright © 2015</Copyright>
<Authors>Alex McAuliffe</Authors>
<LangVersion>7.3</LangVersion>
<Description>Extensions to Stubble adding ValueGetters for Newtonsoft Json.Net</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageTags>template;mustache;text;generation;fast;newtonsoft;json.net;extension;stubble-extension</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/StubbleOrg/Stubble.Extensions.JsonNet</RepositoryUrl>
<PackageIconUrl>https://raw.githubusercontent.com/StubbleOrg/Stubble/master/assets/extension-logo-64.png</PackageIconUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Stubble.Core" Version="1.4.12" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.0.25" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions test/Stubble.Extensions.JsonNet.Tests/JsonNetExtensionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,21 @@ public void Truthy_Checks_Work_For_Inverted()
Assert.NotNull(output);
Assert.Equal("foobar", output);
}

[Fact]
public void It_Handles_Section_Correctly()
{
const string json = "{ foo: { bar: \"foobar\", \"zar\": \"zoo\" } }";

var stubble = new StubbleBuilder()
.Configure(settings => settings.AddJsonNet())
.Build();

var obj = JsonConvert.DeserializeObject(json);

var output = stubble.Render("{{#foo}}{{bar}},{{zar}}{{/foo}}", obj);
Assert.NotNull(output);
Assert.Equal("foobar,zoo", output);
}
}
}

0 comments on commit f2beabf

Please sign in to comment.