예제 #1
0
        private void ExecuteRazorDocumentParser()
        {
            if (_parser.NextChar() != RazorParser.CommentChar)
            {
                _parser.StartViewResponse();
            }
            IDocumentParser parser = new RazorDocumentParser(_root != null ? _root : this, _htmlParser);

            parser.Execute(_parser);
        }
예제 #2
0
 private void ReadTemplate(char chr, char prev, int index)
 {
     //TODO avoid multiple instances
     if (chr == TagStartChr)
     {
         IDocumentParser parser = new HtmlDocumentParser();
         parser.Execute(this);
     }
     else if (chr == RazorChr)
     {
         IDocumentParser parser = new RazorDocumentParser();
         parser.Execute(this);
     }
     else
     {
         _buffer.Append(chr);
     }
 }
예제 #3
0
 private bool HandleText(char chr, int index)
 {
     if (chr == RazorParser.NewLineChr || chr == RazorParser.ReturnChr)
     {
         WriteBuffer(chr);
         FlushBuffer();
         if (_root == null)
         {
             _parser.EndViewResponse();
         }
         return(true);
     }
     else if (chr == RazorParser.RazorChr)
     {
         FlushBuffer();
         IDocumentParser parser = new RazorDocumentParser(_root != null ? _root : this);
         parser.Execute(_parser);
     }
     else
     {
         WriteBuffer(chr);
     }
     return(false);
 }
예제 #4
0
 public RazorDocumentParser(RazorDocumentParser razorParser, HtmlDocumentParser htmlParser)
     : this()
 {
     _root       = razorParser;
     _htmlParser = htmlParser;
 }
예제 #5
0
 public RazorDocumentParser(RazorDocumentParser rootParser) : this()
 {
     _root = rootParser;
 }
        private bool Process(char chr, int index)
        {
            if (chr == RazorParser.RazorChr)
            {
                if (_buffer.Length > 0)
                {
                    _parser.WriteHtml(_buffer.ToString());
                    _buffer.Clear();
                }
                IDocumentParser parser = new RazorDocumentParser(_razor, _root != null ? _root : this);
                parser.Execute(_parser);
            }
            else
            {
                WriteBuffer(chr);
                char prev = _parser.GetCharacterAtIndex(index - 1), next = _parser.GetCharacterAtIndex(index + 1);

                if (_textMode && _buffer.Length >= 6 && chr == RazorParser.TagEndChr)
                {
                    if (_parser.FindNextChars(index - 5, RazorParser.TextTag) > -1)
                    {
                        _buffer.Remove(_buffer.Length - 6, 6);
                    }
                }
                else if (chr == RazorParser.TagStartChr && (prev != RazorParser.QuoteChr || prev != RazorParser.SingleQuoteChr) && (next != RazorParser.TagCloseChr))
                {
                    if (_textMode)
                    {
                        if (_parser.FindNextChars(index, RazorParser.TextTag) > -1)
                        {
                            _tcounter++;
                        }
                    }
                    else
                    {
                        _tcounter++;
                    }
                }
                else if (chr == RazorParser.TagCloseChr && (prev == RazorParser.TagStartChr || next == RazorParser.TagEndChr))
                {
                    if (_textMode)
                    {
                        if (_parser.FindNextChars(index - 1, RazorParser.TextCloseTag) > -1)
                        {
                            _tcounter--;
                        }
                    }
                    else
                    {
                        _tcounter--;
                    }
                }

                if (_tcounter == 0)
                {
                    while (true)
                    {
                        chr = _parser.GetCharacterAtIndex(++_parser.charIndex);
                        if (!_textMode)
                        {
                            WriteBuffer(chr);
                        }
                        if (chr == RazorParser.TagEndChr)
                        {
                            break;
                        }
                    }
                    if (_textMode)
                    {
                        _buffer.Remove(_buffer.Length - 2, 2);
                    }
                    _parser.WriteHtml(_buffer.ToString());
                    if (_razor == null)
                    {
                        _parser.EndViewResponse();
                    }
                    _buffer.Clear();
                    return(true);
                }
            }
            return(false);
        }
 public HtmlDocumentParser(HtmlDocumentParser root, RazorDocumentParser razor) : this()
 {
     _root  = root;
     _razor = razor;
 }