public static async Task RenderAsync(this LiquidViewTemplate template, TextWriter writer, TextEncoder encoder, LiquidTemplateContext context, object model, Action <Scope> scopeAction)
        {
            try
            {
                await context.EnterScopeAsync(model, scopeAction);

                await template.RenderAsync(writer, encoder, context);
            }
            finally
            {
                context.ReleaseScope();
            }
        }
        public static async Task <string> RenderAsync(this LiquidViewTemplate template, TextEncoder encoder, LiquidTemplateContext context, object model, Action <Scope> scopeAction)
        {
            try
            {
                await context.EnterScopeAsync(model, scopeAction);

                return(await template.RenderAsync(context, encoder));
            }
            finally
            {
                context.ReleaseScope();
            }
        }
예제 #3
0
        private LiquidViewTemplate GetCachedTemplate(string source)
        {
            var errors = Enumerable.Empty <string>();

            var result = _memoryCache.GetOrCreate(source, (ICacheEntry e) =>
            {
                if (!LiquidViewTemplate.TryParse(source, out var parsed, out errors))
                {
                    // If the source string cannot be parsed, create a template that contains the parser errors
                    LiquidViewTemplate.TryParse(String.Join(System.Environment.NewLine, errors), out parsed, out errors);
                }

                // Define a default sliding expiration to prevent the
                // cache from being filled and still apply some micro-caching
                // in case the template is use commonly
                e.SetSlidingExpiration(TimeSpan.FromSeconds(30));
                return(parsed);
            });
예제 #4
0
        public Task RenderAsync(string source, TextWriter textWriter, TextEncoder encoder, TemplateContext context)
        {
            if (String.IsNullOrWhiteSpace(source))
            {
                return(Task.CompletedTask);
            }

            var errors = Enumerable.Empty <string>();

            var result = _memoryCache.GetOrCreate(source, (ICacheEntry e) =>
            {
                if (LiquidViewTemplate.TryParse(source, out var parsed, out errors))
                {
                    // Define a default sliding expiration to prevent the
                    // cache from being filled and still apply some micro-caching
                    // in case the template is use commonly
                    e.SetSlidingExpiration(TimeSpan.FromSeconds(30));
                    return(parsed);
                }