示例#1
0
        public static Template FromStream(Stream stream, TemplateData data = null)
        {
            var template = new Template(data);

            template.Read(stream);
            return(template);
        }
示例#2
0
        // Static tools
        public static Template FromText(string text, TemplateData data = null)
        {
            var template = new Template(data);

            template.Parse(text);
            return(template);
        }
示例#3
0
        public static Template FromFile(string file, TemplateData data = null)
        {
            var template = new Template(data);

            template.Read(file);
            return(template);
        }
示例#4
0
        // Operations
        public void PushData(TemplateData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            _stack.Add(data);
        }
示例#5
0
        public string Render(TemplateData data = null)
        {
            var builder = new StringBuilder();

            using (var writer = new StringWriter(builder))
                Render(writer, data);

            return(builder.ToString());
        }
示例#6
0
        public void Render(TextWriter writer, TemplateData data = null)
        {
            var context = new TemplateContext(this, writer);

            context.PushData(_global.Data);

            if (_data != null)
            {
                context.PushData(_data);
            }

            if (data != null)
            {
                context.PushData(data);
            }

            context.PushData(Data);

            _elements.Render(context);
        }
示例#7
0
 // Construction
 public Template(TemplateData data = null)
     : base(_global)
 {
     _data = data;
 }
示例#8
0
 public static string RenderFromStream(Stream stream, TemplateData data = null)
 {
     return(FromStream(stream, data).Render());
 }
示例#9
0
 public static string RenderFromFile(string file, TemplateData data = null)
 {
     return(FromFile(file, data).Render());
 }
示例#10
0
 public static string RenderFromText(string text, TemplateData data = null)
 {
     return(FromText(text, data).Render());
 }