Entry point class to parse templates and render them.
コード例 #1
0
        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));
        }
コード例 #2
0
    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 }
        };
    }
コード例 #3
0
 public Template(Scriban.Template template)
 {
     _template = template;
 }
コード例 #4
0
ファイル: Template.cs プロジェクト: lunet-io/scriban
 /// <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;
 }