public void Execute(TemplateCompilationInfo templateCompilationInfo) { var importDirectives = from l in templateCompilationInfo.OriginalLines where l.Processed == false let match = ImportDirective.Match(l.Content) where match.Success select new { Line = l, Match=match}; foreach (var importDirective in importDirectives) { importDirective.Line.Processed = true; templateCompilationInfo.UsingDirectives.Add(new TemplateCompilationInfo.UsingDirective { OriginalLineNo=importDirective.Line.LineNumber, Using = importDirective.Match.Groups["namespace"].Value }); } }
public void Execute(TemplateCompilationInfo templateCompilationInfo) { var pageDirectives = (from l in templateCompilationInfo.OriginalLines where l.Processed == false let match = PageDirective.Match(l.Content) where match.Success select new { Line = l, Match = match }) .ToArray(); if (pageDirectives.Length==0) return; if (pageDirectives.Length > 1) throw new Exception("there can only be up to one Page directive in a template, sorry."); var pageDirective = pageDirectives[0]; pageDirective.Line.Processed = true; string baseClass = null; if (pageDirective.Match.Groups["base"].Success) baseClass = pageDirective.Match.Groups["base"].Value; templateCompilationInfo.PageDirective = new PageDirective(pageDirective.Line, baseClass); }
public PageDirective(TemplateCompilationInfo.InputLine content, string baseClass) { LineNo = content.LineNumber; BaseClass = baseClass; }
public void Execute(TemplateCompilationInfo templateCompilationInfo) { var lineNo = 0; var inCodeBlock = false; foreach (var inputLine in templateCompilationInfo.OriginalLines) { ++lineNo; if (inputLine.Processed) continue; var lastCharIx = -1; while (lastCharIx < inputLine.Content.Length) { if (inCodeBlock == false) { var nextCodeBlock = inputLine.Content.IndexOf("<%", lastCharIx + 1); if (nextCodeBlock <= lastCharIx) { var block = new TemplateCompilationInfo.MarkupBlock { Content = inputLine.Content.Substring(lastCharIx + 1), OriginalLineNo = lineNo }; if (lineNo < templateCompilationInfo.OriginalLines.Length) block.Content += Environment.NewLine; templateCompilationInfo.Blocks.Add(block); lastCharIx = int.MaxValue; continue; } var markupBlockContent = inputLine.Content.Substring(lastCharIx + 1, nextCodeBlock - lastCharIx - 1); templateCompilationInfo.Blocks.Add(new TemplateCompilationInfo.MarkupBlock { Content = markupBlockContent, OriginalLineNo = lineNo }); lastCharIx = nextCodeBlock - 1 + 2; inCodeBlock = true; } else { var endCodeBlock = inputLine.Content.IndexOf("%>", lastCharIx + 1); if (endCodeBlock <= lastCharIx) { templateCompilationInfo.Blocks.Add(new TemplateCompilationInfo.CodeBlock { Content = inputLine.Content.Substring(lastCharIx + 1), OriginalLineNo = lineNo }); lastCharIx = int.MaxValue; continue; } var codeBlockContent = inputLine.Content.Substring(lastCharIx + 1, endCodeBlock - lastCharIx - 1); templateCompilationInfo.Blocks.Add(new TemplateCompilationInfo.CodeBlock { Content = codeBlockContent, OriginalLineNo = lineNo }); lastCharIx = endCodeBlock - 1 + 2; inCodeBlock = false; } } } }