Ejemplo n.º 1
0
        private Template(string name, IList<Node> nodes, Template parent)
        {
            this.name = name;
            this.parent = parent;

            this.nodes = new List<Node>(nodes);
            childTemplates = new List<Template>();
            templateCache = new Dictionary<string, Template>(StringComparer.InvariantCultureIgnoreCase);
        }
Ejemplo n.º 2
0
        internal TemplateContext(Template template)
        {
            this.template = template;
            currentTemplate = template;

            variableScope = new VariableScope();

            RegisterBuiltInFunctions();
        }
Ejemplo n.º 3
0
        public static Template Parse(string name, string text)
        {
            Lexer lexer = new Lexer(text);
            TemplateParser parser = new TemplateParser(lexer);
            List<Node> nodes = parser.Parse();

            TagParser tagParser = new TagParser(nodes);
            nodes = tagParser.CreateHierarchy();

            Template template = new Template(name, nodes, null);

            foreach (Node elem in nodes) {
                if (elem is TagNode) {
                    TagNode tag = (TagNode)elem;
                    if (string.Compare(tag.TagName, "template", true) == 0) {
                        Expression ename = tag.GetAttributeValue("name");
                        string tname;
                        if (ename is StringLiteralExpression)
                            tname = ((StringLiteralExpression)ename).Value;
                        else
                            tname = "?";

                        template.childTemplates.Add(new Template(tname, tag.ChildNodes, template));
                    }
                }
            }

            return template;
        }
Ejemplo n.º 4
0
 public void AddTemplate(Template childTemplate)
 {
     lock (this) {
         template.ChildTemplates.Add(childTemplate);
     }
 }
Ejemplo n.º 5
0
        public void Transform(TextWriter output)
        {
            lock (this) {
                writer = output;
                currentTemplate = template;

                OnBeforeTransform();

                if (handler != null) {
                    handler.BeforeTransform(this);
                    SetValue("this", handler);
                }

                ProcessNodes(template.Nodes);

                OnAfterTransform();

                if (handler != null)
                    handler.AfterTransform(this);
            }
        }