public static async ValueTask <string> RenderAsync(this IFluidTemplate template, TemplateContext context, TextEncoder encoder)
        {
            if (context == null)
            {
                ExceptionHelper.ThrowArgumentNullException(nameof(context));
            }

            if (template == null)
            {
                ExceptionHelper.ThrowArgumentNullException(nameof(template));
            }

            var sb     = StringBuilderPool.GetInstance();
            var writer = new StringWriter(sb.Builder);

            // A template is evaluated in a child scope such that the provided TemplateContext is immutable
            context.EnterChildScope();

            try
            {
                await template.RenderAsync(writer, encoder, context);

                writer.Flush();
                return(sb.ToString());
            }
            finally
            {
                sb.Dispose();
                writer.Dispose();
                context.ReleaseScope();
            }
        }
Example #2
0
        protected virtual void SetCachedTemplate(string path, IFluidTemplate template)
        {
            _cache[path] = template;

            //// Default sliding expiration to prevent the entries for being kept indefinitely
            //viewEntry.SlidingExpiration = TimeSpan.FromHours(1);

            //viewEntry.ExpirationTokens.Add(fileProvider.Watch(path));
        }
        public static void Render(this IFluidTemplate template, TemplateContext context, TextEncoder encoder, TextWriter writer)
        {
            var task = template.RenderAsync(writer, encoder, context);

            if (!task.IsCompletedSuccessfully)
            {
                task.AsTask().GetAwaiter().GetResult();
            }
        }
Example #4
0
        public static ValueTask <string> RenderAsync(this IFluidTemplate template, TemplateContext context, TextEncoder encoder)
        {
            if (context == null)
            {
                ExceptionHelper.ThrowArgumentNullException(nameof(context));
            }

            if (template == null)
            {
                ExceptionHelper.ThrowArgumentNullException(nameof(template));
            }
Example #5
0
 private void ProcessTemplate(IFluidTemplate template, ExtractingLiquidWalker visitor, string path)
 {
     if (template is CompositeFluidTemplate compositeTemplate)
     {
         foreach (var innerTemplate in compositeTemplate.Templates)
         {
             ProcessTemplate(innerTemplate, visitor, path);
         }
     }
     else if (template is FluidTemplate singleTemplate)
     {
         ProcessTemplate(singleTemplate, visitor, path);
     }
 }
Example #6
0
        public static async Task <string> RenderAsync(this IFluidTemplate template, TemplateContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            using (var writer = new StringWriter())
            {
                await template.RenderAsync(writer, HtmlEncoder.Default, context);

                return(writer.ToString());
            }
        }
Example #7
0
 public static bool TryParse(this FluidParser parser, string template, out IFluidTemplate result, out string error)
 {
     try
     {
         error  = null;
         result = parser.Parse(template);
         return(true);
     }
     catch (ParseException e)
     {
         error  = e.Message;
         result = null;
         return(false);
     }
     catch (Exception e)
     {
         error  = e.Message;
         result = null;
         return(false);
     }
 }
        public static async Task <string> RenderAsync(this IFluidTemplate template, TextEncoder encoder, TemplateContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            using (var sb = StringBuilderPool.GetInstance())
            {
                using (var writer = new StringWriter(sb.Builder))
                {
                    await template.RenderAsync(writer, encoder, context);

                    return(writer.ToString());
                }
            }
        }
 public static string Render(this IFluidTemplate template, TemplateContext context)
 {
     return(template.RenderAsync(context).GetAwaiter().GetResult());
 }
Example #10
0
 public static bool TryParse(this FluidParser parser, string template, out IFluidTemplate result)
 {
     return(parser.TryParse(template, out result, out _));
 }
Example #11
0
        public static string Render(this IFluidTemplate template)
        {
            var task = template.RenderAsync();

            return(task.IsCompletedSuccessfully ? task.Result : task.AsTask().GetAwaiter().GetResult());
        }
Example #12
0
 protected virtual bool TryGetCachedTemplate(string path, out IFluidTemplate template)
 {
     return(_cache.TryGetValue(path, out template));
 }
Example #13
0
 public LiquidViewTemplate(IFluidTemplate fluidTemplate)
 {
     FluidTemplate = fluidTemplate;
 }
 public static void Render(this IFluidTemplate template, TextWriter writer, TextEncoder encoder, TemplateContext context)
 {
     template.RenderAsync(writer, encoder, context).GetAwaiter().GetResult();
 }
 public static string Render(this IFluidTemplate template)
 {
     return(template.RenderAsync().GetAwaiter().GetResult());
 }
 public static Task <string> RenderAsync(this IFluidTemplate template)
 {
     return(template.RenderAsync(new TemplateContext()));
 }
Example #17
0
        public static string Render(this IFluidTemplate template, TemplateContext context, TextEncoder encoder)
        {
            var task = template.RenderAsync(context, encoder);

            return(task.IsCompletedSuccessfully ? task.Result : task.AsTask().GetAwaiter().GetResult());
        }
 public static Task <string> RenderAsync(this IFluidTemplate template, TemplateContext context)
 {
     return(template.RenderAsync(HtmlEncoder.Default, context));
 }
 public static ValueTask <string> RenderAsync(this IFluidTemplate template, TemplateContext context)
 {
     return(template.RenderAsync(context, NullEncoder.Default));
 }
Example #20
0
 public TestCase(string source)
 {
     _source   = source;
     _template = _parser.Parse(source);
 }