/// <summary> /// Add attribute with any name only if <paramref name="condition"/> - <c>true</c>. /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="condition">Condition, which define will be added content or not </param> /// <param name="key">Attribute name</param> /// <param name="value">Attribute value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddAttributeIf(this TagWrapper tag, bool condition, string key, string value) { if (condition) { tag.AddAttribute(key, value); } return(tag); }
/// <summary> /// Add "href" attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="reference">Href attribute value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddReference(this TagWrapper tag, string reference) { if (string.IsNullOrEmpty(reference)) { return(tag); } return(tag.AddAttribute("href", reference)); }
/// <summary> /// Add <c>for</c> attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="value">Type attribute value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddFor(this TagWrapper tag, string value) { if (string.IsNullOrEmpty(value)) { return(tag); } return(tag.AddAttribute("for", value)); }
/// <summary> /// Add "role" attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="value">Role attribute value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddRole(this TagWrapper tag, string value) { if (string.IsNullOrEmpty(value)) { return(tag); } tag.AddAttribute("role", value); return(tag); }
/// <summary> /// Add "name" attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="value">Name attribute value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddName(this TagWrapper tag, string value) { if (string.IsNullOrEmpty(value)) { return(tag); } value = value.TrimStart(new[] { '#' }); return(tag.AddAttribute("name", value)); }
/// <summary> /// Add the key value dictionary. /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="data"><see cref="IDictionary{TKey,TValue}"/></param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddAttributes(this TagWrapper tag, IDictionary <string, string> data) { if (data != null) { foreach (var s in data) { tag.AddAttribute(s.Key, s.Value); } } return(tag); }
/// <summary> /// Add the array of attributes which name and value defines by internal array[2]. /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="data">Array of array[2] - key/value pair</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddAttributes(this TagWrapper tag, string[][] data) { if (data != null) { foreach (var s in data) { if (s.Length == 2) { tag.AddAttribute(s[0], s[1]); } } } return(tag); }
/// <summary> /// Add "aria-*" attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="suffix">Suffix for "aria-*" attribute</param> /// <param name="value">"aria-*" attribute value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AddAria(this TagWrapper tag, string suffix, string value) { if (string.IsNullOrEmpty(suffix)) { return(tag); } if (string.IsNullOrEmpty(value)) { return(tag); } tag.AddAttribute($"aria-{suffix}", value); return(tag); }
/// <summary> /// Adds <c>asp-host</c> Core attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="name">Attribute value name</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspHost(this TagWrapper tag, string name) { tag.AddAttribute($"asp-host", name); return(tag); }
/// <summary> /// Adds <c>asp-protocol</c> Core attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="name">Attribute value name</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspProtocol(this TagWrapper tag, string name) { tag.AddAttribute($"asp-protocol", name); return(tag); }
/// <summary> /// Adds <c>asp-fragment</c> Core attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="value"><c>asp-fragment</c> value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspFragment(this TagWrapper tag, string value) { tag.AddAttribute($"asp-fragment", value); return(tag); }
/// <summary> /// Adds <c>asp-route</c> Core attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="name"><c>asp-route</c> name</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspRoute(this TagWrapper tag, string name) { tag.AddAttribute($"asp-route", name); return(tag); }
/// <summary> /// Adds <c>asp-route-*</c> Core attribute with suffix and value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="suffix"><c>asp-route-*</c> suffix</param> /// <param name="value"><c>asp-route-*</c> value</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspRoute(this TagWrapper tag, string suffix, string value) { tag.AddAttribute($"asp-route-{suffix}", value); return(tag); }
/// <summary> /// Adds <c>asp-action</c> Core attribute with name /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="name">Attribute value name</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspAction(this TagWrapper tag, string name) { tag.AddAttribute($"asp-action", name); return(tag); }
/// <summary> /// Adds <c>asp-page-handler</c> Core attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="name">Attribute value name</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspPageHandler(this TagWrapper tag, string name) { tag.AddAttribute($"asp-page-handler", name); return(tag); }
/// <summary> /// Adds <c>method</c> attribute with value /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="name">Attribute value name</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper Method(this TagWrapper tag, string name) { tag.AddAttribute($"method", name); return(tag); }
/// <summary> /// Adds <c>asp-controller</c> Core attribute with name /// </summary> /// <param name="tag"><see cref="TagWrapper"/></param> /// <param name="name">Attribute value name</param> /// <returns>Changed <see cref="TagWrapper"/></returns> public static TagWrapper AspController(this TagWrapper tag, string name) { tag.AddAttribute($"asp-controller", name); return(tag); }