public static DocumentToken Transform(DocumentToken document, List<DocumentToken> documents) { var transform = DocumentTransform.TransformSections(document, documents); transform = DocumentTransform.TransformRender(transform, documents); return transform; }
public static DocumentToken Transform(DocumentToken document, List <DocumentToken> documents) { var transform = DocumentTransform.TransformSections(document, documents); transform = DocumentTransform.TransformRender(transform, documents); return(transform); }
private static DocumentToken TransformRender(DocumentToken document, List <DocumentToken> documents) { var transform = new DocumentToken(document.Name, document.Content); foreach (var token in document.Tokens) { TransformRender(transform, token, documents); } return(transform); }
private static void TransformRender(DocumentToken transform, Token token, List <DocumentToken> documents) { if (token is RenderToken) { var render = token as RenderToken; renderdepth += 1; if (renderdepth > 32) { renderdepth -= 1; string message = string.Format("error: exceeded maximum render depth for ", render.Name); transform.Tokens.Add(new ContentToken(message, 0, message.Length)); return; } var subdocument = GetDocument(render.Name, documents); if (subdocument != null) { subdocument = Transform(subdocument, documents); foreach (var _token in subdocument.Tokens) { TransformRender(transform, _token, documents); } } renderdepth -= 1; return; } if (token is ContentToken) { transform.Tokens.Add(token); } foreach (var _token in token.Tokens) { TransformRender(transform, _token, documents); } }
private static DocumentToken TransformSections(DocumentToken document, List <DocumentToken> documents) { var transform = new DocumentToken(document.Name, document.Content); var chain = CreateDocumentChain(document, documents); var root = chain[0]; var decendants = new List <DocumentToken>(); for (int i = 1; i < chain.Count; i++) { decendants.Add(chain[i]); } foreach (var token in root.Tokens) { if (token is SectionToken) { var section = token as SectionToken; foreach (var decendant in decendants) { var subsection = decendant.GetSection(section.Name); if (subsection != null) { section = subsection; } else { break; } } transform.Tokens.Add(section); } else { transform.Tokens.Add(token); } } return(transform); }
private DocumentToken LoadDocument(string name, string filename) { if (System.IO.File.Exists(filename)) { try { var document = new DocumentToken(name, System.IO.File.ReadAllText(filename)); return(Lexer.Scan(document)); } catch { } } var error = new DocumentToken(name, string.Format("error: unable to load template for {0}", filename)); error.Tokens.Add(new ContentToken(error.Content, 0, error.Content.Length)); return(error); }
private static List <DocumentToken> CreateDocumentChain(DocumentToken document, List <DocumentToken> documents) { var chain = new List <DocumentToken>(); chain.Add(document); while (document != null) { var import = document.GetImport(); if (import == null) { document = null; break; } if (GetDocument(import.Name, chain) != null) { var message = string.Format("error: cyclic imports detected for ", import.Name); var error = new DocumentToken(document.Name, message); error.Tokens.Add(new ContentToken(error.Content, 0, error.Content.Length)); return(new List <DocumentToken>(new DocumentToken[] { error })); } document = GetDocument(import.Name, documents); if (document != null) { chain.Add(document); } } chain.Reverse(); return(chain); }
private static List<DocumentToken> CreateDocumentChain(DocumentToken document, List<DocumentToken> documents) { var chain = new List<DocumentToken>(); chain.Add(document); while (document != null) { var import = document.GetImport(); if (import == null) { document = null; break; } if (GetDocument(import.Name, chain) != null) { var message = string.Format("error: cyclic imports detected for ", import.Name); var error = new DocumentToken(document.Name, message); error.Tokens.Add(new ContentToken(error.Content, 0, error.Content.Length)); return new List<DocumentToken>(new DocumentToken[] {error}); } document = GetDocument(import.Name, documents); if (document != null) { chain.Add(document); } } chain.Reverse(); return chain; }
public Template(string filename) { var documents = DocumentLoader.Load(filename); this.document = DocumentTransform.Transform(documents[0], documents); }
public Template(string filename) { var documents = DocumentLoader.Load(filename); this.document = DocumentTransform.Transform(documents[0], documents); }
private static DocumentToken TransformSections(DocumentToken document, List<DocumentToken> documents) { var transform = new DocumentToken(document.Name, document.Content); var chain = CreateDocumentChain(document, documents); var root = chain[0]; var decendants = new List<DocumentToken>(); for (int i = 1; i < chain.Count; i++) { decendants.Add(chain[i]); } foreach (var token in root.Tokens) { if (token is SectionToken) { var section = token as SectionToken; foreach (var decendant in decendants) { var subsection = decendant.GetSection(section.Name); if (subsection != null) { section = subsection; } else { break; } } transform.Tokens.Add(section); } else { transform.Tokens.Add(token); } } return transform; }
private static DocumentToken TransformRender(DocumentToken document, List<DocumentToken> documents) { var transform = new DocumentToken(document.Name, document.Content); foreach (var token in document.Tokens) { TransformRender(transform, token, documents); } return transform; }
private static void TransformRender(DocumentToken transform, Token token, List<DocumentToken> documents) { if (token is RenderToken) { var render = token as RenderToken; renderdepth += 1; if(renderdepth > 32) { renderdepth -= 1; string message = string.Format("error: exceeded maximum render depth for ", render.Name); transform.Tokens.Add(new ContentToken(message, 0, message.Length)); return; } var subdocument = GetDocument(render.Name, documents); if (subdocument != null) { subdocument = Transform(subdocument, documents); foreach (var _token in subdocument.Tokens) { TransformRender(transform, _token, documents); } } renderdepth -= 1; return; } if (token is ContentToken) { transform.Tokens.Add(token); } foreach (var _token in token.Tokens) { TransformRender(transform, _token, documents); } }
private DocumentToken LoadDocument(string name, string filename) { if(System.IO.File.Exists(filename)) { try { var document = new DocumentToken(name, System.IO.File.ReadAllText(filename)); return Lexer.Scan(document); } catch { } } var error = new DocumentToken(name, string.Format("error: unable to load template for {0}", filename)); error.Tokens.Add(new ContentToken(error.Content, 0, error.Content.Length)); return error; }