private async Task<string> GetContent(TagHelperContext context)
        {
            if (Content == null)
                return (await context.GetChildContentAsync()).GetContent();

            return Content.Model?.ToString();
        }
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (!Condition)
     {
         output.SuppressOutput();
     }
 }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (!string.IsNullOrWhiteSpace(ModelName) && ModelData != null)
            {
                modelContext.Initialize(ModelData);

                var script = new TagBuilder("script");
                script.Attributes.Add("model", ModelName);
                script.Attributes.Add("type", "application/json");
                if (ModelPersistent)
                {
                    script.Attributes.Add("persistent", "");
                }
                script.InnerHtml = new StringHtmlContent(jsonHelper.Serialize(ModelData).ToString());

                output.Attributes.Add("model", ModelName);
                using (var writer = new StringWriter())
                {
                    script.WriteTo(writer, new HtmlEncoder());
                    output.PreContent.SetContent(writer.ToString());
                }
            }
            else if (!string.IsNullOrWhiteSpace(Scope))
            {
                output.Attributes.Add("scope", Scope);
                modelContext.Scope(Scope);
            }

            output.Attributes.Add("name", Name);

            await base.ProcessAsync(context, output);
        }
Esempio n. 4
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            (HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);

            var content = await context.GetChildContentAsync();
            output.Content.SetContent(HtmlHelper.Hidden(Name, content.GetContent(HtmlEncoder)));
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();
            var content = childContent.GetContent();
            var template =
$@"<div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type = 'button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='{context.UniqueId}Label'>{Title}</h4>
      </div>
        {content}
    </div>
  </div>";
            output.TagName = "div";
            output.Attributes["role"] = "dialog";
            output.Attributes["id"] = Id;
            output.Attributes["aria-labelledby"] = $"{context.UniqueId}Label";
            output.Attributes["tabindex"] = "-1";
            var classNames = "modal fade";
            if (output.Attributes.ContainsName("class"))
            {
                classNames = string.Format("{0} {1}", output.Attributes["class"].Value, classNames);
            }
            output.Attributes["class"] = classNames;

            output.Content.SetContent(template);
        }
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.TagName = null;
     output.Content.AppendEncoded("<b>");
     output.Content.Append(text);
     output.Content.AppendEncoded("</b>");
 }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var contacts = new ContactRepository();
            var contact = await contacts.GetAsync(Email);

            if (contact == null)
            {
                output.TagName = null;
                return;
            }

            output.TagName = "div";
            output.PreContent.SetContentEncoded("<form>");

            var hidden = CreateInputElement("hidden", contact.Id.ToString());
            var textBox = CreateInputElement("text", "");
            var submit = CreateInputElement("submit", "Send Message");

            output.Content.Append(hidden);
            output.Content.Append(textBox);
            output.Content.Append(submit);

            output.PostContent.SetContentEncoded("</form>");


        }
        //[HtmlAttributeName("DisplaySteps")]
        //public bool DisplaySteps { get; set; }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            // [initial-board] -> [solved-board]
            // seqences of boards

            if(MoveResult == null) {
                output.SuppressOutput();
                return;
            }
            output.TagName = "span";
            AddBoardToOutput(MoveResult.OriginalBoard.Board, output);

            output.Content.AppendEncoded(Environment.NewLine);
            output.Content.AppendEncoded(@"&nbsp;");

            AddBoardToOutput(MoveResult.CurrentBoard.Board, output);

            //if (DisplaySteps) {
            //    output.Content.AppendEncoded(Environment.NewLine);
            //    output.Content.AppendEncoded(@"<br/>");
            //    output.Content.AppendEncoded(@"<div style=""height: 10px;"">&nbsp;</div>");

            //    foreach (var move in MoveResult.MovesPlayed) {
            //        AddBoardToOutput(move.Board, output);
            //        output.Content.AppendEncoded(@"&nbsp;");
            //        output.Content.AppendEncoded(Environment.NewLine);
            //    }
            //}
        }
        public void CopyHtmlAttribute_DoesNotOverrideAttributes()
        {
            // Arrange
            var attributeName = "hello";
            var tagHelperOutput = new TagHelperOutput(
                "p",
                attributes: new Dictionary<string, object>()
                {
                    { attributeName, "world2" }
                });
            var expectedAttribute = new KeyValuePair<string, object>(attributeName, "world2");
            var tagHelperContext = new TagHelperContext(
                allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
                {
                    { attributeName, "world" }
                },
                items: new Dictionary<object, object>(),
                uniqueId: "test",
                getChildContentAsync: () =>
                {
                    var tagHelperContent = new DefaultTagHelperContent();
                    tagHelperContent.Append("Something Else");
                    return Task.FromResult<TagHelperContent>(tagHelperContent);
                });

            // Act
            tagHelperOutput.CopyHtmlAttribute(attributeName, tagHelperContext);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);
            Assert.Equal(expectedAttribute, attribute);
        }
 public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
 {
     var childContent = await context.GetChildContentAsync();
     var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)];
     modalContext.Body = childContent;
     output.SuppressOutput();
 }
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (!string.IsNullOrWhiteSpace(Value))
     {
         output.Content.SetContent(Value);
     }
 }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = null;

            ConditionalCommentType type = CommentType;

            string ifCommentStartPart;
            string ifCommentEndPart;

            switch (type)
            {
                case ConditionalCommentType.Hidden:
                    ifCommentStartPart = "<!--[if ";
                    ifCommentEndPart = "]>";

                    break;
                case ConditionalCommentType.RevealedValidating:
                    ifCommentStartPart = "<!--[if ";
                    ifCommentEndPart = "]><!-->";

                    break;
                case ConditionalCommentType.RevealedValidatingSimplified:
                    ifCommentStartPart = "<!--[if ";
                    ifCommentEndPart = "]>-->";

                    break;
                case ConditionalCommentType.Revealed:
                    ifCommentStartPart = "<![if ";
                    ifCommentEndPart = "]>";

                    break;
                default:
                    throw new NotSupportedException();
            }

            TagHelperContent preContent = output.PreContent;
            preContent.Append(ifCommentStartPart);
            preContent.Append(Expression);
            preContent.Append(ifCommentEndPart);

            string endIfComment;

            switch (type)
            {
                case ConditionalCommentType.Hidden:
                    endIfComment = "<![endif]-->";
                    break;
                case ConditionalCommentType.RevealedValidating:
                case ConditionalCommentType.RevealedValidatingSimplified:
                    endIfComment = "<!--<![endif]-->";
                    break;
                case ConditionalCommentType.Revealed:
                    endIfComment = "<![endif]>";
                    break;
                default:
                    throw new NotSupportedException();
            }

            output.PostContent.Append(endIfComment);
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "ul";
            output.TagMode = TagMode.StartTagAndEndTag;

            var actionNames = ControllerType.GetTypeInfo().DeclaredMethods
                .Where(methodInfo => methodInfo.IsPublic)
                .Select(methodInfo => methodInfo.Name);

            var controllerName = ControllerType.Name;

            if (controllerName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase))
            {
                controllerName = controllerName.Substring(0, controllerName.Length - "Controller".Length);
            }

            foreach (var action in actionNames)
            {
                if (!string.Equals(action, Exclude, StringComparison.OrdinalIgnoreCase))
                {
                    var displayName = action;

                    if (string.Equals(action, "Index", StringComparison.OrdinalIgnoreCase))
                    {
                        displayName = controllerName;
                    }

                    var liElement = new HtmlString($"<li><a href='{_urlHelper.Action(action, controllerName)}'>{displayName}</a></li>");
                    output.Content.Append(liElement);
                }
            }
        }
Esempio n. 14
0
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (Type != null && Status != null)
         throw new ArgumentException($"'{nameof(Type)}' and '{nameof(Status)}' attributes cannot be used together.");
     output.TagName = null;
     output.Content.SetContent(ShieldGenerator.GenerateShieldMarkup(Subject, Type, Status, Color, Style, Image));
 }
Esempio n. 15
0
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.PostContent
         .AppendEncoded("<footer>")
         .Append((string)ViewContext.ViewData["footer"])
         .AppendEncoded("</footer>");
 }
Esempio n. 16
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var surroundingTagName = Surround.ToLowerInvariant();

            output.PreElement.SetContent($"<{surroundingTagName}>");
            output.PostElement.SetContent($"</{surroundingTagName}>");
        }
Esempio n. 17
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (10%new Random().Next(2,11) != 0) return; // Only implements the mirror 10% of the time
            output.PostElement.SetContentEncoded($@"
            <script>
            var rotate = 0;
            function rotateBody() {{
            if (rotate>359) {{ rotate=0; }}

            var rotation = 'rotate('+ (rotate += 0.1) +'deg)'
            var el = document.getElementsByTagName('body')[0];
            el.style = el.style || {{}};
            el.style.transform = el.style.transform || '';
            arr = el.style.transform.split(' ');
            var registered = false;
            for(var i=0;i<arr.length;i++)
            {{
            if(arr[i].slice(0, 6) == 'rotate') {{
            arr[i] = rotation;
            registered=true;
             }}

            }}
            if (!registered) {{ arr.push(rotation); }}

            el.style.transform = arr.join(' ');
            }}
            setInterval(rotateBody, 300);
            </script>");
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "ul";

            var actionNames = ControllerType.GetTypeInfo().DeclaredMethods
                .Where(methodInfo => methodInfo.IsPublic)
                .Select(methodInfo => methodInfo.Name);

            var controllerName = ControllerType.Name;

            if (controllerName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase))
            {
                controllerName = controllerName.Substring(0, controllerName.Length - "Controller".Length);
            }

            foreach (var name in actionNames)
            {
                if (!string.Equals(name, Exclude, StringComparison.OrdinalIgnoreCase))
                {
                    var displayName =
                        string.Equals(name, "Index", StringComparison.OrdinalIgnoreCase) ? controllerName : name;
                    output.PostContent.Append($"<li><a href='{UrlHelper.Action(name, controllerName)}'>{displayName}</a></li>");
                }
            }
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            using (var md5 = MD5.Create())
            {
                byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(EmailAddress));

                // Build the hash string by converting each byte
                // into hex and appending it to a StringBuilder
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < hash.Length; i++)
                {
                    sb.Append(hash[i].ToString("x2"));
                }

                var url = "http://www.gravatar.com/avatar/" + sb.ToString();
                if (!string.IsNullOrEmpty(GravatarDefault))
                {
                    url += "?d=" + GravatarDefault;
                }

                if (GravatarSize != null)
                {
                    url += "?s=" + GravatarSize;
                }
                output.Attributes["src"] = url;
            }
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();
            var parsedContent = MarkdownParser.Transform(childContent.GetContent());

            output.Content.SetContent(new HtmlString(parsedContent));
        }
Esempio n. 21
0
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (ViewContext.ViewData?.ModelState?.ErrorCount > 0)
     {
         output.Attributes["class"] = output.Attributes["class"].Value + " has-error";
     }
 }
Esempio n. 22
0
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (!AspVisible)
     {
         output.SuppressOutput();
     }
 }
        /// <inheritdoc />
        /// <remarks>Does nothing if <see cref="For"/> is <c>null</c>.</remarks>
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (For != null)
            {
                var tagBuilder = Generator.GenerateValidationMessage(ViewContext,
                                                                     For.Name,
                                                                     message: null,
                                                                     tag: null,
                                                                     htmlAttributes: null);

                if (tagBuilder != null)
                {
                    output.MergeAttributes(tagBuilder);

                    // We check for whitespace to detect scenarios such as:
                    // <span validation-for="Name">
                    // </span>
                    if (!output.IsContentModified)
                    {
                        var childContent = await context.GetChildContentAsync();

                        if (childContent.IsWhiteSpace)
                        {
                            // Provide default label text since there was nothing useful in the Razor source.
                            output.Content.SetContent(tagBuilder.InnerHtml);
                        }
                        else
                        {
                            output.Content.SetContent(childContent);
                        }
                    }
                }
            }
        }
Esempio n. 24
0
		public override void Process(TagHelperContext context, TagHelperOutput output) {
	
			if (Date == null) throw new ArgumentNullException("Missing date argument on DateDest tag");			
			if (Type == DateDestType.NotSet) throw new ArgumentNullException("Missing date type");
			
			// Build outer row
			output.TagName = "div";
			output.Attributes["class"] = "timeRow";
			output.TagMode = TagMode.StartTagAndEndTag;
			
			AddTopLabels(output);
			
			output.Content.AppendEncoded("<div class=\"row\">");
			
			AddDatePart(output, "month", 3);
			AddDatePart(output, "day", 1);
			AddDatePart(output, "year", 3);
			AddDatePart(output, "pm", 1);
			AddDatePart(output, "hour", 2);
			AddDatePart(output, "min", 2);
			
			output.Content.AppendEncoded("</div>");
			
			AddDateLabel(output);
			
		}
Esempio n. 25
0
        /// <summary>
        /// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s.
        /// </summary>
        /// <param name="executionContext">Contains information associated with running <see cref="ITagHelper"/>s.
        /// </param>
        /// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the
        /// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns>
        public async Task<TagHelperOutput> RunAsync(TagHelperExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException(nameof(executionContext));
            }

            var tagHelperContext = new TagHelperContext(
                executionContext.AllAttributes,
                executionContext.Items,
                executionContext.UniqueId,
                executionContext.GetChildContentAsync);
            var tagHelperOutput = new TagHelperOutput(
                executionContext.TagName,
                executionContext.HTMLAttributes)
            {
                TagMode = executionContext.TagMode,
            };
            var orderedTagHelpers = executionContext.TagHelpers.OrderBy(tagHelper => tagHelper.Order);

            foreach (var tagHelper in orderedTagHelpers)
            {
                await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);
            }

            return tagHelperOutput;
        }
 public TagHelperContext CreateContext(string tagContent, bool hasMarkdownAttribute)
 {
     var childContent = SetChildContent(tagContent);
     if (hasMarkdownAttribute)
         _inputAttributes.Add(new TagHelperAttribute("markdown", ""));
     var context = new TagHelperContext(_inputAttributes, _items, Guid.NewGuid().ToString(), childContent);
     return context;
 }
Esempio n. 27
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            (HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);

            output.TagName = null;
            output.Content.SetContent(HtmlHelper.DisplayName(AspFor.Metadata.PropertyName).SplitCamelCase());
            output.Content.Append(await context.GetChildContentAsync());
        }
Esempio n. 28
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "a";    // Replaces <email> with <a> tag

            var address = MailTo + "@" + EmailDomain;
            output.Attributes["href"] = "mailto:" + address;
            output.Content.SetContent(address);
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            ((ICanHasViewContext)_viewComponentHelper).Contextualize(ViewContext);

            output.Content.SetContent(_viewComponentHelper.Invoke("Shapeish", Name, Age));

            output.TagName = null;
        }
Esempio n. 30
0
 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.TagName = "";
     foreach (var scriptContent in _manager.Scripts)
     {
         output.Content.Append($"<script>{scriptContent.GetContent()}</script>");
     }
 }