Exemple #1
0
        public async Task Json(object value, string expected)
        {
            var input = FluidValue.Create(value, TemplateOptions.Default);

            var arguments = new FilterArguments();
            var context   = new TemplateContext();

            var result = await MiscFilters.Json(input, arguments, context);

            Assert.Equal(expected, result.ToStringValue());
        }
Exemple #2
0
        public void Json(object value, string expected)
        {
            var input = FluidValue.Create(value);

            var arguments = new FilterArguments();
            var context   = new TemplateContext();

            var result = MiscFilters.Json(input, arguments, context);

            Assert.Equal(expected, result.ToStringValue());
        }
        public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext context)
        {
            var content = input.ToObjectValue();

            if (content == null || _hostEnvironment.IsProduction())
            {
                return(NilValue.Instance);
            }

            using var sb = ZString.CreateStringBuilder();
            sb.Append("<script>console.log(");

            if (content is string stringContent)
            {
                sb.Append("\"");
                sb.Append(stringContent);
                sb.Append("\"");
            }
            else if (content is JToken jTokenContent)
            {
                sb.Append(jTokenContent.ToString());
            }
            else if (content is ContentItem contentItem)
            {
                sb.Append(OrchardRazorHelperExtensions.ConvertContentItem(contentItem).ToString());
            }
            else if (content is IShape shape)
            {
                sb.Append(shape.ShapeToJson().ToString());
            }
            else
            {
                sb.Append((await MiscFilters.Json(input, arguments, context)).ToStringValue());
            }

            sb.Append(")</script>");

            var result = new StringValue(sb.ToString(), false);

            return(result);
        }