protected void AttrKey(String attributeName, String attributeValueKey, String attributeValueDefault = null) { var aName = attributeName.ToLowerInvariant(); RemoveAttribute(aName); LocalizedAttributes.Add(aName, new KeyWithDefault(attributeValueKey, attributeValueDefault)); }
internal void AttrKey(String attributeName, String attributeValueKey) { var aName = attributeName.ToLowerInvariant(); RemoveAttribute(aName); LocalizedAttributes.Add(aName, attributeValueKey); }
protected void RemoveAttribute(String attributeName) { if (LocalizedAttributes.ContainsKey(attributeName)) { LocalizedAttributes.Remove(attributeName); } if (OtherAttributes.ContainsKey(attributeName)) { OtherAttributes.Remove(attributeName); } }
/// <summary> /// Returns an IDisposable LocalWrapper that will render the open tag upon opening, and a close tag upon closing /// </summary> /// <returns>returns a LocalWrapper containing the rendered tag</returns> public LocalWrapper Open() { if (!(IsDisplayed || DebugMode)) { return(new LocalWrapper(null, _context)); } var builder = new TagBuilder(TagName); foreach (var attribute in LocalizedAttributes) { var value = Repository.GetQualified(attribute.Value.Key, attribute.Value.Default); builder.MergeAttribute(attribute.Key, Processors.Aggregate( value.Value.DecodeWithReplacements(Replacements), (val, processor) => processor(val) )); if (!DebugMode) { continue; } builder.MergeAttribute("data-loc-debug", "true"); var key = "data-loc-attribute-" + attribute.Key + "-"; builder.MergeAttribute(key + "part", value.Qualifier.Part.ToString()); builder.MergeAttribute(key + "content", value.Value.Content); } if (DebugMode) { if (LocalizedAttributes.Any()) { var localizations = String.Join(((char)31).ToString(CultureInfo.InvariantCulture), LocalizedAttributes.Select(localization => localization.Key + (char)30 + localization.Value)); builder.MergeAttribute("data-loc-localizations", localizations); } if (Replacements.Any()) { var replacements = String.Join(((char)31).ToString(CultureInfo.InvariantCulture), Replacements.Select(replacement => replacement.Key + (char)30 + replacement.Value)); builder.MergeAttribute("data-loc-replacements", replacements); } } foreach (var attribute in OtherAttributes) { builder.MergeAttribute(attribute.Key, attribute.Value); } return(new LocalWrapper(builder, _context)); }
/// <summary> /// Adds (does not overwrite) classes to the tag /// </summary> /// <param name="classNames">the classname(s) to add</param> /// <returns>returns itself</returns> public LocalizedHtmlTag Class(params String[] classNames) { const String classAttr = "class"; foreach (var className in classNames) { if (LocalizedAttributes.ContainsKey(classAttr)) { LocalizedAttributes.Remove(classAttr); } if (OtherAttributes.ContainsKey(classAttr)) { OtherAttributes[classAttr] = OtherAttributes[classAttr] + " " + className; } else { OtherAttributes.Add(classAttr, className); } } return(this); }
public string ToHtmlString() { if (!(IsDisplayed || DebugMode)) { return(String.Empty); } var builder = new TagBuilder(TagName); var innerHtml = String.Empty; QualifiedValue innerHtmlValue = null; if (!String.IsNullOrEmpty(LocalizedHtmlKey.Key)) { innerHtmlValue = Repository.GetQualified(LocalizedHtmlKey.Key, LocalizedHtmlKey.Default); var decodedValue = Processors.Aggregate( innerHtmlValue.Value.DecodeWithReplacements(Replacements), (value, processor) => processor(value) ); builder.InnerHtml = decodedValue; } foreach (var attribute in LocalizedAttributes) { var value = Repository.GetQualified(attribute.Value.Key, attribute.Value.Default); builder.MergeAttribute(attribute.Key, Processors.Aggregate( value.Value.DecodeWithReplacements(Replacements), (val, processor) => processor(val) )); if (!DebugMode) { continue; } var key = "data-loc-attribute-" + attribute.Key + "-"; builder.MergeAttribute(key + "part", value.Qualifier.Part.ToString()); builder.MergeAttribute(key + "content", value.Value.Content); } if (DebugMode) { builder.MergeAttribute("data-loc-debug", "true"); if (innerHtmlValue != null) { builder.MergeAttribute("data-loc-inner-part", innerHtmlValue.Qualifier.Part.ToString()); builder.MergeAttribute("data-loc-inner-key", innerHtmlValue.Qualifier.Key); builder.MergeAttribute("data-loc-inner-value", innerHtmlValue.Value.Content); } if (LocalizedAttributes.Any()) { var localizations = String.Join(((char)31).ToString(CultureInfo.InvariantCulture), LocalizedAttributes.Select(localization => localization.Key + (char)30 + localization.Value)); builder.MergeAttribute("data-loc-localizations", localizations); } if (Replacements.Any()) { var replacements = String.Join(((char)31).ToString(CultureInfo.InvariantCulture), Replacements.Select(replacement => replacement.Key + (char)30 + replacement.Value)); builder.MergeAttribute("data-loc-replacements", replacements); } } if (!String.IsNullOrEmpty(OtherHtml)) { innerHtml += OtherHtml; } if (!String.IsNullOrEmpty(innerHtml)) { builder.InnerHtml = innerHtml; } foreach (var attribute in OtherAttributes) { builder.MergeAttribute(attribute.Key, attribute.Value); } return(builder.ToString()); }