Ejemplo n.º 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("len", new TemplateFunction(FuncLen));
			functions.Add("tolist", new TemplateFunction(FuncToList));
			functions.Add("isnull", new TemplateFunction(FuncIsNull));
			functions.Add("not", new TemplateFunction(FuncNot));
			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("gt", new TemplateFunction(FuncGt));
			functions.Add("lt", new TemplateFunction(FuncLt));
			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));
		}
Ejemplo n.º 2
0
		public VariableScope(VariableScope parent)
		{
			this.parent = parent;
			this.values = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
		}
Ejemplo n.º 3
0
		protected void ProcessTemplate(string name, Tag tag)
		{
			Template useTemplate = currentTemplate.FindTemplate(name);
			if (useTemplate == null)
			{
				string msg = string.Format("Template '{0}' not found", name);
				WriteError(msg, tag.Line, tag.Col);
				return;
			}

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

			try
			{
				ProcessElements(tag.InnerElements);

				content = writer.ToString();
			}
			catch
			{
				return; // on error, do not do tag inclusion
			}
			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;
			}

			
		}
Ejemplo n.º 4
0
 public VariableScope(VariableScope parent)
 {
     this.parent = parent;
     this.values = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase);
 }