Skip to content

Commit 8e25307

Browse files
committed
Update HandlebarsHelpers.cs
1 parent 5e20046 commit 8e25307

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

Virtual_EDW/HandlebarsHelpers.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.IO;
4-
using System.Linq;
53
using System.Text;
6-
using System.Threading.Tasks;
7-
using System.Windows.Forms;
84
using HandlebarsDotNet;
95

106
namespace Virtual_Data_Warehouse
@@ -182,6 +178,39 @@ public static void RegisterHandleBarsHelpers()
182178
}
183179

184180
});
181+
182+
// Character spacing not satisfactory? Do not panic, help is near! Make sure the character spacing is righteous using this Handlebars helper.
183+
// Usage {{space sourceDataObject.name}} will space out (!?) the name of the source to 30 characters and a few tabs for lots of white spaces.
184+
Handlebars.RegisterHelper("space", (writer, context, args) =>
185+
{
186+
string outputString = args[0].ToString();
187+
if (outputString.Length < 30)
188+
{
189+
outputString = outputString.PadRight(30);
190+
}
191+
writer.WriteSafeString(outputString + "\t\t\t\t");
192+
193+
});
194+
195+
196+
Handlebars.RegisterHelper("StringReplace", (writer, context, args) =>
197+
{
198+
if (args.Length < 3) throw new HandlebarsException("The {{StringReplace}} function requires at least three arguments.");
199+
200+
string expression = args[0] as string;
201+
202+
if (args[0] is Newtonsoft.Json.Linq.JValue)
203+
{
204+
expression = ((Newtonsoft.Json.Linq.JValue)args[0]).Value.ToString();
205+
}
206+
207+
string pattern = args[1] as string;
208+
string replacement = args[2] as string;
209+
210+
expression = expression.Replace(pattern, replacement);
211+
writer.WriteSafeString(expression);
212+
213+
});
185214
}
186215
}
187216
}

0 commit comments

Comments
 (0)