Exemple #1
0
        public static string ToString(Microsoft.AspNetCore.Html.IHtmlContent content)
        {
            var writer = new System.IO.StringWriter();

            content.WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
            return(writer.ToString());
        }
Exemple #2
0
        public void Is(string expected, IHtmlString result, string message = null)
        {
            //var resultStr = result.ToString();
            //int index = expected.Zip(resultStr, (c1, c2) => c1 == c2).TakeWhile(b => b).Count() + 1;

            //Assert.AreEqual(expected, resultStr, message + $"(pos: {index}");
            Is(expected, result.ToString(), message);
        }
        /// <summary>
        /// Processes the tag helper
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="output">Output</param>
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            SetTag(output);

            IHtmlHelper htmlHelper  = ViewContext.GetService <IHtmlHelper>();
            HtmlEncoder htmlEncoder = ViewContext.GetService <HtmlEncoder>();

            (htmlHelper as IViewContextAware).Contextualize(ViewContext);

            Microsoft.AspNetCore.Html.IHtmlContent partial = await htmlHelper.PartialAsync(GetView(), await GetViewModelAsync());

            var writer = new StringWriter();

            partial.WriteTo(writer, htmlEncoder);
            output.Content.SetHtmlContent(writer.ToString());
        }
        /// <summary>
        /// Process
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="output">Output</param>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

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

            //clear the output
            output.SuppressOutput();

            //generate antiforgery
            Microsoft.AspNetCore.Html.IHtmlContent antiforgeryTag = Generator.GenerateAntiforgery(ViewContext);
            if (antiforgeryTag != null)
            {
                output.Content.SetHtmlContent(antiforgeryTag);
            }
        }
Exemple #5
0
        /// <summary>
        /// Process
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="output">Output</param>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

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

            //clear the output
            output.SuppressOutput();

            //container for additional attributes
            Dictionary <string, object> htmlAttributes = new Dictionary <string, object>();

            //disabled attribute
            bool.TryParse(IsDisabled, out bool disabled);
            if (disabled)
            {
                htmlAttributes.Add("disabled", "disabled");
            }

            //required asterisk
            bool.TryParse(IsRequired, out bool required);
            if (required)
            {
                output.PreElement.SetHtmlContent("<div class='input-group input-group-required'>");
                output.PostElement.SetHtmlContent("<div class=\"input-group-btn\"><span class=\"required\">*</span></div></div>");
            }

            //contextualize IHtmlHelper
            IViewContextAware viewContextAware = _htmlHelper as IViewContextAware;

            viewContextAware?.Contextualize(ViewContext);

            //add form-control class
            bool.TryParse(RenderFormControlClass, out bool renderFormControlClass);
            if (string.IsNullOrEmpty(RenderFormControlClass) && For.Metadata.ModelType.Name.Equals("String") || renderFormControlClass)
            {
                htmlAttributes.Add("class", "form-control");
            }

            //generate editor

            //we have to invoke strong typed "EditorFor" method of HtmlHelper<TModel>
            //but we cannot do it because we don't have access to Expression<Func<TModel, TValue>>
            //more info at https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelperOfT.cs

            //so we manually invoke implementation of "GenerateEditor" method of HtmlHelper
            //more info at https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs

            //little workaround here. we need to access private properties of HtmlHelper
            //just ensure that they are not renamed by asp.net core team in future versions
            IViewEngine      viewEngine      = CommonHelper.GetPrivateFieldValue(_htmlHelper, "_viewEngine") as IViewEngine;
            IViewBufferScope bufferScope     = CommonHelper.GetPrivateFieldValue(_htmlHelper, "_bufferScope") as IViewBufferScope;
            TemplateBuilder  templateBuilder = new TemplateBuilder(
                viewEngine,
                bufferScope,
                _htmlHelper.ViewContext,
                _htmlHelper.ViewData,
                For.ModelExplorer,
                For.Name,
                Template,
                readOnly: false,
                additionalViewData: new { htmlAttributes, postfix = this.Postfix });

            Microsoft.AspNetCore.Html.IHtmlContent htmlOutput = templateBuilder.Build();
            output.Content.SetHtmlContent(htmlOutput.RenderHtmlContent());
        }
 protected bool TryResolveUrl(string url, out Microsoft.AspNetCore.Html.IHtmlContent resolvedUrl)
 {
     throw null;
 }
 public Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContent SetHtmlContent(Microsoft.AspNetCore.Html.IHtmlContent htmlContent)
 {
     throw null;
 }
 Microsoft.AspNetCore.Html.IHtmlContentBuilder Microsoft.AspNetCore.Html.IHtmlContentBuilder.AppendHtml(Microsoft.AspNetCore.Html.IHtmlContent content)
 {
     throw null;
 }
 public abstract Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContent AppendHtml(Microsoft.AspNetCore.Html.IHtmlContent htmlContent);
 public override Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContent AppendHtml(Microsoft.AspNetCore.Html.IHtmlContent htmlContent)
 {
     throw null;
 }
 public static Microsoft.AspNetCore.Html.IHtmlContentBuilder SetHtmlContent(this Microsoft.AspNetCore.Html.IHtmlContentBuilder builder, Microsoft.AspNetCore.Html.IHtmlContent content)
 {
     throw null;
 }
 public Microsoft.AspNetCore.Html.IHtmlContentBuilder AppendHtml(Microsoft.AspNetCore.Html.IHtmlContent htmlContent)
 {
     throw null;
 }
Exemple #13
0
 public static Microsoft.AspNetCore.Html.IHtmlContentBuilder AppendLine(this Microsoft.AspNetCore.Html.IHtmlContentBuilder builder, Microsoft.AspNetCore.Html.IHtmlContent content) => throw null;