public void ProcessDocument(DocumentDef doc) { Contract.Requires(doc != null); paragraphsStack.Clear(); OnDocumentBegin(doc); foreach (IDocumentElement el in doc.Children) { ParagraphElement paragraphEl = el as ParagraphElement; HeadingElement headingEl = el as HeadingElement; if (paragraphEl != null) { ProcessParagraphElement(paragraphEl); } else if (headingEl != null) { ProcessHeadingElement(headingEl); } else { throw new NotImplementedException("todo next: {0}".Fmt(el.GetType().Name)); } } EnsureParagraphStackIsCleared(); OnDocumentEnd(doc); }
public static RecordList Postprocess(this DocumentDef doc) { var result = new RecordList(doc.Namespace); foreach (var rec in doc.Records) { var flags = new List <string>(); var attrs = new Dictionary <string, string>(); var inproc = ApplyAttibuteModifications(flags, attrs, doc.Defaults); var proto = doc.Prototypes.FirstOrDefault(x => x.Name == rec.PrototypeName); if (proto != null) { inproc = ApplyAttibuteModifications(inproc.Item1, inproc.Item2, proto.Attributes); } inproc = ApplyAttibuteModifications(inproc.Item1, inproc.Item2, rec.Attributes); var fields = rec.Fields.Select(x => new Field(x.Name, x.Type)).ToArray(); result.Records.Add(new Record(rec.Name, inproc.Item1.ToArray(), inproc.Item2, fields)); } return(result); }
protected override void OnDocumentBegin(DocumentDef doc) { textBuilder = new StringBuilder(); textWriter = new StringWriter(textBuilder, CultureInfo.InvariantCulture); writer = new HtmlTextWriter(textWriter, " "); writer.RenderBeginTag(HtmlTextWriterTag.Body); }
protected override void OnDocumentEnd(DocumentDef doc) { writer.RenderEndTag(); writer.Flush(); resultHtml = textWriter.ToString(); DisposeOfManagedResources(); }
public string ExpandTemplate(ICompiledRazorTemplate template, DocumentDef doc, string docHtml, FreudeProject project) { RazorEngineExecutionSettings executionSettings = new RazorEngineExecutionSettings(); executionSettings.Properties.Add("Doc", doc); executionSettings.Properties.Add("DocHtml", docHtml); executionSettings.Properties.Add("Project", project); return(template.Execute(executionSettings)); }
private void ProcessFreudeFile(FreudeProject project, string fileName) { string freudeText = fileSystem.ReadFileAsString(fileName); ParsingContext parsingContext; DocumentDef doc = freudeTextParser.ParseText(freudeText, out parsingContext); throw new NotImplementedException(); //// todo: report parsing errors and warnings //string docHtml = htmlGenerator.GenerateHtml(doc); //ICompiledRazorTemplate template = project.GetTemplate("default"); //string expandedBody = freudeTemplatingEngine.ExpandTemplate(template, doc, docHtml, project); //string destinationFileName = ConstructDestinationFileName (fileName); //destinationFileName = Path.ChangeExtension(destinationFileName, expandedFileExtension); //fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(destinationFileName)); //fileSystem.WriteFile(destinationFileName, expandedBody, Encoding.UTF8); //log.InfoFormat ("Built file '{0}'", destinationFileName); }
protected virtual void OnDocumentBegin(DocumentDef doc) { Contract.Requires(doc != null); }
string IFreudeTemplatingEngine.ExpandTemplate(ICompiledRazorTemplate template, DocumentDef doc, string docHtml, FreudeProject project) { Contract.Requires(template != null); Contract.Requires(doc != null); Contract.Requires(docHtml != null); Contract.Requires(project != null); Contract.Ensures(Contract.Result <string> () != null); throw new System.NotImplementedException(); }