Esempio n. 1
0
		Template currentTemplate;		// current template being executed

		/// <summary>
		/// create template manager using a template
		/// </summary>
		public TemplateManager(Template template)
		{
			this.mainTemplate = template;
			this.currentTemplate = template;

			Init();
		}
Esempio n. 2
0
		public Template(string name, List<Element> elements, Template parent)
		{
			this.name = name;
			this.elements = elements;
			this.parent = parent;

			InitTemplates();
		}
Esempio n. 3
0
		/// <summary>
		/// adds template that can be used within execution 
		/// </summary>
		/// <param name="template"></param>
		public void AddTemplate(Template template)
		{
			mainTemplate.Templates.Add(template.Name, template);
		}
Esempio n. 4
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;
			}

			
		}
Esempio n. 5
0
		/// <summary>
		/// processes current template and sends output to writer
		/// </summary>
		/// <param name="writer"></param>
		public void Process(TextWriter writer)
		{
			this.writer = writer;
			this.currentTemplate = mainTemplate;

			ProcessElements(mainTemplate.Elements);
		}
Esempio n. 6
0
		/// <summary>
		/// go thru all tags and see if they are template tags and add
		/// them to this.templates collection
		/// </summary>
		private void InitTemplates()
		{
			this.templates = new Dictionary<string, Template>(StringComparer.InvariantCultureIgnoreCase);

			foreach (Element elem in elements)
			{
				if (elem is Tag)
				{
					Tag tag = (Tag)elem;
					if (string.Compare(tag.Name, "template", true) == 0)
					{
						Expression ename = tag.AttributeValue("name");
						string tname;
						if (ename is StringLiteral)
							tname = ((StringLiteral)ename).Content;
						else
							tname = "?";

						Template template = new Template(tname, tag.InnerElements, this);
						templates[tname] = template;
					}
				}
			}
		}