Skip to content

Commit

Permalink
Merge pull request #8 from cezarypiatek/feature/initial_release
Browse files Browse the repository at this point in the history
Add custom filters to fluid templates based on the Humanizer
  • Loading branch information
cezarypiatek committed Oct 16, 2023
2 parents 35d5c48 + 90ecbaf commit b99edce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
@@ -1,5 +1,7 @@
using System;
using Fluid;
using Fluid.Values;
using Humanizer;
using UniversalTemplates.Core;

namespace UniversalTemplates.TemplateEngines;
Expand All @@ -9,6 +11,13 @@ class FluidUniversalTemplate : IUniversalTemplate
public string Transform(Template template, object? context)
{
var options = new TemplateOptions();
options.Filters.AddFilter("camelCase", (input, arguments, templateContext) => new StringValue(input.ToStringValue().Camelize()) );
options.Filters.AddFilter("pascalCase", (input, arguments, templateContext) => new StringValue(input.ToStringValue().Pascalize()) );
options.Filters.AddFilter("titleCase", (input, arguments, templateContext) => new StringValue(input.ToStringValue().Titleize()) );
options.Filters.AddFilter("snakeCase", (input, arguments, templateContext) => new StringValue(input.ToStringValue().Underscore()) );
options.Filters.AddFilter("kebabCase", (input, arguments, templateContext) => new StringValue(input.ToStringValue().Kebaberize()) );
options.Filters.AddFilter("humanize", (input, arguments, templateContext) => new StringValue(input.ToStringValue().Humanize()) );
options.Filters.AddFilter("dehumanize", (input, arguments, templateContext) => new StringValue(input.ToStringValue().Dehumanize()) );
var parser = new FluidParser();
if (parser.TryParse(template.Content, out var ftemplate, out var error))
{
Expand Down
1 change: 1 addition & 0 deletions src/UniversalTemplates/UniversalTemplates.csproj
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Handlebars.Net" Version="2.1.2" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="7.0.0-rc.2.22472.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
Expand Down

0 comments on commit b99edce

Please sign in to comment.