Example #1
0
        /// <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
                   ));
        }
Example #2
0
        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));
        }
Example #3
0
        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
             */
        }
Example #4
0
        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"
            );
        }