Beispiel #1
0
        public Precompiler(string root)
        {
            _root       = root;
            _handlebars = HandlebarsFactory.CreateEngine();
            _templates  = System.IO.Directory.EnumerateFiles(_root,
                                                             "*.handlebars",
                                                             SearchOption.AllDirectories).Union(
                System.IO.Directory.EnumerateFiles(_root,
                                                   "*.hbs",
                                                   SearchOption.AllDirectories)
                ).ToList();

            // var assembly = Assembly.GetExecutingAssembly();
            // var names = assembly.GetManifestResourceNames()
            //                     .Where(_ => _.EndsWith(".js"))
            //                     .ToList();
            //
            // foreach (var resource in names)
            // {
            //     using (Stream stream = assembly.GetManifestResourceStream(resource))
            //     using (StreamReader reader = new StreamReader(stream))
            //     {
            //         string content = reader.ReadToEnd();
            //         _handlebars.AddHelpers(content);
            //     }
            // }
        }
 public HandlebarsCompiler(IHandlebarsEngine engine)
 {
     _tokenizer = new Tokenizer();
     _tokenExpressionConverter = new TokenExpressionConverter(engine.Configuration);
     _functionBuilder          = new FunctionBuilder(engine);
     _engine = engine;
 }
        public Precompiler(string root)
        {
            _root = root;
            _handlebars = HandlebarsFactory.CreateEngine();
            _templates = System.IO.Directory.EnumerateFiles(_root,
                                                            "*.handlebars",
                                                            SearchOption.AllDirectories).Union(
                                                            System.IO.Directory.EnumerateFiles(_root,
                                                            "*.hbs",
                                                            SearchOption.AllDirectories)                                                            
                                                            ).ToList();            

            // var assembly = Assembly.GetExecutingAssembly();
            // var names = assembly.GetManifestResourceNames()
            //                     .Where(_ => _.EndsWith(".js"))
            //                     .ToList();
            // 
            // foreach (var resource in names)
            // {
            //     using (Stream stream = assembly.GetManifestResourceStream(resource))
            //     using (StreamReader reader = new StreamReader(stream))
            //     {
            //         string content = reader.ReadToEnd();
            //         _handlebars.AddHelpers(content);
            //     }
            // }
        }
Beispiel #4
0
        public void Execute(IHandlebarsEngine engine, TextWriter output, dynamic context, params object[] arguments)
        {
            var configuration = engine.Configuration;
            var logger        = configuration.Logger;

            if (logger == null || configuration.LogLevel == LogLevel.None)
            {
                return;
            }

            var parameters = arguments.LastOrDefault() as HashParameterDictionary;
            var logLevel   = GetLogLevel(parameters);

            if (logLevel < configuration.LogLevel || logLevel == LogLevel.None)
            {
                return;
            }

            var count = parameters != null ? arguments.Length - 1 : arguments.Length;

            for (var i = 0; i < count; i++)
            {
                logger.Log(arguments[i].ToString(), logLevel);
            }
        }
Beispiel #5
0
        public CustomConfigurationTests()
        {
            var configuration = new HandlebarsConfiguration
            {
                ExpressionNameResolver =
                    new UpperCamelCaseExpressionNameResolver()
            };

            this.HandlebarsInstance = new HandlebarsEngine(configuration);
        }
        public PrecompiledHandlebarsTemplate(IHandlebarsEngine engine,
                                             IHandlebarsResourceProvider provider, 
                                             Uri uri)
        {
            this._engine = engine;
            this._provider = provider;

            // download the string
            var js = new WebClient().DownloadString(uri);
            _engine.ImportPrecompile(js);
        }
Beispiel #7
0
        public PrecompiledHandlebarsTemplate(IHandlebarsEngine engine,
                                             IHandlebarsResourceProvider provider,
                                             Uri uri)
        {
            this._engine   = engine;
            this._provider = provider;

            // download the string
            var js = new WebClient().DownloadString(uri);

            _engine.ImportPrecompile(js);
        }
Beispiel #8
0
        private static string CaptureTextWriterOutputFromHelper(
            HandlebarsHelperV2 helper,
            IHandlebarsEngine engine,
            object context,
            object[] arguments)
        {
            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder))
            {
                helper(engine, writer, context, arguments);
            }
            return(builder.ToString());
        }
Beispiel #9
0
        public void Execute(IHandlebarsEngine engine, TextWriter output, HandlebarsBlockHelperOptions options,
                            dynamic context, params object[] arguments)
        {
            if (arguments.Length != 1)
            {
                throw new HandlebarsException("{{with}} helper must have exactly one argument");
            }

            if (HandlebarsUtils.IsTruthyOrNonEmpty(arguments[0]))
            {
                options.Template(output, arguments[0]);
            }
            else
            {
                options.Inverse(output, context);
            }
        }
        public ProxyStartup(IHandlebarsEngine engine, IHandlebarsTemplate template)
        {
            _handlebars = engine;
            _template = template;

            HandlebarsConfiguration.Instance.TemplatePath = HandlebarsProxyConfiguration.Instance.Directory + "\\template";
            WebRequestHandler webRequestHandler = new WebRequestHandler();

            // we don't do this, as we miss the authentication headers
            // we just pass redirects onto the browser and handle it like that
            webRequestHandler.AllowAutoRedirect = false;
            webRequestHandler.UseCookies = false;
            webRequestHandler.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });

            _store = MemoryCache.Default;
            _client = new HttpClient(webRequestHandler, false)
            {
                BaseAddress = new Uri(HandlebarsProxyConfiguration.Instance.Scheme +
                                      "://" +
                                      HandlebarsProxyConfiguration.Instance.Domain +
                                      ":" +
                                      HandlebarsProxyConfiguration.Instance.DomainPort),                                      

            };

            

            // 
            if (!string.IsNullOrEmpty(HandlebarsProxyConfiguration.Instance.Username) &&
                !string.IsNullOrEmpty(HandlebarsProxyConfiguration.Instance.Password))
            {
                _authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
                                     Encoding.ASCII.GetBytes(string.Format("{0}:{1}", 
                                                                           HandlebarsProxyConfiguration.Instance.Username,
                                                                           HandlebarsProxyConfiguration.Instance.Password)))
                );

                _client.DefaultRequestHeaders.Authorization = _authHeader;                
            }
            
        }
Beispiel #11
0
        public ProxyStartup(IHandlebarsEngine engine, IHandlebarsTemplate template)
        {
            _handlebars = engine;
            _template   = template;

            HandlebarsConfiguration.Instance.TemplatePath = HandlebarsProxyConfiguration.Instance.Directory + "\\template";
            WebRequestHandler webRequestHandler = new WebRequestHandler();

            // we don't do this, as we miss the authentication headers
            // we just pass redirects onto the browser and handle it like that
            webRequestHandler.AllowAutoRedirect = false;
            webRequestHandler.UseCookies        = false;
            webRequestHandler.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); });

            _store  = MemoryCache.Default;
            _client = new HttpClient(webRequestHandler, false)
            {
                BaseAddress = new Uri(HandlebarsProxyConfiguration.Instance.Scheme +
                                      "://" +
                                      HandlebarsProxyConfiguration.Instance.Domain +
                                      ":" +
                                      HandlebarsProxyConfiguration.Instance.DomainPort),
            };



            //
            if (!string.IsNullOrEmpty(HandlebarsProxyConfiguration.Instance.Username) &&
                !string.IsNullOrEmpty(HandlebarsProxyConfiguration.Instance.Password))
            {
                _authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
                                                                Encoding.ASCII.GetBytes(string.Format("{0}:{1}",
                                                                                                      HandlebarsProxyConfiguration.Instance.Username,
                                                                                                      HandlebarsProxyConfiguration.Instance.Password)))
                                                            );

                _client.DefaultRequestHeaders.Authorization = _authHeader;
            }
        }
Beispiel #12
0
        private static bool InvokePartial(
            string partialName,
            BindingContext context,
            IHandlebarsEngine engine)
        {
            var templateRegistry = engine.Configuration.HandlebarsTemplateRegistry;

            if (!templateRegistry.TryGetTemplate(partialName, out HandlebarsTemplate template))
            {
                var partialLookupKey = $"{context.TemplateName ?? string.Empty}+{partialName}";
                if (!templateRegistry.TryGetTemplate(partialLookupKey, out template))
                {
                    template = engine.CompileView(partialName, context.TemplateName, false);
                    if (template == null)
                    {
                        return(false);
                    }
                    templateRegistry.RegisterTemplate(partialLookupKey, template);
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                template.RenderTo(context.TextWriter, context);
                return(true);
            }
            catch (Exception exception)
            {
                throw new HandlebarsRuntimeException(
                          $"Runtime error while rendering partial '{partialName}', see inner exception for more information",
                          exception);
            }
        }
Beispiel #13
0
 public DevelopmentHandlebarsTemplate(IHandlebarsEngine engine,
                                      IHandlebarsResourceProvider provider)
 {
     this._engine   = engine;
     this._provider = provider;
 }
Beispiel #14
0
 public FunctionBuilder(IHandlebarsEngine engine)
 {
     _engine = engine;
 }
 public CompilationContext(IHandlebarsEngine engine)
 {
     Engine         = engine;
     BindingContext = Expression.Variable(typeof(BindingContext), "context");
 }
 public DevelopmentHandlebarsTemplate(IHandlebarsEngine engine,
                                      IHandlebarsResourceProvider provider)
 {
     this._engine = engine;
     this._provider = provider;
 }
 public StandardHandlebarsTemplate(IHandlebarsEngine engine,
                                   IHandlebarsResourceProvider provider)
 {
     this._engine = engine;
     this._provider = provider;
 }
Beispiel #18
0
 public StandardHandlebarsTemplate(IHandlebarsEngine engine,
                                   IHandlebarsResourceProvider provider)
 {
     this._engine   = engine;
     this._provider = provider;
 }