public async Task <string> Build(DirectoryPath path, IEnumerable <string> versions) { if (path is null) { throw new ArgumentNullException(nameof(path)); } if (versions is null) { throw new ArgumentNullException(nameof(versions)); } // Compile the template var template = ScribanTemplate.Parse(File.ReadAllText(Template)); // Get all data var data = await GetAllData(path, versions, Filter); // Prepare template context var context = new TemplateContext(); context.LoopLimit = int.MaxValue; context.PushGlobal(new ScribanHelpers()); context.PushGlobal(new ScriptObject { ["data"] = data, ["name"] = ClassName, }); // Render template return(template.Render(context)); }
public static void Prepare() { compile = Scriban.Template.ParseLiquid(template); List <object> rows = new List <object>(); for (int i = 0; i < 100; i++) { rows.Add(new Dictionary <string, object> { { "ID", i }, { "Message", string.Format("message {0}", i) }, { "Print", i % 2 == 0 }, }); } hash = new Dictionary <string, object> { { "rows", rows } }; }
public Template(Scriban.Template template) { _template = template; }
/// <summary> /// Parses the specified scripting text into a <see cref="Template"/> . /// </summary> /// <param name="text">The scripting text.</param> /// <param name="sourceFilePath">The source file path. Optional, used for better error reporting if the source file has a location on the disk</param> /// <param name="options">The templating parsing options.</param> /// <returns>A template</returns> public static Template Parse(string text, string sourceFilePath = null, ParserOptions options = null) { var template = new Template(options, sourceFilePath); template.ParseInternal(text, sourceFilePath); return template; }