Beispiel #1
0
 public RenderContext(Section section, object data, TextWriter writer, TemplateLocator templateLocator)
 {
     _sectionStack.Push(section);
     _dataStack.Push(data);
     _writer = writer;
     _templateLocator = templateLocator;
     _includeLevel = 0;
 }
Beispiel #2
0
        public void Parse(Section section, IEnumerable<Part> parts)
        {
            if (section == null)
                throw new ArgumentNullException("section");

            var sectionStack = new Stack<Section>();
            sectionStack.Push(section);

            foreach (var part in parts)
            {
                section.Add(part);

                if (part is Section)
                {
                    var newSection = (Section)part;

                    if (newSection.Name == "else")
                    {
                        section.Inverse = newSection;
                        newSection.Inverse = section;
                        section = newSection;
                    }
                    else
                    {
                        sectionStack.Push(section);
                        section = newSection;
                    }
                }
                else if (part is EndSection)
                {
                    var endSection = (EndSection)part;

                    if (section.Name == "else")
                    {
                        section = section.Inverse;
                    }

                    if (sectionStack.Count == 1)
                    {
                        throw new NustacheException(
                            string.Format(
                                "End section {0} does not match any start section!",
                                endSection.Name));
                    }

                    if (endSection.Name.Split()[0].Trim() != section.Name.Split()[0].Trim())
                    {
                        throw new NustacheException(
                            string.Format(
                                "End section {0} does not match start section {1}!",
                                endSection.Name,
                                section.Name));
                    }

                    section = sectionStack.Pop();
                }
            }
        }
Beispiel #3
0
        public CompileContext(Section section, Type targetType, Expression dataParam, TemplateLocator templateLocator)
        {
            this.targetType = targetType;
            this.renderContext = new RenderContext(section, null, null, templateLocator);
            this.templateLocator = templateLocator;

            _targetObjectStack.Push(dataParam);
            _sectionStack.Push(section);
        }
 public void Visit(Section section)
 {
     foreach (var part in section.Parts)
     {
         part.Accept(this);
     }
     
     result = Concat(parts.Where(part => part != null));
 }
Beispiel #5
0
 public RenderContext(Section section, object data, TextWriter writer, TemplateLocator templateLocator,
     IValueProviderCollection valueProviders)
 {
     _sectionStack.Push(section);
     _dataStack.Push(data);
     _writer = writer;
     _templateLocator = templateLocator;
     _valueProviders = valueProviders;
     _includeLevel = 0;
 }
Beispiel #6
0
        public RenderContext(Section section, object data, TextWriter writer, TemplateLocator templateLocator, RenderContextBehaviour renderContextBehaviour = null)
        {
            _sectionStack.Push(section);
            _dataStack.Push(data);
            _writer = writer;
            _templateLocator = templateLocator;
            _includeLevel = 0;

            _renderContextBehaviour = renderContextBehaviour ??
                                      RenderContextBehaviour.GetDefaultRenderContextBehaviour();
        }
Beispiel #7
0
 public void Push(Section section, object data)
 {
     _sectionStack.Push(section);
     _dataStack.Push(data);
 }
Beispiel #8
0
 public void Enter(Section section)
 {
     _sectionStack.Push(section);
 }
Beispiel #9
0
 internal void Push(Section section, object data)
 {
     _sectionStack.Push(section);
     _dataStack.Push(data);
     if (section != null)
     {
         section.Data = data;
     }
 }
Beispiel #10
0
 internal void Push(Section section, Expression targetObjectRef)
 {
     _sectionStack.Push(section);
     _targetObjectStack.Push(targetObjectRef);
 }
Beispiel #11
0
 public RenderContext(Section section, object data, TextWriter writer, TemplateLocator templateLocator)
     : this(section, data, writer, templateLocator, new ValueProviderCollection())
 {
 }