CopyItem ITemplateEngine.GetCopyItem(TemplateContext context, TemplateProperties properties, string[] mimeTypes) { Initialise(); var copyItemEngine = GetCopyItemEngine(context); return(CreateCopyItem(copyItemEngine, context, properties, mimeTypes)); }
private MethodInfo CreateMethodInfo(TemplateProperties properties) { // Parse the text and create an assembly from it. var settings = GetSettings(properties); var code = MergeParser.Parse(_text, _mimeType, Method, properties, settings); return(MergeCompiler.Compile(code, _mimeType, Method, settings)); }
private static object[] GetParameters(TemplateProperties properties) { var parameters = new object[properties.Count]; var index = 0; foreach (var property in properties) { parameters[index++] = property.Value; } return(parameters); }
protected virtual string GetCopyText(TemplateContext context, TemplateProperties properties) { // Get the method info for this template. if (_methodInfo == null) { lock (_methodLock) { if (_methodInfo == null) { _methodInfo = CreateMethodInfo(properties); } } } // Create the set of parameters and invoke. return((string)_methodInfo.Invoke(null, GetParameters(properties))); }
string ITextTemplateEngine.GetCopyText(TemplateContext context, TemplateProperties properties) { return(GetCopyText(context, properties)); }
CopyItem ITemplateEngine.GetCopyItem(CopyItemEngine copyItemEngine, TemplateContext context, TemplateProperties properties, string[] mimeTypes) { return(_firstTemplateEngine.GetCopyItem(copyItemEngine, context, properties, mimeTypes)); }
CopyItem ITemplateEngine.GetCopyItem(TemplateContext context, TemplateProperties properties, string[] mimeTypes) { return(_secondTemplateEngineNames.Contains(context.Definition) ? _secondTemplateEngine.GetCopyItem(context, properties, mimeTypes) : _firstTemplateEngine.GetCopyItem(context, properties, mimeTypes)); }
public static string Parse(string text, string mimeType, string method, TemplateProperties properties, MergeSettings settings) { using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream, System.Text.Encoding.UTF8)) { WriteUsings(writer, mimeType, settings.Usings); // Class declaration. writer.Write(@" using System; namespace LinkMe.Utility.Templates.Generated { public class Engine { "); // Fields. WriteFields(writer, settings.Fields); // Methods. WriteMethods(writer, settings.Methods); // The actual merge method. writer.Write(@" public static string "); writer.Write(method); writer.Write("("); WriteParameters(writer, properties); writer.Write(@") { using (MemoryStream stream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.UTF8)) { "); writer.Write(@" // Start of template. "); WriteText(writer, text, mimeType); writer.Write(@" // End of template. "); writer.Write(@" writer.Flush(); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { return reader.ReadToEnd(); } } } } } }"); writer.Flush(); stream.Position = 0; using (var reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } } }
CopyItem ITemplateEngine.GetCopyItem(CopyItemEngine copyItemEngine, TemplateContext context, TemplateProperties properties, string[] mimeTypes) { Initialise(); // Create an engine specifically for this template. return(CreateCopyItem(copyItemEngine, context, properties, mimeTypes)); }
private static CopyItem CreateCopyItem(CopyItemEngine copyItemEngine, TemplateContext context, TemplateProperties properties, ICollection <string> mimeTypes) { var copyItem = new CopyItem(copyItemEngine.GetCopyText(context, properties)); foreach (var pair in GetViewEngines(copyItemEngine.ViewEngines, mimeTypes)) { copyItem.ViewItems.Add(new ViewItem(pair.Key, pair.Value.GetCopyText(context, properties))); } return(copyItem); }