Example #1
0
        public Scaffold(Core RennderCore, string file, string name, string[] vars = null)
        {
            R = RennderCore;
            if (vars == null)
            {
                Data = new Dictionary <string, string>();
            }
            else
            {
                Setup(vars);
            }

            if (R.Server.Scaffold.ContainsKey(file + '/' + name) == false)
            {
                scaffold           = new structScaffoldElement();
                scaffold.parts     = new List <structScaffold>();
                scaffold.arguments = new Dictionary <string, string>();

                //first, load file from disk or cache
                var htm = "";
                if (R.Server.Cache.ContainsKey(file) == false)
                {
                    htm = File.ReadAllText(R.Server.MapPath(file));
                }
                else
                {
                    htm = (string)R.Server.Cache[file];
                }

                //next, find the group of code matching the scaffold name
                if (name != "")
                {
                    int[]  e = new int[3];
                    string s = "";
                    e[0] = -1;
                    while (e[0] < 0)
                    {
                        //find starting tag (optionally with arguments)
                        e[0] = htm.IndexOf("{{" + name);
                        if (e[0] >= 0)
                        {
                            e[1] = e[0] + 2 + name.Length;
                            s    = htm.Substring(e[1], 1);
                            switch (s)
                            {
                            case "}":
                                break;

                            case " ":
                            case "(":
                                if (s == " ")
                                {
                                    e[1] += 1; s = htm.Substring(e[1], 1);
                                }
                                if (s == "(")
                                {
                                    //get arguments
                                    e[2] = htm.IndexOf(")", e[1]);
                                    string[] args = htm.Substring(e[1] + 1, e[2] - e[1] - 1).Split(',');
                                    for (int x = 0; x < args.Length; x++)
                                    {
                                        string[] kv = args[x].Split(':');
                                        if (kv.Length == 2)
                                        {
                                            scaffold.arguments.Add(kv[0].Trim().Trim(new char[] { '\'' }), kv[1].Trim().Trim(new char[] { '\'' }));
                                        }
                                    }
                                }
                                break;

                            default:
                                e[0] = -1;
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    e[1] = htm.IndexOf("{{/" + name + "}}");
                    if (e[0] >= 0 & e[1] > e[0])
                    {
                        e[2] = e[0] + 4 + name.Length;
                        htm  = htm.Substring(e[2], e[1] - e[2]);
                    }
                }

                //get scaffold from html code
                var arr = htm.Split(new string[] { "{{" }, StringSplitOptions.RemoveEmptyEntries);
                var i = 0; structScaffold scaff;
                for (var x = 0; x < arr.Length; x++)
                {
                    i     = arr[x].IndexOf("}}");
                    scaff = new structScaffold();
                    if (i > 0)
                    {
                        scaff.name = arr[x].Substring(0, i);
                        scaff.htm  = arr[x].Substring(i + 2);
                    }
                    else
                    {
                        scaff.name = "";
                        scaff.htm  = arr[x];
                    }
                    scaffold.parts.Add(scaff);
                }
                if (R.isLocal == false)
                {
                    R.Server.Scaffold.Add(file + '/' + name, scaffold);
                }
            }
            else
            {
                //get scaffold object from memory
                scaffold = R.Server.Scaffold[file + '/' + name];
            }
        }
Example #2
0
        public Scaffold(Core RennderCore, string file, string name, string[] vars = null)
        {
            R = RennderCore;
            if (vars == null)
            {
                Data = new Dictionary<string, string>();
            }
            else
            {
                Setup(vars);
            }

            if (R.Server.Scaffold.ContainsKey(file + '/' + name) == false)
            {
                scaffold = new structScaffoldElement();
                scaffold.parts = new List<structScaffold>();
                scaffold.arguments = new Dictionary<string, string>();

                //first, load file from disk or cache
                var htm = "";
                if (R.Server.Cache.ContainsKey(file) == false)
                {
                    htm = File.ReadAllText(R.Server.MapPath(file));
                }
                else
                {
                    htm = (string)R.Server.Cache[file];
                }

                //next, find the group of code matching the scaffold name
                if(name != "")
                {
                    int[] e = new int[3];
                    string s = "";
                    e[0] = -1;
                    while(e[0] < 0) {
                        //find starting tag (optionally with arguments)
                        e[0] = htm.IndexOf("{{" + name);
                        if(e[0] >= 0)
                        {
                            e[1] = e[0] + 2 + name.Length;
                            s = htm.Substring(e[1], 1);
                            switch (s)
                            {
                                case "}":
                                    break;

                                case " ":
                                case "(":
                                    if (s == " ") { e[1] += 1; s = htm.Substring(e[1], 1); }
                                    if (s == "(")
                                    {
                                        //get arguments
                                        e[2] = htm.IndexOf(")", e[1]);
                                        string[] args = htm.Substring(e[1] + 1, e[2] - e[1] - 1).Split(',');
                                        for (int x = 0; x < args.Length; x++)
                                        {
                                            string[] kv = args[x].Split(':');
                                            if (kv.Length == 2)
                                            {
                                                scaffold.arguments.Add(kv[0].Trim().Trim(new char[] { '\'' }), kv[1].Trim().Trim(new char[] { '\'' }));
                                            }
                                        }
                                    }
                                    break;

                                default:
                                    e[0] = -1;
                                    break;
                            }
                        } else { break; }

                    }
                    e[1] = htm.IndexOf("{{/" + name + "}}");
                    if (e[0] >= 0 & e[1] > e[0])
                    {
                        e[2] = e[0] + 4 + name.Length;
                        htm = htm.Substring(e[2], e[1] - e[2]);
                    }
                }

                //get scaffold from html code
                var arr = htm.Split(new string[] { "{{" }, StringSplitOptions.RemoveEmptyEntries);
                var i = 0; structScaffold scaff;
                for (var x = 0; x < arr.Length; x++)
                {
                    i = arr[x].IndexOf("}}");
                    scaff = new structScaffold();
                    if (i > 0)
                    {
                        scaff.name = arr[x].Substring(0, i);
                        scaff.htm = arr[x].Substring(i + 2);
                    }
                    else
                    {
                        scaff.name = "";
                        scaff.htm = arr[x];
                    }
                    scaffold.parts.Add(scaff);
                }
                if(R.isLocal == false){ R.Server.Scaffold.Add(file + '/' + name, scaffold); }
            }
            else
            {
                //get scaffold object from memory
                scaffold = R.Server.Scaffold[file + '/' + name];
            }
        }