Пример #1
0
        public void Add(RenoItem item, SourceSet set, bool asTemplate)
        {
            var function = set.Source.Parsed.Functions.ToArray().FirstOrDefault(f => item.id.EndsWith("." + f.Name));

            if (function != null)
            {
                sb.Append("/**" + function.Snippet.Replace("\n", "\r\n") +
                          "\r\n * @see " + item.url + "\r\n" +
                          "*/\r\n");

                var line          = "";
                var preline       = "";
                var allParameters = true;

                sb.Append("\r\n");

                if (function.Parameters.Count > 0)
                {
                    for (int i = 0; i < function.Parameters.Count; i++)
                    {
                        var parm = function.Parameters[i];

                        var actualValue = (item.parms[i].defaultData == "null"
                            ? "null"
                            : parm.Type == "string" ? ("\"" + item.parms[i].defaultData + "\"") : item.parms[i].defaultData);

                        //TODO: literal values vs. others (like document.title);

                        if (allParameters || (item.parms[i].defaultData != "" && item.parms[i].defaultData != "null"))
                        {
                            sb.Append("var " + parm.Name + " = " + actualValue + ";\r\n");
                            line   += preline + parm.Name + ", ";
                            preline = "";
                        }
                        else
                        {
                            preline += actualValue + ", ";
                        }
                    }

                    line = (function.Returns != null ? ("var " + function.Returns.Name + " = ") : "") + function.Method + "(" +
                           line.Substring(0, line.Length - 2) + ");";
                }
                else
                {
                    line = (function.Returns != null ? ("var " + function.Returns.Name + " = ") : "") + function.Method + "();";
                }


                sb.Append("\r\n" + line + "\r\n\r\n");
            }
        }
Пример #2
0
        public async Task <SourceData> Get()
        {
            var list = await SourceList();

            //TODO: Get list of known file of options/source.
            var mgr     = new SourceManager.SourceManager();
            var catalog = await mgr.GetCatalog(list, true);

            var sourcePath = Path.GetTempPath() + "\\original";

            if (!Directory.Exists(sourcePath))
            {
                Directory.CreateDirectory(sourcePath);
            }

            sourcePath += "\\";

            for (int i = 0; i < catalog.Count; i++)
            {
                var sourceSet = catalog[i];

                var url     = sourceSet.Source.Url;
                var index   = url.LastIndexOf("/");
                var hash    = sourceSet.Code.GetHashCode();
                var name    = url.Substring(index + 1);
                var period  = name.IndexOf(".");
                var newName = name.Substring(0, period) + "-" + hash + name.Substring(period);

                sourceSet.Source.Hash = hash.ToString();


                if (!File.Exists(sourcePath + newName))
                {
                    try
                    {
                        File.WriteAllText(sourcePath + newName, sourceSet.Code);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                }
            }

            var source = new SourceData();

            source.Sources = catalog.Select(s => s.Source).ToList();
            var doc = new Documentation();

            for (int i = 0; i < source.Sources.Count; i++)
            {
                var cat = catalog[i];
                var src = source.Sources[i];
                //source.Sources[0].Parsed.Functions
                for (int j = 0; j < src.Parsed.Functions.Count; j++)
                {
                    var fn   = src.Parsed.Functions[j];
                    var item = new RenoItem();
                    item.url   = src.Url;
                    item.id    = src.Id + "." + fn.Name;
                    item.image = fn.Image;
                    item.parms = new List <RenoParm>();
                    for (int k = 0; k < fn.Parameters.Count; k++)
                    {
                        var parm = fn.Parameters[k];
                        item.parms.Add(new RenoParm {
                            id = item.id + "." + parm.Name, defaultData = parm.Default
                        });
                    }

                    doc.Add(item, cat, true);
                    fn.Snippet = doc.GetDocumentation();
                    doc.Clear();
                }
            }

            return(source);
        }