/// <summary> /// Get the abstract of the article /// </summary> /// <returns></returns> internal string GetAbstract() { PropertyTemplate ptm = NonParameterizedTemplate.Spawn(GetPropertyTemplate(pageAbstractProperty), Parent, this.Context) as PropertyTemplate; if (ptm == null) { return(base.GetContextPropertyValue(pageAbstractProperty).ToString()); } else { return(ptm.FillTemplate()); } }
/// <summary> /// Get the page path /// </summary> internal string GetPath() { PropertyTemplate ptm = NonParameterizedTemplate.Spawn(GetPropertyTemplate(pagePathTemplate), Parent, this.Context) as PropertyTemplate; if (ptm == null) { return(pagePathTemplate); } else { return(ptm.FillTemplate()); } }
public override string FillTemplate() { //// Current template fields string[][] templateFields = new string[][] { new string[] { "$feature$", "Invalid Operation" }, new string[] { "01-09-2009", DateTime.Now.ToString("yyyy-MM-dd") }, new string[] { "$date$", DateTime.Now.ToString("yyyy-MM-dd") }, new string[] { "$time$", DateTime.Now.ToString("HH:mm:ss") }, new string[] { "$user$", SystemInformation.UserName }, new string[] { "$value$", Context.ToString().Replace("<", "<").Replace(">", ">").Replace("$", "$").Replace("@", "@").Replace("^", "^") }, new string[] { "$$", "$" }, new string[] { "@@", "@" }, new string[] { "^^", "^;" }, new string[] { "$version$", Assembly.GetEntryAssembly().GetName().Version.ToString() }, new string[] { "$typeName$", Context == null ? "" : Context.GetType().Name }, new string[] { "$guid$", Guid.NewGuid().ToString() }, new string[] { "$guid2$", Guid.NewGuid().ToString() } }; if (this.Context is Feature && (this.Context as Feature).Annotations.Exists(o => o is SuppressBrowseAnnotation)) { System.Diagnostics.Trace.WriteLine(String.Format("Feature '{0}' won't be published as a SuppressBrowse annotation was found", (this.Context as Feature).Name), "warn"); return(""); } string output = Content; foreach (string[] kv in templateFields) { output = output.Replace(kv[0], kv[1]); } // Process output for literals #region Literals while (output.Contains("$")) { int litPos = output.IndexOf('$'); int ePos = output.IndexOf('$', litPos + 1); System.Diagnostics.Debug.Assert(ePos >= litPos, String.Format("Unfinished template variable in HTML template '{0}'", output)); string parmName = ""; if (ePos > litPos) { parmName = output.Substring(litPos + 1, ePos - litPos - 1); } PropertyTemplate pt = NonParameterizedTemplate.Spawn(GetPropertyTemplate(parmName) as NonParameterizedTemplate, Parent, GetContextPropertyValue(parmName)) as PropertyTemplate; var ctxPropertyValue = GetContextPropertyValue(parmName); if (pt == null && !string.IsNullOrEmpty(parmName)) // None found ... use value { output = output.Replace(string.Format("${0}$", parmName), string.Format("{0}", ctxPropertyValue).Replace("$", "$").Replace("@", "@").Replace("^", "^")); } else if (pt.Property == null) { System.Diagnostics.Trace.WriteLine(String.Format("Invalid property name for parameter '{0}' propertyTemplate name '{1}'", parmName, pt.Name), "error"); output = output.Replace(String.Format("${0}$", parmName), "<span style=\"color:red\">Invalid property name</span>"); } else if (!string.IsNullOrEmpty(parmName))// Found, so use { pt.Context = GetContextPropertyValue(pt.Property); output = output.Replace(string.Format("${0}$", parmName), pt.FillTemplate().Replace("$", "$").Replace("@", "@").Replace("^", "^")); } } #endregion #region Arrays while (output.Contains("@")) { int litPos = output.IndexOf('@'); int ePos = output.IndexOf('@', litPos + 1); string parmName = output.Substring(litPos + 1, ePos - litPos - 1); object[] value = null; PropertyTemplate pt = NonParameterizedTemplate.Spawn(GetPropertyTemplate(parmName) as NonParameterizedTemplate, Parent, null) as PropertyTemplate; if (parmName == "this") { value = ConvertToObjectArray(this.Context); } else { value = ConvertToObjectArray(GetContextPropertyValue(pt != null ? pt.Property : parmName)); } // First, we'll look for a property template that has the specific name //value = ConvertToObjectArray(GetContextPropertyValue(pt != null ? pt.Property : parmName)); if (value != null && pt == null) { foreach (object o in value) { output = output.Replace(string.Format("@{0}@", parmName), string.Format("{0}@{1}@", o, parmName)); } output = output.Replace(string.Format("@{0}@", parmName), ""); } else if (value != null && pt != null) // Apply template { foreach (object o in value) { PropertyTemplate cpt = NonParameterizedTemplate.Spawn(pt, Parent, o) as PropertyTemplate; output = output.Replace(string.Format("@{0}@", parmName), string.Format("{0}@{1}@", cpt.FillTemplate().Replace("$", "$").Replace("@", "@").Replace("^", "^"), parmName)); } output = output.Replace(string.Format("@{0}@", parmName), ""); } else { output = output.Replace(string.Format("@{0}@", parmName), ""); } } #endregion #region Functoids while (output.Contains("^")) { int litPos = output.IndexOf('^'); int ePos = output.IndexOf('^', litPos + 1); System.Diagnostics.Debug.Assert(ePos != -1, String.Format("Template field not closed at '{0}'", this.Name)); string funcName = output.Substring(litPos + 1, ePos - litPos - 1); // First, we'll look for a property template that has the specific name var funcTemplate = NonParameterizedTemplate.Spawn(this.SubTemplates.Find(o => o.Name == funcName && o is FunctoidTemplate), this.Parent, this.Context) as FunctoidTemplate; object content = null; if (funcTemplate == null) { content = String.Format("<span style=\"color:red\">Could not find function template '{0}'</span>", funcName); } else { content = funcTemplate.FillTemplate(); } if (content is IEnumerable && !(content is String)) { foreach (object o in content as IEnumerable) { string ovalue = o == null ? "" : o.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^"); output = output.Replace(string.Format("^{0}^", funcName), string.Format("{0}^{1}^", ovalue, funcName)); } output = output.Replace(string.Format("^{0}^", funcName), ""); } else { output = output.Replace(string.Format("^{0}^", funcName), string.Format("{0}", content.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^"))); } } #endregion // Apply XmlElement Templates output = ApplyXmlElementTemplates(output); return(output); }