Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 94 lines (77 sloc) 3.191 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using IronAHK.Rusty;

namespace IronAHK.Setup
{
    partial class Program
    {
        static void TransformDocs()
        {
            string root = string.Format("..{0}..{0}..{0}{1}{0}Site{0}docs{0}commands", Path.DirectorySeparatorChar, Name);

            var xsl = new XslCompiledTransform();

            using (var src = XmlReader.Create(Path.Combine(root, "view.xsl"), new XmlReaderSettings { ProhibitDtd = false }))
            {
                xsl.Load(src);
            }

            string prefix = string.Format("M:{0}.", typeof(Core).FullName), assembly = typeof(Core).Namespace;
            const string index = "index", srcName = index + ".xml", htmlName = index + ".html", member = "member";

            foreach (var path in Directory.GetDirectories(root))
            {
                RemoveCommonPaths(path, srcName, htmlName);
                Directory.Delete(path, false);
            }

            string xml = assembly + ".xml";

            if (!File.Exists(xml))
            {
                string parent = Path.GetFullPath(Path.Combine(WorkingDir, string.Format("..{0}..{0}..", Path.DirectorySeparatorChar)));
                string diff = Path.GetDirectoryName(Path.GetFullPath(xml)).Substring(parent.Length + 1);
                diff = diff.Replace("Deploy", assembly.Substring(Name.Length + 1));
                xml = Path.Combine(Path.Combine(parent, diff), xml);
            }

            using (var reader = XmlReader.Create(xml))
            {
                reader.ReadToDescendant(member);

                do
                {
                    string name = reader.GetAttribute("name");
                    int z = name.IndexOf('(');

                    if (!name.StartsWith(prefix) || z == -1 || z <= prefix.Length)
                        continue;

                    name = name.Substring(prefix.Length, z - prefix.Length);
                    string path = Path.Combine(root, name.ToLowerInvariant());

                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);

                    RemoveCommonPaths(path, srcName, htmlName);
                    string src = Path.Combine(path, srcName), html = Path.Combine(path, htmlName);

                    using (var writer = new StreamWriter(src))
                    {
                        writer.Write(@"<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='../view.xsl'?>
<doc>
<assembly>
<name>{0}</name>
</assembly>
<members>
", assembly);
                        writer.Write(reader.ReadOuterXml());
                        writer.Write(@"
</members>
</doc>");
                    }

                    xsl.Transform(src, html);
                }
                while (reader.ReadToNextSibling(member));
            }
        }

        static void RemoveCommonPaths(string parent, params string[] files)
        {
            foreach (var file in files)
            {
                string path = Path.Combine(parent, file);

                if (File.Exists(path))
                    File.Delete(path);
            }
        }
    }
}
Something went wrong with that request. Please try again.