Beispiel #1
0
        void Init()
        {
            this.functions = new Dictionary<string, TemplateFunction>(StringComparer.InvariantCultureIgnoreCase);

            this.variables = new VariableScope();

            functions.Add("equals", new TemplateFunction(FuncEquals));
            functions.Add("notequals", new TemplateFunction(FuncNotEquals));
            functions.Add("iseven", new TemplateFunction(FuncIsEven));
            functions.Add("isodd", new TemplateFunction(FuncIsOdd));
            functions.Add("isempty", new TemplateFunction(FuncIsEmpty));
            functions.Add("isnotempty", new TemplateFunction(FuncIsNotEmpty));
            functions.Add("isnumber", new TemplateFunction(FuncIsNumber));
            functions.Add("toupper", new TemplateFunction(FuncToUpper));
            functions.Add("tolower", new TemplateFunction(FuncToLower));
            functions.Add("isdefined", new TemplateFunction(FuncIsDefined));
            functions.Add("ifdefined", new TemplateFunction(FuncIfDefined));
            functions.Add("length", new TemplateFunction(FuncLength));
            functions.Add("tolist", new TemplateFunction(FuncToList));
            functions.Add("isnull", new TemplateFunction(FuncIsNull));
            functions.Add("gt", new TemplateFunction(FuncGt));
            functions.Add("lt", new TemplateFunction(FuncLt));
            functions.Add("not", new TemplateFunction(FuncNot));
            functions.Add("div", new TemplateFunction(FuncDiv));//2012-03-15增加

            functions.Add("iif", new TemplateFunction(FuncIif));
            functions.Add("format", new TemplateFunction(FuncFormat));
            functions.Add("trim", new TemplateFunction(FuncTrim));
            functions.Add("filter", new TemplateFunction(FuncFilter));

            functions.Add("compare", new TemplateFunction(FuncCompare));
            functions.Add("or", new TemplateFunction(FuncOr));
            functions.Add("and", new TemplateFunction(FuncAnd));
            functions.Add("comparenocase", new TemplateFunction(FuncCompareNoCase));
            functions.Add("stripnewlines", new TemplateFunction(FuncStripNewLines));
            functions.Add("typeof", new TemplateFunction(FuncTypeOf));
            functions.Add("cint", new TemplateFunction(FuncCInt));
            functions.Add("cdouble", new TemplateFunction(FuncCDouble));
            functions.Add("cdate", new TemplateFunction(FuncCDate));
            functions.Add("cdatestring", new TemplateFunction(FuncCDateString));
            functions.Add("floatstring", new TemplateFunction(FuncFloatString));
            functions.Add("now", new TemplateFunction(FuncNow));
            functions.Add("createtypereference", new TemplateFunction(FuncCreateTypeReference));
            functions.Add("nohtml", new TemplateFunction(FuncNoHTML));
            functions.Add("cutstring", new TemplateFunction(FuncCutString));
            functions.Add("htmlencode", new TemplateFunction(FuncHTMLEncode));
            functions.Add("htmldecode", new TemplateFunction(FuncHTMLDecode));
        }
Beispiel #2
0
        protected void ProcessTemplate(string name, Tag tag)
        {
            if (customTags != null && customTags.ContainsKey(name))
            {
                ExecuteCustomTag(tag);
                return;
            }

            Template useTemplate = currentTemplate.FindTemplate(name);
            if (useTemplate == null)
            {
                string msg = string.Format("Template '{0}' not found", name);
                throw new TemplateRuntimeException(msg, tag.Line, tag.Col);
            }

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

            try
            {
                ProcessElements(tag.InnerElements);

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

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

            try
            {
                foreach (TagAttribute attrib in tag.Attributes)
                {
                    object val = EvalExpression(attrib.Expression);
                    variables[attrib.Name] = val;
                }

                currentTemplate = useTemplate;
                ProcessElements(currentTemplate.Elements);
            }
            finally
            {
                variables = variables.Parent;
                currentTemplate = saveTemplate;
            }
        }
Beispiel #3
0
 public VariableScope(VariableScope parent)
 {
     this.parent = parent;
     this.values = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
 }