public List <HtmlTemplate> GetHtmlTemplates(string path) { CheckConfigForRefresh(); TemplateFolder folder = FindFolder(path, Root); return((from t in folder.Templates select new HtmlTemplate(t.Name, GetTemplateHtml(t.Path, ""))).ToList()); }
private string GetTemplateHtml(TemplateFolder folder, ThemedTemplate template, string theme) { string body = "{content}"; if (template.MasterTemplateName != "") { ThemedTemplate master = (from m in folder.Masters where m.Name.ToLower() == template.MasterTemplateName.ToLower() select m).SingleOrDefault(); if (master != null) { body = GetTemplateHtml(folder, master, theme); } } return(body.Replace("{content}", template.GetHtml(theme))); }
private TemplateFolder LoadTemplateFolder(XElement el, string path) { TemplateFolder tf = new TemplateFolder(el.Attribute("name").Value, path); XNamespace ns = el.GetDefaultNamespace(); List <XElement> subFolders = el.Elements(ns + "templateFolder").ToList(); foreach (XElement f in subFolders) { string name = f.Attribute("name").Value; tf.Folders.Add(LoadTemplateFolder(f, string.Format("{0}/{1}", path, name))); } //load themes XElement elThemes = el.Element(ns + "themes"); if (elThemes != null) { List <XElement> themes = elThemes.Elements(ns + "theme").ToList(); foreach (XElement th in themes) { tf.Themes.Add(th.Attribute("name").Value); } } List <XElement> masters = el.Elements(ns + "master").ToList(); foreach (XElement m in masters) { ThemedTemplate template = LoadTemplate(tf.Path, m, tf.Themes); if (template != null) { tf.Masters.Add(template); } } List <XElement> templates = el.Elements(ns + "template").ToList(); foreach (XElement t in templates) { ThemedTemplate template = LoadTemplate(tf.Path, t, tf.Themes); if (template != null) { tf.Templates.Add(template); } } return(tf); }
private string GetTemplateHtml(string path, string theme) { if (path.EndsWith("/")) { throw new ArgumentException(string.Format("Invalid path - ends with /. path=[{0}]", path)); } TemplateFolder folder = FindFolder(path, Root); string templateName = path; if (templateName.IndexOf("/") > 0) { templateName = templateName.Substring(templateName.LastIndexOf("/") + 1); } ThemedTemplate template = (from t in folder.Templates where t.Name.ToLower() == templateName.ToLower() select t).SingleOrDefault(); if (template == null) { throw new ArgumentException(string.Format("Could not find template. name=[{0}] path=[{1}]", templateName, path)); } CheckTemplateForRefresh(template); return(GetTemplateHtml(folder, template, theme)); }
private TemplateFolder FindFolder(string path, TemplateFolder parent) { while (path.StartsWith("/")) { path = path.Substring(1); } int nextIndex = path.IndexOf('/'); if (nextIndex > 0) { string currentName = path.Substring(0, nextIndex).ToLower(); TemplateFolder folder = (from f in parent.Folders where f.Name.ToLower() == currentName select f).SingleOrDefault(); if (folder == null) { throw new ArgumentException(string.Format("Could not find Template Folder folder=[{0}]", currentName)); } return(FindFolder(path.Substring(nextIndex + 1), folder)); } else { return(parent); } }
private void LoadTemplates() { try { XmlReader reader = XmlReader.Create(_configFilePath); XElement doc = XElement.Load(reader); XmlNameTable nameTable = reader.NameTable; _namespaceManager = new XmlNamespaceManager(nameTable); _namespaceManager.AddNamespace("dc", _namespace); XElement rootFolder = doc.XPathSelectElement("//dc:templateFolder[@name='root']", _namespaceManager); if (rootFolder == null) { throw new XmlException("No root template folder specified."); } _root = LoadTemplateFolder(rootFolder, ""); } catch (Exception ex) { _logger.Error(this.GetType(), ex, "Error loading templates for ThemedHtmlTemplateManager. configpath=[{0}]", _configFilePath); throw new Exception("Could not load templates for ThemedHtmlTemplateManager.", ex); } }
public void RefreshTemplates() { // refresh all templates _root = new TemplateFolder(); LoadTemplates(); }