Esempio n. 1
0
        public void PushContext(IDictionary <string, object> input, ISeekable text, TextHolder parentHolder, bool skipOutput = false, bool disableLogging = false)
        {
            var holderDefinitions = parentHolder == null ? null : Context.PreparsedHolders.GetOrDefault(parentHolder.Name);

            if (parentHolder != null && Context.Holders.ContainsKey(parentHolder.Name))
            {
                parentHolder = Context.Holders[parentHolder.Name];
            }
            var newC = new TemplatorParsingContext(skipOutput)
            {
                Input            = input,
                ParentHolder     = parentHolder,
                Logger           = disableLogging ? null : (Context != null && Context.Nesting) ? new TemplatorLogger() : Config.Logger,
                Text             = text ?? Context?.Text,
                PreparsedHolders = holderDefinitions?.Children
            };

            if (Stack == null)
            {
                Context = newC;
                Stack   = new Stack <TemplatorParsingContext>();
                if (input == null)
                {
                    NoInput = true;
                }
                return;
            }
            Stack.Push(Context);
            Context = newC;
        }
Esempio n. 2
0
        public void PopContext()
        {
            var c = Context;

            Context = Stack.Pop();
            if (c.ParentHolder != null)
            {
                if (Context.Nesting)
                {
                    Context.ChildLogger = c.Logger;
                    Context.Holders     = TemplatorUtil.MergeHolders(Context.Holders, c.Holders.Values);
                }
                else
                {
                    c.ParentHolder.Children = TemplatorUtil.MergeHolders(c.ParentHolder.Children, c.Holders.Values);
                }
            }
            if (Context.NestingBefore)
            {
                Context.ChildResultBefore.Append(c.Result);
            }
            else if (Context.NestingAfter)
            {
                Context.ChildResultAfter.Append(c.Result);
            }
            else
            {
                AppendResult(c.Result);
            }
        }
Esempio n. 3
0
 public TemplatorParser(TemplatorConfig config)
 {
     Config = config;
     config.PrepareKeywords();
     config.Logger = config.Logger ?? new TemplatorLogger();
     Context       = new TemplatorParsingContext();
 }
Esempio n. 4
0
 public void StartOver(bool clearHolders = true)
 {
     RemovingElements.Clear();
     Stack = null;
     XmlStack.Clear();
     XmlContext = null;
     Context    = new TemplatorParsingContext();
     Csv        = false;
     NoInput    = false;
     if (clearHolders)
     {
         Holders.Clear();
     }
 }