Esempio n. 1
0
        public TemplateParser(string name, string content)
        {
            Result = new Representation.Template(name, null);
            Templates.Push(Result);
            CurrentProcessFunc = pf_Default;
            Buffer.Clear();
            LineNumber   = 1;
            ColumnNumber = 1;

            foreach (char c in content)
            {
                CurrentProcessFunc(c);
                if (c == '\n')
                {
                    ++LineNumber;
                    ColumnNumber = 1;
                }
                else
                {
                    ++ColumnNumber;
                }
            }
            StoreCurrentBuffer();
            Trace.Assert(Templates.Count == 1);
            Trace.Assert(Templates.Peek() == Result);
        }
Esempio n. 2
0
        public string RenderTemplate(Representation.Template template, object data)
        {
            var context = new RenderContext(this);

            context.TemplateHierarchy.Add(template);
            while (!string.IsNullOrEmpty(template.Extends))
            {
                var parentTemplate = KnownTemplates[template.Extends];
                template.Parent = parentTemplate;
                context.TemplateHierarchy.Add(parentTemplate);
                template = parentTemplate;
            }

            foreach (var item in template.Items)
            {
                item.Render(context, data);
            }
            return(context.Result.ToString());
        }
Esempio n. 3
0
        private void FeedGenericExpression()
        {
            string content = Buffer.ToString().Trim();

            if (!string.IsNullOrEmpty(content))
            {
                // HACK HACK HACK
                if (content.StartsWith("block "))
                {
                    string blockName = content.Substring(6);
                    var    t         = new Representation.Template(blockName, Templates.Peek());
                    Templates.Peek().Items.Add(t);
                    Templates.Push(t);
                    Trace.Assert(Templates.Peek() == t);
                }
                else if (content.Equals("endblock"))
                {
                    Trace.Assert(Templates.Count > 1);
                    Templates.Pop();
                }
                else if (content.StartsWith("extends "))
                {
                    string blockName = content.Substring(8).Trim();
                    Trace.Assert(blockName.StartsWith("\""));
                    Trace.Assert(blockName.EndsWith("\""));
                    blockName = blockName.Substring(1, blockName.Length - 2);
                    Templates.Peek().Extends = blockName;
                }
                else
                {
                    Trace.TraceError("Don't konw bloc: {0}", content);
                    Trace.Assert(false);
                }
            }
            Buffer.Clear();
        }
Esempio n. 4
0
 public VariableLookup(Template parent)
 {
     Parent = parent;
 }