public MathHelpersTemplateTests() { _handlebarsContext = Handlebars.Create(); _handlebarsContext.Configuration.FormatProvider = CultureInfo.InvariantCulture; HandlebarsHelpers.Register(_handlebarsContext, Category.Math); }
public StringHelpersTemplateTests() { _dateTimeServiceMock = new Mock <IDateTimeService>(); _dateTimeServiceMock.Setup(d => d.Now()).Returns(DateTimeNow); _dateTimeServiceMock.Setup(d => d.UtcNow()).Returns(DateTimeNow.ToUniversalTime); _handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(_handlebarsContext, o => { o.DateTimeService = _dateTimeServiceMock.Object; }); }
public StringHelpersTemplateTests() { _dateTimeServiceMock = new Mock <IDateTimeService>(); _dateTimeServiceMock.Setup(d => d.Now()).Returns(DateTimeNow); _dateTimeServiceMock.Setup(d => d.UtcNow()).Returns(DateTimeNow.ToUniversalTime); _handlebarsContext = Handlebars.Create(); _handlebarsContext.Configuration.FormatProvider = CultureInfo.InvariantCulture; HandlebarsHelpers.Register(_handlebarsContext, o => { o.DateTimeService = _dateTimeServiceMock.Object; }); }
public void WithoutCategoryPrefix() { // Arrange var handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(handlebarsContext, options => { options.UseCategoryPrefix = false; }); var action = handlebarsContext.Compile("{{[Append] \"foo\" \"bar\"}}"); // Act var result = action(""); // Assert result.Should().Be("foobar"); }
public void WithCustomPrefixSeparator() { // Arrange var handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(handlebarsContext, options => { options.PrefixSeparator = "-"; }); var action = handlebarsContext.Compile("{{String-Append \"foo\" \"bar\"}}"); // Act var result = action(""); // Assert result.Should().Be("foobar"); }
public void WithCategoryPrefixAndExtraWithPrefix() { // Arrange var handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(handlebarsContext, options => { options.UseCategoryPrefix = true; options.Prefix = "test"; }); var action = handlebarsContext.Compile("{{[test.String.Append] \"foo\" \"bar\"}}"); // Act var result = action(""); // Assert result.Should().Be("foobar"); }
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler) { // Register https://github.com/StefH/Handlebars.Net.Helpers HandlebarsHelpers.Register(handlebarsContext); // Register WireMock.Net specific helpers HandlebarsRegex.Register(handlebarsContext); HandlebarsJsonPath.Register(handlebarsContext); HandlebarsLinq.Register(handlebarsContext); HandlebarsRandom.Register(handlebarsContext); HandlebarsXeger.Register(handlebarsContext); HandlebarsXPath.Register(handlebarsContext); HandlebarsFile.Register(handlebarsContext, fileSystemHandler); }
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler) { // Register https://github.com/StefH/Handlebars.Net.Helpers HandlebarsHelpers.Register(handlebarsContext, o => { o.CustomHelperPaths = new string[] { Directory.GetCurrentDirectory() #if !NETSTANDARD1_3 , Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) #endif } .Distinct() .ToList(); o.CustomHelpers = new Dictionary <string, IHelpers> { { "File", new FileHelpers(handlebarsContext, fileSystemHandler) } }; }); }
public static Services Create(QuartzminOptions options) { var handlebarsConfiguration = new HandlebarsConfiguration() { FileSystem = ViewFileSystemFactory.Create(options), ThrowOnUnresolvedBindingExpression = true, }; var services = new Services() { Options = options, Scheduler = options.Scheduler, Handlebars = HandlebarsDotNet.Handlebars.Create(handlebarsConfiguration), }; HandlebarsHelpers.Register(services); services.ViewEngine = new ViewEngine(services); services.TypeHandlers = new TypeHandlerService(services); services.Cache = new Cache(services); return(services); }
public JsonPathHelpersTemplateTests() { _handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(_handlebarsContext, Category.JsonPath); }
public RandomHelpersTemplateTests() { _handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(_handlebarsContext, Category.Random); }
static void Main(string[] args) { var handlebars = Handlebars.Create(); HandlebarsHelpers.Register(handlebars, options => { options.UseCategoryPrefix = false; }); //handlebars.RegisterHelper("ArrayTest", (context, arguments) => //{ // var array = new object[] // { // 1, // "two" // }; // return array; //}); //var templateX = handlebars.Compile("{{#each (ArrayTest min=6)}}_{{this}}_{{/each}}"); //var resultX = templateX.Invoke(""); //Console.WriteLine("ArrayTest = " + resultX); var tests = new[] { "{{Abs -1}}", "{{Abs -1.1234}}", "{{Add 1 2}}", "{{Add 1 '2'}}", "{{Sign -1}}", "{{Sign " + long.MinValue + "}}", "{{Sign -1.1234}}", "{{Abs -1,1234}}", "{{Min 42 5}}", "{{Min 42 5.2}}", "{{Min 42.1 5}}", "{{this}}", "{{[Constants.Math.PI]}}", "{{#IsMatch \"Hello\" \"Hello\"}}yes{{else}}no{{/IsMatch}}", "{{#IsMatch \"Hello\" \"hello\"}}yes{{else}}no{{/IsMatch}}", "{{#IsMatch \"Hello\" \"hello\" 'i'}}yesI{{else}}noI{{/IsMatch}}", "{{#StartsWith \"Hello\" \"x\"}}Hi{{else}}Goodbye{{/StartsWith}}", "{{Skip [\"a\", \"b\", \"c\", 1] 1}}", "{{StartsWith \"abc\" \"!def\"}}", "{{Append \"abc\" \"!def\"}}", "{{Capitalize \"abc def\"}}", "{{Ellipsis \"abcfskdagdghsjfjd\" 5}}", "{{Reverse \"abc def\"}}", "{{Truncate \"abc def\" 166}}", "{{Camelcase \"abc def\"}}", "{{Pascalcase \"abc def\"}}", "{{Uppercase \"abc\"}}", "{{Lowercase \"XYZ\"}}", "{{Format x \"o\"}}", "{{Now}}", "{{UtcNow}}", "{{Now \"yyyy-MM-dd\"}}", "{{Format (Now) \"yyyy-MM-dd\"}}", "{{Xeger.Generate \"[1-9]{1}\\d{3}\"}}", "{{Random Type=\"Integer\" Min=1000 Max=9999}}" }; foreach (string test in tests) { var t = new { x = DateTime.Now }; var template = handlebars.Compile(test); var result = template.Invoke(t); Console.WriteLine($"{test} : {result}"); } Console.WriteLine(new string('-', 80)); var handlebars2 = Handlebars.Create(); HandlebarsHelpers.Register(handlebars2, options => { options.UseCategoryPrefix = true; }); var tests2 = new[] { "{{[Math.Abs] -42}}", "{{Math.Abs -42}}" }; foreach (string test in tests2) { var x = DateTime.Now; var template = handlebars2.Compile(test); var result = template.Invoke(x); Console.WriteLine($"{test} : {result}"); } }
public DynamicLinqHelpersTemplateTests() { _handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(_handlebarsContext, Category.DynamicLinq); }
public ConstantsHelpersTemplateTests() { _handlebarsContext = Handlebars.Create(); HandlebarsHelpers.Register(_handlebarsContext, Category.Constants); }