/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.Tales.BuiltinContextsContainer"/> class. /// </summary> /// <param name="options">Options.</param> /// <param name="repeat">Repeat.</param> /// <param name="attrs">Attrs.</param> /// <param name="templateFileFactory">A template-file factory.</param> /// <param name="model">The model being rendered.</param> public BuiltinContextsContainer(NamedObjectWrapper options, RepetitionMetadataCollectionWrapper repeat, Lazy<OriginalAttributeValuesCollection> attrs, ITemplateFileFactory templateFileFactory, object model = null) { if(options == null) { throw new ArgumentNullException(nameof(options)); } if(repeat == null) { throw new ArgumentNullException(nameof(repeat)); } if(attrs == null) { throw new ArgumentNullException(nameof(attrs)); } _nothing = null; _default = ZptConstants.CancellationToken; _options = options; _repeat = repeat; _attrs = attrs; _model = model; _templateFileFactory = templateFileFactory; }
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; }
public MvcTalesModel(IEvaluatorSelector evaluatorRegistry, NamedObjectWrapper options = null, IExpressionFactory expressionCreator = null, object model = null) : base(evaluatorRegistry, options, expressionCreator, model) { }
public MvcContextsContainer(NamedObjectWrapper options, RepetitionMetadataCollectionWrapper repeat, Lazy<OriginalAttributeValuesCollection> attrs, ViewContext viewContext, ITemplateFileFactory templateFileFactory = null) : base(options, repeat, attrs, templateFileFactory, viewContext?.ViewData?.Model) { _viewContext = viewContext?? new ViewContext(); _applicationDictionary = GetApplicationDictionary(viewContext); }
/// <summary> /// Initializes a new root of the <see cref="CSF.Zpt.Rendering.Model"/> class. /// </summary> /// <param name="options">Keyword options.</param> /// <param name="modelObject">The model to be rendered.</param> public Model(NamedObjectWrapper options, object modelObject = null) { _options = options?? new NamedObjectWrapper(); _parent = null; _root = this; this.LocalDefinitions = new Dictionary<string, object>(); _globalDefinitions = (_root == this)? new Dictionary<string,object>() : null; this.ModelObject = modelObject; }
/// <summary> /// Initializes a new instance of the <see cref="CSF.Zpt.Tales.TalesModel"/> class. /// </summary> /// <param name="evaluatorRegistry">Evaluator registry.</param> /// <param name="options">Options.</param> /// <param name="expressionCreator">The expression factory to use.</param> /// <param name="modelObject">An object to which the ZPT document is to be applied.</param> public TalesModel(IEvaluatorSelector evaluatorRegistry, NamedObjectWrapper options = null, IExpressionFactory expressionCreator = null, object modelObject = null) : base(options, modelObject) { if(evaluatorRegistry == null) { throw new ArgumentNullException(nameof(evaluatorRegistry)); } _registry = evaluatorRegistry; _expressionCreator = expressionCreator?? new ExpressionFactory(); }
/// <summary> /// Create a context instance. /// </summary> public virtual IRenderingContext Create(IZptElement element, IRenderingSettings options, object model) { if(element == null) { throw new ArgumentNullException(nameof(element)); } if(options == null) { throw new ArgumentNullException(nameof(options)); } NamedObjectWrapper metalKeywordOptions = new NamedObjectWrapper(MetalKeywordOptions), talKeywordOptions = new NamedObjectWrapper(TalKeywordOptions); IModel metalModel = new TalesModel(this.EvaluatorRegistry, metalKeywordOptions, modelObject: model), talModel = new TalesModel(this.EvaluatorRegistry, talKeywordOptions, modelObject: model); PopulateMetalModel(metalModel); PopulateTalModel(talModel); return new RenderingContext(metalModel, talModel, element, options, this.RootDocumentPath); }
/// <summary> /// Initializes a new instance of the <see cref="Test.CSF.Zpt.Rendering.DummyModel"/> class. /// </summary> /// <param name="options">Keyword options.</param> public DummyModel(NamedObjectWrapper options) : base(options) { }
/// <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; }
internal EmptyModel(NamedObjectWrapper opts) : base(opts) { }