Ejemplo n.º 1
0
        internal TemplateContext(Template template)
        {
            this.template = template;
            currentTemplate = template;

            variableScope = new VariableScope();

            RegisterBuiltInFunctions();
        }
Ejemplo n.º 2
0
        private void ProcessTemplate(string name, TagNode tag)
        {
            if (customTags != null && customTags.ContainsKey(name)) {
                ExecuteCustomTag(tag);
                return;
            }

            Template useTemplate = currentTemplate.FindTemplate(name);
            if (useTemplate == null)
                throw new TemplateException(String.Format("Template '{0}' not found", name), tag.Line, tag.Column);

            // process inner elements and save content
            TextWriter saveWriter = writer;
            writer = new StringWriter();
            string content = String.Empty;

            try {
                ProcessNodes(tag.ChildNodes);

                content = writer.ToString();
            } finally {
                writer = saveWriter;
            }

            Template saveTemplate = currentTemplate;
            variableScope = new VariableScope(variableScope);
            variableScope["innerText"] = content;

            try {
                foreach (TagNodeAttribute attrib in tag.Attributes) {
                    object val = EvaluateExpression(attrib.Value);
                    variableScope[attrib.Name] = val;
                }

                currentTemplate = useTemplate;
                ProcessNodes(currentTemplate.Nodes);
            } finally {
                variableScope = variableScope.Parent;
                currentTemplate = saveTemplate;
            }
        }
Ejemplo n.º 3
0
        public VariableScope(VariableScope parent)
        {
            this.parent = parent;

            values = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
        }