Пример #1
0
        /// <summary>
        /// Parse node contents add return a fresh node.
        /// </summary>
        /// <param name="prototypes">List containing all node types</param>
        /// <param name="parent">Node that this is a subnode to. Can be null</param>
        /// <param name="line">Line to parse</param>
        /// <param name="offset">Where to start the parsing. Should be set to where the next node should start parsing.</param>
        /// <returns>A node corresponding to the bla bla; null if parsing failed.</returns>
        /// <exception cref="CodeGeneratorException"></exception>
        public override Node Parse(NodeList prototypes, Node parent, LineInfo line, ref int offset)
        {
            if (line.Data[offset] != '{')
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Attribute cant handle info at char " + offset + 1);
            }

            int endPos = GetEndPos(offset, line.Data, '}');

            if (endPos == -1)
            {
                throw new CodeGeneratorException(line.LineNumber, line.Data, "Failed to find end of attribute list: '" + line.UnparsedData + "'.");
            }

            List <Attribute> col        = new List <Attribute>();
            string           attributes = line.Data.Substring(offset + 1, endPos - offset - 1);

            ParseAttributes(line, attributes, col);
            offset = endPos + 1;


            AttributeNode node = (AttributeNode)prototypes.CreateNode("{", parent);

            node._attributes = col;
            return(AddMe(prototypes, parent, line, node));
        }
Пример #2
0
        public void TestPartial3()
        {
                        LineInfo line = new LineInfo(1, string.Empty);
            line.Set("%a{href=\"/settings/divert/remove/\", title=Language[\"RemoveDivert\"] }", 0, 0);

            TagNode tagNode = new TagNode(null);
            NodeList nodes = new NodeList();
            AttributeNode node = new AttributeNode(tagNode);
            nodes.Add(node);
            nodes.Add(tagNode);

            int offset = 2;
            AttributeNode myNode = (AttributeNode)node.Parse(nodes, tagNode, line, ref offset);

            bool inStr = true;
            string res = myNode.ToCode(ref inStr, false);

            //Assert.Equal("\"this\"+testCase.Id+\"id\"", myNode.GetAttribute("value").Value);
            //Assert.Equal("value=\"\"\"); sb.Append(\"this\"+testCase.Id+\"id\"); sb.Append(@\"\"\"", res);
        }
Пример #3
0
        public void TestPartial2()
        {
                        LineInfo line = new LineInfo(1, string.Empty);
            line.Set("%input{ value=\"http://\"+domain+\"/voicemail/listen/\" + item.Id }", 0, 0);

            TagNode tagNode = new TagNode(null);
            NodeList nodes = new NodeList();
            AttributeNode node = new AttributeNode(tagNode);
            nodes.Add(node);
            nodes.Add(tagNode);

            int offset = 6;
            AttributeNode myNode = (AttributeNode)node.Parse(nodes, tagNode, line, ref offset);

            bool inStr = true;
            string res = myNode.ToCode(ref inStr, false);

            Assert.Equal("\"this\"+testCase.Id+\"id\"", myNode.GetAttribute("value").Value);
            Assert.Equal("value=\"\"\"); sb.Append(\"this\"+testCase.Id+\"id\"); sb.Append(@\"\"\"", res);
        }
Пример #4
0
        public void Test()
        {
            LineInfo line = new LineInfo(1, string.Empty);
            line.Set("%input{ type=\"checkbox\", value=testCase.Id, name=\"case\", class=lastCat.Replace(' ', '-')}", 0,
                     0);

            TagNode tagNode = new TagNode(null);
            NodeList nodes = new NodeList();
            AttributeNode node = new AttributeNode(tagNode);
            nodes.Add(node);
            nodes.Add(tagNode);

            int offset = 6;
            AttributeNode myNode  = (AttributeNode)node.Parse(nodes, tagNode, line, ref offset);
            bool t = false;
            string temp = myNode.ToCode(ref t, false);
            Assert.Equal("\"checkbox\"", myNode.GetAttribute("type").Value);
            Assert.Equal("testCase.Id", myNode.GetAttribute("value").Value);
            Assert.Equal("\"case\"", myNode.GetAttribute("name").Value);
            Assert.Equal("lastCat.Replace(' ', '-')", myNode.GetAttribute("class").Value);
        }