protected override IRenderingContextFactory CreateTestEnvironment(DirectoryInfo rootPath) { var output = (TalesRenderingContextFactory) base.CreateTestEnvironment(rootPath); // The location of the other ZPT documents output.MetalLocalDefinitions.Add("documents", new TemplateDirectory(this.SourcePath)); var tests = new NamedObjectWrapper(); tests["input"] = new TemplateDirectory(this.SourcePath, true); output.MetalLocalDefinitions.Add("tests", tests); // The 'content' keyword option var content = new NamedObjectWrapper(); content["args"] = "yes"; output.TalKeywordOptions.Add("content", content); // The 'batch' keyword option var batch = new EnumerableObjectWrapperWithNamedItems(); batch["previous_sequence"] = false; batch["previous_sequence_start_item"] = "yes"; batch["next_sequence"] = true; batch["next_sequence_start_item"] = "six"; batch["next_sequence_end_item"] = "ten"; var items = Enumerable .Range(1, 5) .Select(x => { var item = new NamedObjectWrapper(); item["num"] = x.ToString(); return item; }) .ToArray(); items[0].SetStringRepresentation("one"); items[1].SetStringRepresentation("two"); items[2].SetStringRepresentation("three"); items[3].SetStringRepresentation("four"); items[4].SetStringRepresentation("five"); foreach(var item in items) { batch.Items.Add(item); } output.TalKeywordOptions.Add("batch", batch); // The 'laf' keyword option // The 'getProducts' option var getProducts = new [] { new NamedObjectWrapper(), new NamedObjectWrapper(), }; getProducts[0]["description"] = "This is the tee for those who LOVE Zope. Show your heart on your tee."; getProducts[0]["image"] = "smlatee.jpg"; getProducts[0]["price"] = 12.99m; getProducts[1]["description"] = "This is the tee for Jim Fulton. He's the Zope Pope!"; getProducts[1]["image"] = "smpztee.jpg"; getProducts[1]["price"] = 11.99m; output.TalKeywordOptions.Add("getProducts", getProducts); return output; }
/// <summary> /// Gets the rendering context configurator for a given job. /// </summary> /// <returns>The context configurator.</returns> /// <param name="job">Job.</param> protected virtual Action<IModelValueContainer> GetContextConfigurator(IRenderingJob job) { return ctx => { if(job.InputRootDirectory != null) { var docRoot = new TemplateDirectory(job.InputRootDirectory); ctx.MetalModel.AddGlobal("documents", docRoot); } }; }
/// <summary> /// Gets a built-in object by name (a TALES path fragment). /// </summary> /// <returns><c>true</c> if the path traversal was a success; <c>false</c> otherwise.</returns> /// <param name="pathFragment">The path fragment.</param> /// <param name="result">Exposes the result if the traversal was a success</param> /// <param name="currentContext">Gets the current rendering context.</param> public override bool HandleTalesPath(string pathFragment, out object result, IRenderingContext currentContext) { bool output; switch(pathFragment) { case VIEW_DATA_DICTIONARY: output = ViewContext.ViewData != null; result = output? new NamedObjectWrapper(ViewContext.ViewData) : null; break; case TEMP_DATA_DICTIONARY: output = ViewContext.TempData != null; result = output? new NamedObjectWrapper(ViewContext.TempData) : null; break; case APPLICATION_DICTIONARY: result = new NamedObjectWrapper(_applicationDictionary.Value); output = true; break; case CACHE_DICTIONARY: result = ViewContext.HttpContext?.Cache; output = result != null; break; case REQUEST: result = ViewContext.HttpContext?.Request; output = result != null; break; case REQUEST_LOWER: result = ViewContext.HttpContext?.Request; output = result != null; break; case RESPONSE: result = ViewContext.HttpContext?.Response; output = result != null; break; case ROUTE_DATA: result = ViewContext.RouteData; output = result != null; break; case SERVER: result = ViewContext.HttpContext?.Server; output = result != null; break; case SESSION_DICTIONARY: result = ViewContext.HttpContext?.Session; output = result != null; break; case TYPED_MODEL: result = ViewContext.ViewData?.Model; output = (result != null); break; case VIEWS_DIRECTORY: var viewsDirectoryPath = ViewContext.HttpContext.Server.MapPath(VIEWS_VIRTUAL_PATH); result = new TemplateDirectory(new DirectoryInfo(viewsDirectoryPath)); output = true; break; default: output = false; result = null; break; } if(!output) { output = base.HandleTalesPath(pathFragment, out result, currentContext); } return output; }