public static string Render(Context context, string input) { var reader = new StringReader(input); Assembly assembly = Assemble(reader); RazorTemplate<Context> template = CreateTemplateInstance(assembly, context); return template.Render(); }
public static void Render(Context context, Stream input, Stream output) { var reader = new StreamReader(input); var writer = new StreamWriter(output); Assembly assembly = Assemble(reader); RazorTemplate<Context> template = CreateTemplateInstance(assembly, context); writer.Write(template.Render()); writer.Flush(); }
public static Statement InterpretStatement(Context context, string text) { // example statement: // select *.md -recursive >> markdown >> template template.html >> save .html Statement statement = new Statement(); string[] sentences = text.Split(new string[] { ">>" }, StringSplitOptions.RemoveEmptyEntries); statement.Selector = InterpretSelector(context, sentences.First()); foreach (string s in sentences.Skip(1)) { IProcessor processor = InterpretProcessor(context, s); if (processor != null) { statement.PipeLine.Add(processor); } } return statement; }
public static IWork InterpretDocument(string text, Context context) { Bulk bulk = new Bulk(); StringReader reader = new StringReader(text); bool ok; do { string statement = reader.ReadLine(); bool skip = (string.IsNullOrWhiteSpace(statement)) || (statement.StartsWith("//")); ok = (statement != null); if (skip) continue; if (ok) { IWork work = InterpretStatement(context, statement); bulk.Append(work); } } while (ok); return bulk; }
public static ISelector Create(Context context, string mask, bool recursive = false, bool fromoutput = false) { FileFilter filter = new FileFilter(); filter.Context = context; filter.Filter = mask; filter.Recursive = recursive; filter.FromOutput = fromoutput; return filter; }
public static ISelector Create(Context context, IEnumerable<string> args) { return Selector.Create(context, args.ToArray()); }
public static ISelector Create(Context context, params string[] args) { string p1 = args.FirstOrDefault(); string mask = args.Skip(1).Where(a => !a.StartsWith("-")).FirstOrDefault(); // first non option parameter if (p1 == null) throw new Exception("No parameters for filter"); if (p1.StartsWith(STASHPREFIX)) { return new StashFilter(p1, mask); } else { FileFilter filter = new FileFilter(); filter.Filter = p1; filter.Recursive = args.Contains("-recursive"); filter.FromOutput = args.Contains("-output"); filter.Context = context.Clone(); filter.Mask = mask; return filter; } }
public static Document GetDocument(Context context, string mask) { ISelector filter = FileFilter.Create(context, mask, false); Document doc = filter.Documents.FirstOrDefault(); if (doc == null) { throw new Exception(string.Format("Mask {0} yielded no results", mask)); } else return doc; }
public static RazorTemplate<Context> CreateTemplateInstance(Assembly assembly, Context context) { //Type type = assembly.GetType("RazorOutput.Template"); Type type = assembly.GetExportedTypes().Single(); // there is only one RazorTemplate<Context> template = Activator.CreateInstance(type) as RazorTemplate<Context>; var property = type.GetProperty("Model"); property.SetValue(template, context, null); return template; }
public Context Clone() { Context context = new Context(this.Root); context.Location = this.Location.Clone(); return context; }
public static IProcessor InterpretProcessor(Context context, string text) { try { var words = text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (words.Count() == 0) return null; string command = words.First().ToLower(); var parameters = words.Skip(1); switch (command) { case "markdown": return new RenderProcessor(new MarkDownRenderer()); case "template": { var processor = new TemplateProcessor(); //pr.Template = influx.Documents.First(); //Document document = Document.CreateInContext(context, template); processor.Influx = Selector.Create(context, parameters); return processor; } case "razor": return new RenderProcessor(new RazorRenderer()); case "copy": return new CopyProcessor(); case "save": { string mask = parameters.FirstOrDefault(); var processor = new SaveProcessor(); processor.Mask = mask; return processor; } case "stash": { string key = words.Skip(1).First(); if (!key.StartsWith(Selector.STASHPREFIX)) throw new Exception("Stash name should always begin with " + Selector.STASHPREFIX); return new StashProcessor(key); } case "attach": { IProcessor p = new AttachProcessor(); p.Influx = Selector.Create(context, parameters); return p; } case "concatenate": return new ConcatenateProcessor(); case "make": return new MakeProcessor(); case "makeall": { string folder = parameters.FirstOrDefault(); return new MakeForAllProcessor(folder); } case "profiletable": return new ProfileProcessor(); case "structure": return new StructureProcessor(); case "dict": return new DictTableProcessor(); case "valueset": return new ValueSetProcessor(); default: throw new Exception("Unknown processing command: " + command); } } catch { throw new Exception("Invalid processor statement: " + text); } }
public static ISelector InterpretSelector(Context context, string text) { try { var words = text.Split(' '); string command = words.First(); var parameters = words.Skip(1).ToArray(); return Selector.Create(context, parameters); } catch { throw new Exception("Invalid select statement: " + text); } }
public void Test(Context context) { Document.CreateInContext(context, "template.html"); }
public TestProcessor(Context context, string filename) { // todo: move to influx !!!! template = Document.CreateInContext(context, filename); }
public static Document CreateInContext(Context context, string filename) { Document document = new Document(); document.Context = context.Clone(); string dir = Path.GetDirectoryName(filename); document.Context.MoveTo(dir); document.SetFilename(filename); return document; }
public static Document CreateFromFullPath(Context context, string fullpath) { Document document = new Document(); document.Context = Context.CreateFromSource(context.Root, fullpath); document.SetFilename(fullpath); return document; }