Exemple #1
0
        private void Initialize()
        {
            Root = ParentContext?.Root ?? this;

            if (!ReferenceEquals(Root, this))
            {
                Root.RootDataObject.CopyTo(ContextDataObject);
            }
            ContextDataObject.AddOrReplace(ChainSegment.Root, Root.Value, out WellKnownVariables[(int)WellKnownVariable.Root]);

            if (ParentContext == null)
            {
                ContextDataObject.AddOrReplace(
                    ChainSegment.Parent,
                    UndefinedBindingResult.Create(ChainSegment.Parent),
                    out WellKnownVariables[(int)WellKnownVariable.Parent]
                    );

                return;
            }

            ContextDataObject.AddOrReplace(
                ChainSegment.Parent,
                ParentContext.Value,
                out WellKnownVariables[(int)WellKnownVariable.Parent]
                );

            Bag.Outer = ParentContext.Bag;
            ParentContext.BlockParamsObject.CopyTo(BlockParamsObject);

            //Inline partials cannot use the Handlebars.RegisteredTemplate method
            //because it pollutes the static dictionary and creates collisions
            //where the same partial name might exist in multiple templates.
            //To avoid collisions, pass around a dictionary of compiled partials
            //in the context
            InlinePartialTemplates.Outer = ParentContext.InlinePartialTemplates;

            if (!(Value is HashParameterDictionary dictionary) || ParentContext.Value == null || ReferenceEquals(Value, ParentContext.Value))
            {
                return;
            }

            // Populate value with parent context
            PopulateHash(dictionary, ParentContext.Value);
        }
 public void Write(UndefinedBindingResult undefined) => UnderlyingWriter.Write(undefined);