/// <summary> /// Generates a new Nettle compiler with custom functions /// </summary> /// <returns>The Nettle compiler</returns> public INettleCompiler Generate() { var dataResolver = new NettleDataResolver(); var webResolver = new NettleWebResolver(); var appSettings = ConfigurationManager.AppSettings; var defaultTimeZoneId = appSettings["DefaultTimeZoneId"]; NettleEngine.RegisterResolvers ( dataResolver, webResolver ); if (false == String.IsNullOrEmpty(defaultTimeZoneId)) { NettleEngine.SetDefaultTimeZone ( defaultTimeZoneId ); } return(NettleEngine.GetCompiler ( _customFunctions )); }
private static async Task <string> HomePageTemplate(object o) { var data = await AbsolutePath.EntryPoint.Combine(@"Controllers\Templates\AuthorControls.html") .ReadAllTextAsync(); var func = NettleEngine.GetCompiler().Compile(data); return(func(o)); }
public void CanTemplateString() { var source = @"Welcome {{Name}}"; var model = new { Name = "John Smith" }; var compiler = NettleEngine.GetCompiler(); var template = compiler.Compile(source); var output = template(model); output.ShouldBe("Welcome John Smith"); /* Result: * Welcome John Smith */ }
public DemoForm() { InitializeComponent(); var dataResolver = new NettleDataResolver(); var connectionString = ConfigurationManager.AppSettings [ "DatabaseConnectionString" ]; if (false == String.IsNullOrEmpty(connectionString)) { dataResolver.ConnectionRepository.AddConnection ( new SqlClientConnection ( "Demo", connectionString ) ); } NettleEngine.RegisterResolvers ( new DefaultNettleResolver(), new NettleWebResolver(), new NettleNCalcResolver(), dataResolver ); _compiler = NettleEngine.GetCompiler(); _compiler.AutoRegisterViews ( "../../Templates" ); }