Exemplo n.º 1
0
        protected override string GetReactContent(ReactArtifactContext context)
        {
            var classContent          = context.ChildrenReactContent;
            var classContentDefintion =
                $"class {this.ClassName} extends React.Component {{{classContent}}}";

            return(classContentDefintion);
        }
 protected override string GetRazorContent(ReactArtifactContext context)
 {
     if (this.TargetId == null)
     {
         return($@"<div id=""{this.FinalTargetId}""></div>");
     }
     return(base.GetRazorContent(context));
 }
        protected override string GetReactContent(ReactArtifactContext context)
        {
            var componentTag = RenderComponentTag(context.TagHelperContext, this.ClassName);

            return($@"ReactDOM.render(
{componentTag},
document.getElementById('{this.FinalTargetId}'));");
        }
        protected override string GetReactContent(ReactArtifactContext context)
        {
            var modified = $@"
render()
{{
    return (
{WebUtility.HtmlDecode(context.ChildrenRenderContent)}
            );
}}";

            return(modified);
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var reactContext = this.ReactRenderContext();

            if (!this.Initialize(reactContext))
            {
                output.SuppressOutput();
                output.Content.SetContent(string.Empty);
                output.TagName = null;
                return;
            }


            string childrenRenderContent;
            string childrenReactContent = null;

            using (reactContext.AddScope(this))
                using (this.Process(c => childrenReactContent += c))
                {
                    childrenRenderContent =
                        (await output.GetChildContentAsync(NullHtmlEncoder.Default))
                        .GetContent(NullHtmlEncoder.Default);
                }


            var artifactContext = new ReactArtifactContext
            {
                ReactContext          = reactContext,
                TagHelperContext      = context,
                TagHelperOutput       = output,
                ChildrenReactContent  = childrenReactContent,
                ChildrenRenderContent = childrenRenderContent,
            };

            var reactContent = this.GetReactContent(artifactContext);

            reactContent = reactContent.Indent(reactContext.Scope.Count, '\t');
            reactContext.AddReactContent(this, reactContent);

            var razorContent = this.GetRazorContent(artifactContext) ?? string.Empty;

            // output.PreElement.SetHtmlContent(new HtmlString(razorContent)); // default content
            output.Content.SetHtmlContent(new HtmlString(razorContent));
            output.TagName = null;
        }
 protected virtual string GetRazorContent(ReactArtifactContext context)
 {
     return(null);
 }
 protected virtual string GetReactContent(ReactArtifactContext context)
 {
     return(context.ChildrenReactContent);
 }