コード例 #1
0
            public static SliceZone Parse(JToken json)
            {
                var slices = new List <Slice>();

                foreach (JToken sliceJson in (JArray)json)
                {
                    String sliceType = (string)sliceJson["slice_type"];
                    String label     = (string)sliceJson["slice_label"];

                    // Handle Deprecated SliceZones
                    JToken fragJson = sliceJson["value"];
                    if (fragJson != null)
                    {
                        string   fragmentType  = (string)fragJson["type"];
                        JToken   fragmentValue = fragJson["value"];
                        Fragment value         = FragmentParser.Parse(fragmentType, fragmentValue);
                        slices.Add(new SimpleSlice(sliceType, label, value));
                    }
                    else
                    {
                        //Parse new format non-repeating slice zones
                        JObject  nonRepeatsJson = (JObject)sliceJson["non-repeat"];
                        GroupDoc nonRepeat      = GroupDoc.Parse(nonRepeatsJson);
                        JArray   repeatJson     = (JArray)sliceJson["repeat"];
                        Group    repeat         = Group.Parse(repeatJson);
                        slices.Add(new CompositeSlice(sliceType, label, repeat, nonRepeat));
                    }
                }
                return(new SliceZone(slices));
            }
コード例 #2
0
ファイル: DomFragment.cs プロジェクト: wangscript007/roycms
        /// <summary>
        /// 从指定 HTML 创建一个 DomFragment 实例
        /// </summary>
        /// <param name="manager">文档碎片管理器</param>
        /// <param name="html">要分析成碎片的原始 HTML 文本</param>
        public DomFragment(DomFragmentManager manager, string html)
            : this( manager )
        {
            var parser = new FragmentParser();

            parser.ProcessFragment(html, this);
        }
コード例 #3
0
        public void CanParseFragmentWithParamBlockWithInitialValues()
        {
            // Arrange.
            Lexer lexer = new Lexer(null, @"fragment basic_material;

				[params]
				float alpha : ALPHA = 1.0f;
				float3 dir = float3(1.0f, -1.1f, 0.0);
				bool enable = false;"                );

            FragmentParser parser = new FragmentParser(null, lexer.GetTokens());

            // Act.
            FragmentNode fragment = parser.Parse();

            // Assert.
            Assert.AreEqual("basic_material", fragment.Name);
            Assert.IsNotNull(fragment.Parameters);
            Assert.AreEqual(3, fragment.Parameters.VariableDeclarations.Count);
            Assert.AreEqual(TokenType.Float, fragment.Parameters.VariableDeclarations[0].DataType);
            Assert.AreEqual("alpha", fragment.Parameters.VariableDeclarations[0].Name);
            Assert.AreEqual("ALPHA", fragment.Parameters.VariableDeclarations[0].Semantic);
            Assert.AreEqual("1", fragment.Parameters.VariableDeclarations[0].InitialValue);
            Assert.AreEqual(TokenType.Float3, fragment.Parameters.VariableDeclarations[1].DataType);
            Assert.AreEqual("dir", fragment.Parameters.VariableDeclarations[1].Name);
            Assert.AreEqual("float3(1,-1.1,0)", fragment.Parameters.VariableDeclarations[1].InitialValue);
            Assert.AreEqual(TokenType.Bool, fragment.Parameters.VariableDeclarations[2].DataType);
            Assert.AreEqual("enable", fragment.Parameters.VariableDeclarations[2].Name);
            Assert.AreEqual("false", fragment.Parameters.VariableDeclarations[2].InitialValue);
        }
コード例 #4
0
            public static SliceZone Parse(JToken json)
            {
                var slices = new List <Slice>();

                foreach (JToken sliceJson in (JArray)json)
                {
                    String   sliceType     = (string)sliceJson["slice_type"];
                    String   label         = (string)sliceJson["slice_label"];
                    JToken   fragJson      = sliceJson["value"];
                    String   fragmentType  = (string)fragJson["type"];
                    JToken   fragmentValue = fragJson["value"];
                    Fragment value         = FragmentParser.Parse(fragmentType, fragmentValue);
                    slices.Add(new Slice(sliceType, label, value));
                }
                return(new SliceZone(slices));
            }
コード例 #5
0
        public static GroupDoc Parse(JToken json)
        {
            var fragmentMap = new Dictionary <String, Fragment>();

            foreach (KeyValuePair <String, JToken> field in (JObject)json)
            {
                String   fragmentType  = (string)field.Value["type"];
                JToken   fragmentValue = field.Value["value"];
                Fragment fragment      = FragmentParser.Parse(fragmentType, fragmentValue);
                if (fragment != null)
                {
                    fragmentMap[field.Key] = fragment;
                }
            }

            return(new GroupDoc(fragmentMap));
        }
コード例 #6
0
            public static Group Parse(JToken json)
            {
                var groupDocs = new List <GroupDoc> ();

                foreach (JToken groupJson in (JArray)json)
                {
                    // each groupJson looks like this: { "somelink" : { "type" : "Link.document", { ... } }, "someimage" : { ... } }
                    var fragmentMap = new Dictionary <String, Fragment>();
                    foreach (KeyValuePair <String, JToken> field in (JObject)groupJson)
                    {
                        String   fragmentType  = (string)field.Value["type"];
                        JToken   fragmentValue = field.Value["value"];
                        Fragment fragment      = FragmentParser.Parse(fragmentType, fragmentValue);
                        if (fragment != null)
                        {
                            fragmentMap[field.Key] = fragment;
                        }
                    }
                    groupDocs.Add(new GroupDoc(fragmentMap));
                }
                return(new Group(groupDocs));
            }
コード例 #7
0
        public void CanParseFragmentWithParamBlock()
        {
            // Arrange.
            Lexer lexer = new Lexer(null, @"fragment basic_material;

				[params]
				float alpha : ALPHA;
				float3 color;"                );

            FragmentParser parser = new FragmentParser(null, lexer.GetTokens());

            // Act.
            FragmentNode fragment = parser.Parse();

            // Assert.
            Assert.AreEqual("basic_material", fragment.Name);
            Assert.IsNotNull(fragment.Parameters);
            Assert.AreEqual(2, fragment.Parameters.VariableDeclarations.Count);
            Assert.AreEqual(TokenType.Float, fragment.Parameters.VariableDeclarations[0].DataType);
            Assert.AreEqual("alpha", fragment.Parameters.VariableDeclarations[0].Name);
            Assert.AreEqual("ALPHA", fragment.Parameters.VariableDeclarations[0].Semantic);
            Assert.AreEqual(TokenType.Float3, fragment.Parameters.VariableDeclarations[1].DataType);
            Assert.AreEqual("color", fragment.Parameters.VariableDeclarations[1].Name);
        }