public KeyBasedXhtmlRenderer(string templateString, XhtmlRenderingEncoding renderingEncoding) { templateString = templateString.Replace("~", UrlUtils.PublicRootPath); templateString = templateString.Replace("{label}", "{0}"); templateString = templateString.Replace("{id}", "{1}"); _labelHasToBeEvaluated = templateString.Contains("{0}"); _idHasToBeEvaluated = templateString.Contains("{1}"); _renderingEncoding = renderingEncoding; int stringFormattingIndex = 2; while (true) { int fieldDefinitionOffset = templateString.IndexOf("{field:"); if (fieldDefinitionOffset < 0) { break; } int closingBraceIndex = templateString.IndexOf("}", fieldDefinitionOffset + 7); Verify.That(closingBraceIndex > 0, "Invalid rendering template."); string fieldName = templateString.Substring(fieldDefinitionOffset + 7, closingBraceIndex - fieldDefinitionOffset - 7); _fieldNames.Add(fieldName); string fieldPattern = templateString.Substring(fieldDefinitionOffset, closingBraceIndex - fieldDefinitionOffset + 1); _fieldPatterns.Add(fieldPattern); templateString = templateString.Replace(fieldPattern, "{" + (stringFormattingIndex++) + "}"); } _templateString = string.Format("<body xmlns='{0}'>{1}</body>", Namespaces.Xhtml, templateString); }
/// <summary> /// Created a XHTML Renderer that uses the specified template to create markup. /// The key of the data will be inserted into the specified template where '{id}' is. /// If you spcify '{label}' the system will fetch the value of the label field and insert it. /// You also can use '{field:__a field name__}' syntax to insert a field value. /// Use '~' to create absolute paths. /// Example: <example><a href='~/showProduct.aspx?id={id}'>read more about {label}</a></example> /// </summary> public KeyTemplatedXhtmlRendererAttribute(XhtmlRenderingType renderingType, XhtmlRenderingEncoding renderingEncoding, string formatedTemplate) { this.FormatedTemplate = formatedTemplate; _supportedRenderingType = renderingType; _renderingEncoding = renderingEncoding; }
public KeyBasedXhtmlRenderer(string templateString, XhtmlRenderingEncoding renderingEncoding) { templateString = templateString.Replace("~", UrlUtils.PublicRootPath); templateString = templateString.Replace("{label}", "{0}"); templateString = templateString.Replace("{id}", "{1}"); _labelHasToBeEvaluated = templateString.Contains("{0}"); _idHasToBeEvaluated = templateString.Contains("{1}"); _renderingEncoding = renderingEncoding; int stringFormattingIndex = 2; while (true) { int fieldDefinitionOffset = templateString.IndexOf("{field:"); if (fieldDefinitionOffset < 0) break; int closingBraceIndex = templateString.IndexOf("}", fieldDefinitionOffset + 7); Verify.That(closingBraceIndex > 0, "Invalid rendering template."); string fieldName = templateString.Substring(fieldDefinitionOffset + 7, closingBraceIndex - fieldDefinitionOffset - 7); _fieldNames.Add(fieldName); string fieldPattern = templateString.Substring(fieldDefinitionOffset, closingBraceIndex - fieldDefinitionOffset + 1); _fieldPatterns.Add(fieldPattern); templateString = templateString.Replace(fieldPattern, "{" + (stringFormattingIndex++) + "}"); } _templateString = string.Format("<body xmlns='{0}'>{1}</body>", Namespaces.Xhtml, templateString); }