Пример #1
0
        /// <inheritdoc />
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            TagHelperContent result = null;

            if (Enabled)
            {
                var key = GenerateKey(context);
                if (!MemoryCache.TryGetValue(key, out result))
                {
                    // Create an entry link scope and flow it so that any triggers related to the cache entries
                    // created within this scope get copied to this scope.
                    using (var link = MemoryCache.CreateLinkingScope())
                    {
                        result = await context.GetChildContentAsync();

                        MemoryCache.Set(key, result, GetMemoryCacheEntryOptions(link));
                    }
                }
            }

            // Clear the contents of the "cache" element since we don't want to render it.
            output.SuppressOutput();
            if (Enabled)
            {
                output.Content.SetContent(result);
            }
            else
            {
                result = await context.GetChildContentAsync();

                output.Content.SetContent(result);
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        /// <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)
            {
                if (output.ContentSet)
                {
                    var childContent = await context.GetChildContentAsync();

                    if (!string.IsNullOrWhiteSpace(childContent))
                    {
                        output.Content = childContent;
                    }
                    else
                    {
                        output.Content = GetContainer(context, output);
                    }
                }
                else
                {
                    output.Content = GetContainer(context, output);
                }


                //var tagBuilder = Generator.GenerateLabel(ViewContext,
                //                                         For.Metadata,
                //                                         For.Name,
                //                                         labelText: null,
                //                                         htmlAttributes: null);
            }
        }
Пример #4
0
        /// <inheritdoc />
        /// <remarks>Does nothing if <see cref="For"/> is <c>null</c>.</remarks>
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var tagBuilder = Generator.GenerateLabel(
                ViewContext,
                For.ModelExplorer,
                For.Name,
                labelText: null,
                htmlAttributes: null);

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

                // We check for whitespace to detect scenarios such as:
                // <label for="Name">
                // </label>
                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);
                    }
                }
            }
        }
Пример #5
0
        /// <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.ContentSet)
                    {
                        var childContent = await context.GetChildContentAsync();

                        if (string.IsNullOrWhiteSpace(childContent))
                        {
                            // Provide default label text since there was nothing useful in the Razor source.
                            output.Content = tagBuilder.InnerHtml;
                        }
                        else
                        {
                            output.Content = childContent;
                        }
                    }
                }
            }
        }
Пример #6
0
        /// <inheritdoc />
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var    key = GenerateKey(context);
            string result;

            if (!MemoryCache.TryGetValue(key, out result))
            {
                // Create an EntryLink and flow it so that it is accessible via the ambient EntryLinkHelpers.ContentLink
                // for user code.
                var entryLink = new EntryLink();
                using (entryLink.FlowContext())
                {
                    result = await context.GetChildContentAsync();
                }

                MemoryCache.Set(key, cacheSetContext =>
                {
                    UpdateCacheContext(cacheSetContext, entryLink);
                    return(result);
                });
            }

            // Clear the contents of the "cache" element since we don't want to render it.
            output.SuppressOutput();

            output.Content = result;
        }
Пример #7
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());
        }
Пример #8
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));
        }
Пример #9
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            for (var i = 0; i < this.Count; i++)
            {
                var html = await context.GetChildContentAsync(false);

                output.Content.Append(html);
            }
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            for (int i = 0; i < Count; i++)
            {
                output.Content.Append(await context.GetChildContentAsync());
            }

            output.TagName = null;
        }
Пример #11
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();

            var parsedContent = MarkdownParser.Transform(childContent.GetContent());

            output.Content.SetContentEncoded(parsedContent);

            output.Attributes.RemoveAll("markdown");
        }
Пример #12
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();

            // Find Urls in the content and replace them with their anchor tag equivalent.
            output.Content.AppendEncoded(Regex.Replace(
                                             childContent.GetContent(),
                                             @"\b(?:https?://|www\.)(\S+)\b",
                                             "<strong><a target=\"_blank\" href=\"http://$0\">$0</a></strong>"));
        }
Пример #13
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();

            // Find Urls in the content and replace them with their anchor tag equivalent.
            output.Content.SetContent(Regex.Replace(
                                          childContent.GetContent(),
                                          @"\b(?:https?://)(\S+)\b",
                                          "<a target=\"_blank\" href=\"$0\">$0</a>")); // http link version}
        }
Пример #14
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "a";    // Replaces <email> with <a> tag
            var content = await context.GetChildContentAsync();

            var target = content.GetContent() + "@" + EmailDomain;

            output.Attributes["href"] = "mailto:" + target;
            output.Content.SetContent(target);
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var    childContent = context.GetChildContentAsync().Result;
            string demoContent  = childContent.GetContent();
            string demo         = context.AllAttributes["asp-custom"].ToString();

            output.TagName = "div";
            output.Attributes.Clear();
            output.Attributes["data-custom"] = demo;
            output.Content.SetContent(demoContent);
        }
Пример #16
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = output.Content.IsModified ? output.Content.GetContent() :
                               (await context.GetChildContentAsync()).GetContent();

            // Find Urls in the content and replace them with their anchor tag equivalent.
            output.Content.SetContent(Regex.Replace(
                                          childContent,
                                          @"\b(www\.)(\S+)\b",
                                          "<a target=\"_blank\" href=\"http://$0\">$0</a>")); // www version
        }
Пример #17
0
        /// <inheritdoc />
        /// <remarks>
        /// Does nothing unless <see cref="FormContext.FormData"/> contains a
        /// <see cref="SelectTagHelper.SelectedValuesFormDataKey"/> entry and that entry is a non-empty
        /// <see cref="ICollection{string}"/> instance. Also does nothing if the associated &lt;option&gt; is already
        /// selected.
        /// </remarks>
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            // Pass through attributes that are also well-known HTML attributes.
            if (Value != null)
            {
                output.CopyHtmlAttribute(nameof(Value), context);
            }

            // Nothing to do if this <option/> is already selected.
            if (!output.Attributes.ContainsName("selected"))
            {
                // Is this <option/> element a child of a <select/> element the SelectTagHelper targeted?
                object formDataEntry;
                ViewContext.FormContext.FormData.TryGetValue(
                    SelectTagHelper.SelectedValuesFormDataKey,
                    out formDataEntry);

                // ... And did the SelectTagHelper determine any selected values?
                var selectedValues = formDataEntry as ICollection <string>;
                if (selectedValues != null && selectedValues.Count != 0)
                {
                    // Encode all selected values for comparison with element content.
                    var encodedValues = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                    foreach (var selectedValue in selectedValues)
                    {
                        encodedValues.Add(Generator.Encode(selectedValue));
                    }

                    // Select this <option/> element if value attribute or content matches a selected value. Callers
                    // encode values as-needed while executing child content. But TagHelperOutput itself
                    // encodes attribute values later, when start tag is generated.
                    bool selected;
                    if (Value != null)
                    {
                        selected = selectedValues.Contains(Value);
                    }
                    else if (output.IsContentModified)
                    {
                        selected = encodedValues.Contains(output.Content.GetContent());
                    }
                    else
                    {
                        var childContent = await context.GetChildContentAsync();

                        selected = encodedValues.Contains(childContent.GetContent());
                    }

                    if (selected)
                    {
                        output.Attributes.Add("selected", "selected");
                    }
                }
            }
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var classValue      = context.AllAttributes["class"].Value;
            var existingContent = await context.GetChildContentAsync();

            existingContent.Append(" It is!");

            output.TagName = "span";
            output.Attributes.Clear();
            output.Content.SetContent(existingContent);
            output.PreContent.AppendEncoded($"<strong class='{classValue}'>");
            output.PostContent.AppendEncoded("</strong>");
        }
Пример #19
0
        /// <inheritdoc />
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            // Pass through attribute that is also a well-known HTML attribute.
            if (Src != null)
            {
                output.CopyHtmlAttribute(SrcAttributeName, context);
            }

            var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails);

            var logger = Logger ?? LoggerFactory.CreateLogger <ScriptTagHelper>();

            modeResult.LogDetails(logger, this, context.UniqueId, ViewContext.View.Path);

            if (!modeResult.FullMatches.Any())
            {
                // No attributes matched so we have nothing to do
                return;
            }

            // Get the highest matched mode
            var mode = modeResult.FullMatches.Select(match => match.Mode).Max();

            // NOTE: Values in TagHelperOutput.Attributes may already be HTML-encoded.
            var attributes = new Dictionary <string, object>(output.Attributes);

            var builder         = new DefaultTagHelperContent();
            var originalContent = await context.GetChildContentAsync();

            if (mode == Mode.Fallback && string.IsNullOrEmpty(SrcInclude) || mode == Mode.FileVersion)
            {
                // No globbing to do, just build a <script /> tag to match the original one in the source file
                // Or just add file version to the script tag.
                BuildScriptTag(originalContent, attributes, builder);
            }
            else
            {
                BuildGlobbedScriptTags(originalContent, attributes, builder);
            }

            if (mode == Mode.Fallback)
            {
                BuildFallbackBlock(attributes, builder);
            }

            // We've taken over tag rendering, so prevent rendering the outer tag
            output.TagName = null;
            output.Content.SetContent(builder);
        }
Пример #20
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (this.Enabled)
            {
                context.Items.Add(typeof(OpenGraphMetadata), null);

                await context.GetChildContentAsync();

                string namespaces = context.Items[typeof(OpenGraphMetadata)] as string;
                if (namespaces != null)
                {
                    output.Attributes.Add(PrefixAttributeName, namespaces);
                }
            }
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var content = await context.GetChildContentAsync();

            var iconHTML = string.Format(" <span class='glyphicon glyphicon-{0}'> </span>", getIconName());

            if (content.IsEmpty || content.IsWhiteSpace)
            {
                output.Content.SetContent(iconHTML);
            }
            else
            {
                output.Content.SetContent(content.Append(iconHTML));
            }
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();


            output.TagName = "div";
            var classNames = "modal-body";

            if (output.Attributes.ContainsName("class"))
            {
                classNames = string.Format("{0} {1}", output.Attributes["class"].Value, classNames);
            }
            output.Attributes["class"] = classNames;
            output.Content.SetContent(childContent);
        }
Пример #23
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var content = await context.GetChildContentAsync();

            var repeatContent = HtmlHelper.Encode(Expression.Metadata.Model.ToString());

            if (string.IsNullOrEmpty(repeatContent))
            {
                repeatContent = content;
            }

            for (int i = 0; i < RepeatContent; i++)
            {
                output.Content += repeatContent;
            }
        }
Пример #24
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            (HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);

            var content = await context.GetChildContentAsync();

            var repeatContent = HtmlHelper.Encode(Expression.Model.ToString());

            if (string.IsNullOrEmpty(repeatContent))
            {
                repeatContent = content.GetContent();
            }

            for (int i = 0; i < RepeatContent; i++)
            {
                output.Content.Append(repeatContent);
            }
        }
Пример #25
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            (HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);
            output.TagName = null;

            if (AspFor.Metadata?.TemplateHint != null)
            {
                output.Content.SetContent(
                    HtmlHelper.Partial($"{Const.DisplayTemplateViewPath}/{AspFor.Metadata.TemplateHint}", AspFor.Model).ToString());
            }
            else
            {
                output.Content.SetContent(
                    string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                  AspFor.Metadata?.DisplayFormatString ?? "{0}", AspFor.Model));
            }

            output.Content.Append(await context.GetChildContentAsync());
        }
Пример #26
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();

            if (ShowDismiss)
            {
                var dismissTemplate = $@"<button type='button' class='btn btn-default' data-dismiss='modal'>{DismissText}</button>";
                output.PreContent.SetContent(dismissTemplate);
            }
            output.TagName = "div";
            var classNames = "modal-footer";

            if (output.Attributes.ContainsName("class"))
            {
                classNames = string.Format("{0} {1}", output.Attributes["class"].Value, classNames);
            }
            output.Attributes["class"] = classNames;
            output.Content.SetContent(childContent);
        }
Пример #27
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (_webSite.IsAuthenticated(ViewContext.HttpContext.User))
            {
                output.TagMode = TagMode.StartTagAndEndTag;
                //add the own contents.
                output.Content.SetContent(context.GetChildContentAsync().Result);

                (_htmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);
                output.PreContent.Append(_htmlHelper.Partial(MiniWebFileProvider.ADMIN_FILENAME));

                if (!IgnoreAdminStart)
                {
                    output.Content.AppendEncoded($"<script>$(function(){{$('{MiniWebAdminTag}').miniwebAdmin();}});</script>");
                }
            }
            else
            {
                output.SuppressOutput();
            }
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (this.Enabled)
            {
                await context.GetChildContentAsync();

                // Workaround for context.Items not working across _Layout.cshtml and Index.cshtml using ViewContext.
                // https://github.com/aspnet/Mvc/issues/3233 and https://github.com/aspnet/Razor/issues/564
                if (this.ViewContext.ViewData.ContainsKey(nameof(OpenGraphPrefixTagHelper)))
                {
                    string namespaces = (string)this.ViewContext.ViewData[nameof(OpenGraphPrefixTagHelper)];
                    output.Attributes.Add(PrefixAttributeName, namespaces);
                }

                // if (context.Items.ContainsKey(typeof(OpenGraphMetadata)))
                // {
                //     string namespaces = context.Items[typeof(OpenGraphMetadata)] as string;
                //     output.Attributes.Add(PrefixAttributeName, namespaces);
                // }
            }
        }
Пример #29
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            //fill property title and content on specified tags
            if (!string.IsNullOrWhiteSpace(Property))
            {
                var view        = ViewContext.View as RazorView;
                var viewItem    = view.RazorPage as RazorPage <ContentItem>;
                var htmlContent = viewItem.Model.GetValue(Property, context.GetChildContentAsync().Result?.GetContent(HtmlEncoder.Default));
                output.Content.Clear();
                output.Content.AppendEncoded(htmlContent);

                foreach (var attr in EditAttributes)
                {
                    output.Attributes[attr].Value = viewItem.Model.GetValue(Property + ":" + attr, context.AllAttributes[attr]?.Value?.ToString());
                }
            }
            //Set Content edit properties on tags when logged in
            if (_webSite.IsAuthenticated(ViewContext.HttpContext.User))
            {
                if (!string.IsNullOrWhiteSpace(Property))
                {
                    output.Attributes.Add("data-miniwebprop", Property);
                }
                if (!string.IsNullOrWhiteSpace(EditType))
                {
                    output.Attributes.Add("data-miniwebedittype", EditType);
                }

                if (EditAttributes.Any())
                {
                    output.PostElement.AppendEncoded("<div class=\"miniweb-attributes\">");
                    foreach (var attr in EditAttributes)
                    {
                        var attrEditItem = string.Format("<span data-miniwebprop=\"{0}:{1}\">{2}</span>", Property, attr, output.Attributes[attr].Value);
                        output.PostElement.AppendEncoded(attrEditItem);
                    }
                    output.PostElement.AppendEncoded("</div>");
                }
            }
        }
Пример #30
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var content = await context.GetChildContentAsync();

            output.Content.SetContent(HtmlHelper.Hidden(Name, content).ToString());
        }